Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def draw_roof_tile(p0, p1, p2, p3, min_dist = 6, opp=1):
if opp == 1:
draw_roof_tile(p0, p1, p2, p3, 3*min_dist, opp=-1)
#initialization
if p0[1]*opp < p1[1]*opp:
p1, p2 = co.cen( p0, p1 ), co.cen( p2, p3 )
else:
p0, p3 = co.cen( p0, p1 ), co.cen( p2, p3 )
tile_dist = min_dist
tile_dist_max = co.dis_between_two_points( p0, p3 )
while 1:
if tile_dist >= tile_dist_max: break
point1 = ( tile_dist*(p3[0]-p0[0])/tile_dist_max+p0[0], tile_dist*(p3[1]-p0[1])/tile_dist_max+p0[1] )
point2 = ( tile_dist*(p2[0]-p1[0])/tile_dist_max+p1[0], tile_dist*(p2[1]-p1[1])/tile_dist_max+p1[1] )
cv2.polylines(img,[np.int32(np.around([point1, point2]))],True,(255,255,255),1)
tile_dist = tile_dist + min_dist
def draw_roof_tile(p0, p1, p2, p3, min_dist = 6, opp=1):
if opp == 1:
draw_roof_tile(p0, p1, p2, p3, 3*min_dist, opp=-1)
#initialization
if p0[1]*opp < p1[1]*opp:
p1, p2 = co.cen( p0, p1 ), co.cen( p2, p3 )
else:
p0, p3 = co.cen( p0, p1 ), co.cen( p2, p3 )
tile_dist = min_dist
tile_dist_max = co.dis_between_two_points( p0, p3 )
while 1:
if tile_dist >= tile_dist_max: break
point1 = ( tile_dist*(p3[0]-p0[0])/tile_dist_max+p0[0], tile_dist*(p3[1]-p0[1])/tile_dist_max+p0[1] )
point2 = ( tile_dist*(p2[0]-p1[0])/tile_dist_max+p1[0], tile_dist*(p2[1]-p1[1])/tile_dist_max+p1[1] )
drawing.append( sdxf.Line(points=[point1, point2], layer='roof_tile') )
tile_dist = tile_dist + min_dist
# Kind3:A yard or a street block
if rect_max_side < bound_B:
if rect_width < bound_A:
# Kind2
c_right, c_left, c_up, c_down = co.sidecenter( four_points )
center_rect = co.cen(c_up,c_down)
tmp_point = co.cen( co.cen(c_down, center_rect), c_up )
result_set = result_set.union( roof_cut( co.line_to_rect(c_up, tmp_point, rect_width*0.5*0.8, 0.2*0.5*rect_width ) ) )
result_set = result_set.union( roof_cut( co.line_to_rect(tmp_point, c_down, rect_width*0.5 ) ) )
return result_set
elif rect_height < bound_A:
# Kind2
c_right, c_left, c_up, c_down = co.sidecenter( four_points )
center_rect = co.cen(c_up,c_down)
tmp_point = co.cen( co.cen(c_right, center_rect), c_left )
result_set = result_set.union( roof_cut( co.line_to_rect(c_left, tmp_point, rect_height*0.5*0.8, 0.2*0.5*rect_height ) ) )
result_set = result_set.union( roof_cut( co.line_to_rect(tmp_point, c_right, rect_height*0.5 ) ) )
return result_set
else:
# Kind3
if rect_width>2*bound_A or rect_height>2*bound_A:
width_cut, height_cut = int(rect_width / bound_A), int(rect_height / bound_A)
if width_cut == 0: width_cut = 1
if height_cut == 0: height_cut = 1
width_side, height_side = rect_width / width_cut, rect_height / height_cut
print width_side, height_side,width_cut,height_cut, '&&&&'
for i in xrange(width_cut):
for j in xrange(height_cut):
#wrong
p0 = co.get_rect_point( four_points[0], four_points[1], four_points[2], four_points[3], \
def draw_roof_tile(p0, p1, p2, p3, min_dist = 6, opp=1):
if opp == 1:
draw_roof_tile(p0, p1, p2, p3, 3*min_dist, opp=-1)
#initialization
if p0[1]*opp < p1[1]*opp:
p1, p2 = co.cen( p0, p1 ), co.cen( p2, p3 )
else:
p0, p3 = co.cen( p0, p1 ), co.cen( p2, p3 )
tile_dist = min_dist
tile_dist_max = co.dis_between_two_points( p0, p3 )
while 1:
if tile_dist >= tile_dist_max: break
point1 = ( tile_dist*(p3[0]-p0[0])/tile_dist_max+p0[0], tile_dist*(p3[1]-p0[1])/tile_dist_max+p0[1] )
point2 = ( tile_dist*(p2[0]-p1[0])/tile_dist_max+p1[0], tile_dist*(p2[1]-p1[1])/tile_dist_max+p1[1] )
cv2.polylines(img,[np.int32(np.around([point1, point2]))],True,(255,255,255),1)
tile_dist = tile_dist + min_dist
rect_max_side = max( rect_width, rect_height )
# Kind1:One building
if rect_max_side < bound_A:
if min( rect_width, rect_height ) <10: return set()
return set([four_points])
result_set = set()
# Kind2:One side to be a yard or block
# Kind3:A yard or a street block
if rect_max_side < bound_B:
if rect_width < bound_A:
# Kind2
c_right, c_left, c_up, c_down = co.sidecenter( four_points )
center_rect = co.cen(c_up,c_down)
tmp_point = co.cen( co.cen(c_down, center_rect), c_up )
result_set = result_set.union( roof_cut( co.line_to_rect(c_up, tmp_point, rect_width*0.5*0.8, 0.2*0.5*rect_width ) ) )
result_set = result_set.union( roof_cut( co.line_to_rect(tmp_point, c_down, rect_width*0.5 ) ) )
return result_set
elif rect_height < bound_A:
# Kind2
c_right, c_left, c_up, c_down = co.sidecenter( four_points )
center_rect = co.cen(c_up,c_down)
tmp_point = co.cen( co.cen(c_right, center_rect), c_left )
result_set = result_set.union( roof_cut( co.line_to_rect(c_left, tmp_point, rect_height*0.5*0.8, 0.2*0.5*rect_height ) ) )
result_set = result_set.union( roof_cut( co.line_to_rect(tmp_point, c_right, rect_height*0.5 ) ) )
return result_set
else:
# Kind3
# Kind1:One building
if rect_max_side < bound_A:
if min( rect_width, rect_height ) <10: return set()
return set([four_points])
result_set = set()
# Kind2:One side to be a yard or block
# Kind3:A yard or a street block
if rect_max_side < bound_B:
if rect_width < bound_A:
# Kind2
c_right, c_left, c_up, c_down = co.sidecenter( four_points )
center_rect = co.cen(c_up,c_down)
tmp_point = co.cen( co.cen(c_down, center_rect), c_up )
result_set = result_set.union( roof_cut( co.line_to_rect(c_up, tmp_point, rect_width*0.5*0.8, 0.2*0.5*rect_width ) ) )
result_set = result_set.union( roof_cut( co.line_to_rect(tmp_point, c_down, rect_width*0.5 ) ) )
return result_set
elif rect_height < bound_A:
# Kind2
c_right, c_left, c_up, c_down = co.sidecenter( four_points )
center_rect = co.cen(c_up,c_down)
tmp_point = co.cen( co.cen(c_right, center_rect), c_left )
result_set = result_set.union( roof_cut( co.line_to_rect(c_left, tmp_point, rect_height*0.5*0.8, 0.2*0.5*rect_height ) ) )
result_set = result_set.union( roof_cut( co.line_to_rect(tmp_point, c_right, rect_height*0.5 ) ) )
return result_set
else:
# Kind3
if rect_width>2*bound_A or rect_height>2*bound_A:
def draw_roof_tile(p0, p1, p2, p3, min_dist = 6, opp=1):
if opp == 1:
draw_roof_tile(p0, p1, p2, p3, 3*min_dist, opp=-1)
#initialization
if p0[1]*opp < p1[1]*opp:
p1, p2 = co.cen( p0, p1 ), co.cen( p2, p3 )
else:
p0, p3 = co.cen( p0, p1 ), co.cen( p2, p3 )
tile_dist = min_dist
tile_dist_max = co.dis_between_two_points( p0, p3 )
while 1:
if tile_dist >= tile_dist_max: break
point1 = ( tile_dist*(p3[0]-p0[0])/tile_dist_max+p0[0], tile_dist*(p3[1]-p0[1])/tile_dist_max+p0[1] )
point2 = ( tile_dist*(p2[0]-p1[0])/tile_dist_max+p1[0], tile_dist*(p2[1]-p1[1])/tile_dist_max+p1[1] )
drawing.append( sdxf.Line(points=[point1, point2], layer='roof_tile') )
tile_dist = tile_dist + min_dist