def estimating_t1(components,upper_bound=200000): #it works only if len(components) t1=upper_bound t2=0 for box1 in components[0]: for box2 in components[1]: a=d.distance(box1,box2).lower() b=d.distance(box1,box2).upper() if t1 > a: t1=a if t2<b: t2=b t=d.ftconstructor(t1,t2) t=0.25*d.power_interval(t,2) return [float(t.lower()),float(t.upper())]
def estimating_yandr(components,upper_bound=100000): r_bounds=[[upper_bound,0]]*(len(components[0][0])-2) r_list=[] y_list=[] for box1 in components[0]: for box2 in components[1]: ft_box1= [d.ftconstructor(Bi[0],Bi[1]) for Bi in box1 ] ft_box2= [d.ftconstructor(Bi[0],Bi[1]) for Bi in box2 ] y_list.append([0.5*(q1+q2) for q1,q2 in zip(ft_box1[2:],ft_box2[2:])]) norm_q1q2=d.distance(box1[2:],box2[2:]) norm_q1q2=d.ftconstructor(norm_q1q2[0],norm_q1q2[1]) q1q2=[ft_box1[i]-ft_box2[i] for i in range(2,len(box1)) ] r=[ ri/norm_q1q2 for ri in q1q2 ] r_list.append(r) r=[] y=[] for i in range(len(y_list[0])): yi1=min([float(y[i].lower()) for y in y_list ]) yi2=max([float(y[i].upper()) for y in y_list ]) y.append([yi1,yi2]) for i in range(len(r_list[0])): ri1=min([float(r[i].lower()) for r in r_list ]) ri2=max([float(r[i].upper()) for r in r_list ]) r.append([ri1,ri2]) r=d.boxes_intersection(r,[[-1,1]]*(len(components[0][0])-2)) return y+r
def estimating_t(components): #it works only if len(components)==2 uni = d.distance(components[0][0], components[1][0]) for box1 in components[0]: for box2 in components[1]: #print(uni);input() if d.width(box1[2:]) < 1e-6: box1[2:] = [[Bi[0] - 1e-6, Bi[1] + 1e-6] for Bi in box1[2:]] if d.width(box2[2:]) < 1e-6: box2[2:] = [[Bi[0] - 1e-6, Bi[1] + 1e-6] for Bi in box2[2:]] a = d.distance(box1[2:], box2[2:]) #print(a);input() uni = d.box_union([uni], [a])[0] """if t1 > a[0]: t1=a[0] if t2<a[1]: t2=a[1]""" t = d.ftconstructor(uni[0], uni[1]) t = 0.25 * d.power_interval(t, 2) return [float(t.lower()), float(t.upper())]
def estimating_t(components,upper_bound=19000.8): #it works only if len(components)==2 t1=upper_bound t2=0 for box1 in components[0]: for box2 in components[1]: a=d.distance(box1[2:],box2[2:]) if t1 > a[0]: t1=a[0] if t2<a[1]: t2=a[1] t=d.ftconstructor(t1,t2) t=0.25*d.power_interval(t,2) return [float(t.lower()),float(t.upper())]