Try to sketch an intersection between two objects.
(
name1: str,
args1: list[Union[gm.Point, Point]],
name2: str,
args2: list[Union[gm.Point, Point]],
existing_points: list[Point],
)
| 1437 | |
| 1438 | |
| 1439 | def try_to_sketch_intersect( |
| 1440 | name1: str, |
| 1441 | args1: list[Union[gm.Point, Point]], |
| 1442 | name2: str, |
| 1443 | args2: list[Union[gm.Point, Point]], |
| 1444 | existing_points: list[Point], |
| 1445 | ) -> Optional[Point]: |
| 1446 | """Try to sketch an intersection between two objects.""" |
| 1447 | obj1 = sketch(name1, args1)[0] |
| 1448 | obj2 = sketch(name2, args2)[0] |
| 1449 | |
| 1450 | if isinstance(obj1, Line) and isinstance(obj2, Line): |
| 1451 | fn = line_line_intersection |
| 1452 | elif isinstance(obj1, Circle) and isinstance(obj2, Circle): |
| 1453 | fn = circle_circle_intersection |
| 1454 | else: |
| 1455 | fn = line_circle_intersection |
| 1456 | if isinstance(obj2, Line) and isinstance(obj1, Circle): |
| 1457 | obj1, obj2 = obj2, obj1 |
| 1458 | |
| 1459 | try: |
| 1460 | x = fn(obj1, obj2) |
| 1461 | except: # pylint: disable=bare-except |
| 1462 | return None |
| 1463 | |
| 1464 | if isinstance(x, Point): |
| 1465 | return x |
| 1466 | |
| 1467 | x1, x2 = x |
| 1468 | |
| 1469 | close1 = check_too_close([x1], existing_points) |
| 1470 | far1 = check_too_far([x1], existing_points) |
| 1471 | if not close1 and not far1: |
| 1472 | return x1 |
| 1473 | close2 = check_too_close([x2], existing_points) |
| 1474 | far2 = check_too_far([x2], existing_points) |
| 1475 | if not close2 and not far2: |
| 1476 | return x2 |
| 1477 | |
| 1478 | return None |
| 1479 | |
| 1480 | |
| 1481 | def sketch_acircle(args: tuple[gm.Point, ...]) -> Circle: |
nothing calls this directly
no test coverage detected