diff --git a/inire/router/_automatic.py b/inire/router/_automatic.py index c7123af..7eb1db1 100644 --- a/inire/router/_automatic.py +++ b/inire/router/_automatic.py @@ -12,8 +12,7 @@ from typing import TYPE_CHECKING import shapely from shapely.geometry import box -from inire.constants import TOLERANCE_LINEAR -from inire.geometry.collision import RoutingWorld +from inire.geometry.collision import RoutingWorld, _violates_net_clearance from inire.model import FixedRoute, resolve_bend_geometry from inire.results import AutomaticRoutingReport, RoutingStage, RoutingTiming, _planner_for_mode from inire.router._bundle import ordered_bundle_terminal_headings, plan_ordered_bundle @@ -335,7 +334,7 @@ class _AutomaticRun: pairs = chain(pairs, reserved_pairs) for (first_seed, first_shape), (second_seed, second_shape) in pairs: - if first_shape.distance(second_shape) < problem.clearance - TOLERANCE_LINEAR: + if _violates_net_clearance(first_shape, second_shape, problem.clearance): continue plan = replace(problem, initial_paths={first.net_id: first_seed, second.net_id: second_seed}) trial = self._verify(plan, "paired-perimeter") diff --git a/inire/router/_compact.py b/inire/router/_compact.py index e1c01dd..b975672 100644 --- a/inire/router/_compact.py +++ b/inire/router/_compact.py @@ -9,8 +9,7 @@ from typing import TYPE_CHECKING from shapely import union_all from shapely.geometry import box -from inire.constants import TOLERANCE_LINEAR -from inire.geometry.collision import RoutingWorld +from inire.geometry.collision import RoutingWorld, _violates_net_clearance from inire.geometry.primitives import port_local_coordinates from inire.geometry.sbend import exact_sbend_spans, sbend_grid_span from inire.model import resolve_bend_geometry @@ -119,7 +118,7 @@ def _pack_routes( if remaining <= 0: return None remaining -= 1 - if any(footprint.distance(other) < clearance - TOLERANCE_LINEAR for _, other in chosen.values()): + if any(_violates_net_clearance(footprint, other, clearance) for _, other in chosen.values()): continue chosen[net_id] = (seed, footprint) index += 1 diff --git a/inire/tests/test_compact.py b/inire/tests/test_compact.py index cfb0284..4f2a93d 100644 --- a/inire/tests/test_compact.py +++ b/inire/tests/test_compact.py @@ -19,3 +19,21 @@ def test_local_sbend_planner_uses_the_snapped_span() -> None: assert run.metrics.nodes_expanded == 0 for net in (east, north): assert run.results_by_net[net.net_id].as_seed().segments == (SBendSeed(5, 10),) + + +def test_local_sbend_packing_skips_intersecting_candidates_at_zero_clearance() -> None: + east = NetSpec("east", Port(10, 10, 0), Port(50, 18, 0)) + north = NetSpec("north", Port(26, 12, 90), Port(18, 42, 90)) + line = NetSpec("line", Port(10, 65, 0), Port(55, 65, 0)) + problem = RoutingProblem((0, 0, 100, 100), (east, north, line), clearance=0) + options = RoutingOptions( + search=SearchOptions(node_limit=1, min_straight_length=0, bend_radii=(), sbend_radii=(10,), sbend_offsets=(8,)), + congestion=CongestionOptions(max_iterations=1, warm_start_enabled=False), + refinement=RefinementOptions(enabled=False), + ) + + run = route(problem, options=options) + + assert all(result.is_valid for result in run.results_by_net.values()) + assert run.automatic.selected_planner == "local-sbend" + assert run.metrics.nodes_expanded == 0