Reduce intersecting objects into one point of intersections.
(
objs: list[Union[Point, Line, Circle, HalfLine, HoleCircle]],
existing_points: list[Point],
)
| 1295 | |
| 1296 | |
| 1297 | def reduce( |
| 1298 | objs: list[Union[Point, Line, Circle, HalfLine, HoleCircle]], |
| 1299 | existing_points: list[Point], |
| 1300 | ) -> list[Point]: |
| 1301 | """Reduce intersecting objects into one point of intersections.""" |
| 1302 | if all(isinstance(o, Point) for o in objs): |
| 1303 | return objs |
| 1304 | |
| 1305 | elif len(objs) == 1: |
| 1306 | return objs[0].sample_within(existing_points) |
| 1307 | |
| 1308 | elif len(objs) == 2: |
| 1309 | a, b = objs |
| 1310 | result = a.intersect(b) |
| 1311 | if isinstance(result, Point): |
| 1312 | return [result] |
| 1313 | a, b = result |
| 1314 | a_close = any([a.close(x) for x in existing_points]) |
| 1315 | if a_close: |
| 1316 | return [b] |
| 1317 | b_close = any([b.close(x) for x in existing_points]) |
| 1318 | if b_close: |
| 1319 | return [a] |
| 1320 | return [np.random.choice([a, b])] |
| 1321 | |
| 1322 | else: |
| 1323 | raise ValueError(f'Cannot reduce {objs}') |
| 1324 | |
| 1325 | |
| 1326 | def sketch( |
nothing calls this directly
no test coverage detected