Skip forward perimeter detours that cannot fit four turns

This commit is contained in:
Jan Petykiewicz 2026-11-30 10:41:01 -08:00
commit 653edda512
2 changed files with 36 additions and 1 deletions

View file

@ -246,7 +246,8 @@ def perimeter_detour_candidates(problem: RoutingProblem, search: SearchOptions)
if net.start.x > net.target.x:
yield from ((net, seed) for seed in _return_detours(problem, net, obstacles, radius))
continue
if net.start.x == net.target.x or not obstacles:
# The two outer tangencies take one radius each, and the middle leg takes two.
if net.target.x - net.start.x < 4 * radius or not obstacles:
continue
low, high = sorted((net.start.y, net.target.y))
if all(bottom > high or top < low or right < net.start.x or left > net.target.x for left, bottom, right, top in obstacles):

View file

@ -0,0 +1,34 @@
from shapely.geometry import box
from inire import Bend90Seed, CongestionOptions, NetSpec, Port, RefinementOptions, RoutingOptions, RoutingProblem, SearchOptions, route
OPTIONS = RoutingOptions(
search=SearchOptions(node_limit=1, bend_radii=(10,), sbend_radii=()),
congestion=CongestionOptions(max_iterations=1, warm_start_enabled=False),
refinement=RefinementOptions(enabled=False),
)
def test_short_forward_perimeter_detour_does_not_abort_the_batch() -> None:
short = NetSpec("short", Port(30, 30, 0), Port(31, 70, 0))
peer = NetSpec("peer", Port(5, 90, 0), Port(95, 90, 0))
problem = RoutingProblem((0, 0, 100, 100), (short, peer), (box(30.3, 5, 30.6, 40),), clearance=0)
run = route(problem, options=OPTIONS)
assert run.results_by_net["short"].outcome == "unroutable"
assert run.results_by_net["peer"].is_valid
def test_forward_perimeter_detour_can_fit_at_exactly_four_radii() -> None:
net = NetSpec("edge", Port(20, 25, 0), Port(60, 25, 0))
obstacles = (box(42, 20, 45, 30), box(35, 20, 38, 30), box(75, 50, 85, 58))
problem = RoutingProblem((0, 0, 100, 100), (net,), obstacles, clearance=0)
run = route(problem, options=OPTIONS)
result = run.results_by_net[net.net_id]
assert result.is_valid
assert run.automatic.selected_planner == "perimeter"
assert sum(isinstance(move, Bend90Seed) for move in result.as_seed().segments) == 4