Compare two points by polar angle relative to min_point.
(point_a: Point, point_b: Point)
| 174 | |
| 175 | # Sort by polar angle using a comparison based on cross product |
| 176 | def compare_points(point_a: Point, point_b: Point) -> int: |
| 177 | """Compare two points by polar angle relative to min_point.""" |
| 178 | orientation = min_point.consecutive_orientation(point_a, point_b) |
| 179 | if orientation < 0.0: |
| 180 | return 1 # point_a comes after point_b (clockwise) |
| 181 | elif orientation > 0.0: |
| 182 | return -1 # point_a comes before point_b (counter-clockwise) |
| 183 | else: |
| 184 | # Collinear: farther point should come first |
| 185 | dist_a = min_point.euclidean_distance(point_a) |
| 186 | dist_b = min_point.euclidean_distance(point_b) |
| 187 | if dist_b < dist_a: |
| 188 | return -1 |
| 189 | elif dist_b > dist_a: |
| 190 | return 1 |
| 191 | else: |
| 192 | return 0 |
| 193 | |
| 194 | from functools import cmp_to_key |
| 195 |
nothing calls this directly
no test coverage detected