Check if a point lies on the line segment between p1 and p2.
(p1: Point, p2: Point, point: Point)
| 56 | |
| 57 | |
| 58 | def _is_point_on_segment(p1: Point, p2: Point, point: Point) -> bool: |
| 59 | """Check if a point lies on the line segment between p1 and p2.""" |
| 60 | # Check if point is collinear with segment endpoints |
| 61 | cross = (point.y - p1.y) * (p2.x - p1.x) - (point.x - p1.x) * (p2.y - p1.y) |
| 62 | |
| 63 | if abs(cross) > 1e-9: |
| 64 | return False |
| 65 | |
| 66 | # Check if point is within the bounding box of the segment |
| 67 | return min(p1.x, p2.x) <= point.x <= max(p1.x, p2.x) and min( |
| 68 | p1.y, p2.y |
| 69 | ) <= point.y <= max(p1.y, p2.y) |
| 70 | |
| 71 | |
| 72 | def _find_leftmost_point(points: list[Point]) -> int: |
no outgoing calls
no test coverage detected