Check whether *point*, known to be collinear with the segment, lies on it. >>> on_segment(Point(0, 0), Point(4, 4), Point(2, 2)) True >>> on_segment(Point(0, 0), Point(4, 4), Point(5, 5)) False >>> on_segment(Point(0, 0), Point(4, 0), Point(2, 0)) True
(seg_start: Point, seg_end: Point, point: Point)
| 49 | |
| 50 | |
| 51 | def on_segment(seg_start: Point, seg_end: Point, point: Point) -> bool: |
| 52 | """Check whether *point*, known to be collinear with the segment, lies on it. |
| 53 | |
| 54 | >>> on_segment(Point(0, 0), Point(4, 4), Point(2, 2)) |
| 55 | True |
| 56 | >>> on_segment(Point(0, 0), Point(4, 4), Point(5, 5)) |
| 57 | False |
| 58 | >>> on_segment(Point(0, 0), Point(4, 0), Point(2, 0)) |
| 59 | True |
| 60 | """ |
| 61 | return min(seg_start.x, seg_end.x) <= point.x <= max( |
| 62 | seg_start.x, seg_end.x |
| 63 | ) and min(seg_start.y, seg_end.y) <= point.y <= max(seg_start.y, seg_end.y) |
| 64 | |
| 65 | |
| 66 | def segments_intersect(p1: Point, p2: Point, p3: Point, p4: Point) -> bool: |
no outgoing calls
no test coverage detected