def find_helipad_radius(edges: CandidateEdges, roof: Roof) -> float: # If polygon is defined in counterclockwise direction, then if we are moving right at the start, # the first time we move up (Y) is when we start measuring the min X value. That is the largest # possible X value for the right side. Once this is done for all four sides, take the difference # between Xs and Ys, figure out which is greater and divide by 2 to get the radius. largest_radius = -99.0 outline_points = roof.upper_right_points + roof.bottom_left_points for left in edges.left: for right in edges.right: for top in edges.top: for bottom in edges.bottom: possible_location = Rect(left, top, right, bottom) helipad_center = Point(left + (right - left) / 2, bottom + (top - bottom) / 2) radius = find_largest_radius_inside(possible_location) possible_helipad = Circle(helipad_center, radius) points_inside = [point_in_circle(pt, possible_helipad) for pt in outline_points] if not any(points_inside) and radius > largest_radius: largest_radius = radius return largest_radius