def calc_side_lengths(contour: Polygon) -> tp.List[float]: """For a list of points, returns a list of numbers, where each element with index `i` is the distance from point `i` to point `i+1`.""" result = [] for i, point in enumerate(contour): next_point = contour[list_utils.next_index(contour, i)] result.append(calc_2d_dist(point, next_point)) return result
def calc_corner_angles(contour: Polygon) -> tp.List[float]: """For a list of points, returns a list of numbers, where each element with index `i` is the angle between points `i-1`, `i`, and `i+1`.""" result = [] for i, point in enumerate(contour): previous_point = contour[list_utils.prev_index(contour, i)] next_point = contour[list_utils.next_index(contour, i)] result.append(calc_angle(previous_point, point, next_point)) return result
def get_corner(square: Polygon, corner: Corner) -> Point: """Gets the point representing the given corner of the square. Square should be pretty close to vertical - horizontal. """ xs = [p.x for p in square] highest_xs = sorted(list_utils.find_greatest_value_indexes(xs, 2)) side_points = [ p for i, p in enumerate(square) if (corner.value[1] == 1 and i in highest_xs) or ( corner.value[1] == 0 and i not in highest_xs) ] side_ys = [p.y for p in side_points] [highest_y] = list_utils.find_greatest_value_indexes(side_ys, 1) corner_point = side_points[highest_y] if ( corner.value[0] == 0) else side_points[list_utils.next_index( side_points, highest_y)] return corner_point