MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / compare_points

Function compare_points

geometry/graham_scan.py:176–192  ·  view source on GitHub ↗

Compare two points by polar angle relative to min_point.

(point_a: Point, point_b: Point)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

euclidean_distanceMethod · 0.80

Tested by

no test coverage detected