From a83b5ed155d9bb68772626d03bba1e14b7e4277b Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 30 Nov 2026 11:24:18 -0800 Subject: [PATCH] Snap return-detour board pivots inward --- inire/router/_perimeter.py | 8 +++++--- inire/tests/test_perimeter.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/inire/router/_perimeter.py b/inire/router/_perimeter.py index 39e89e1..5189d4a 100644 --- a/inire/router/_perimeter.py +++ b/inire/router/_perimeter.py @@ -218,11 +218,13 @@ def _return_detours( high = max(start.y, target.y) + 2 * radius bottom = min(low, min((floor(bottom - margin) for _, bottom, _, _ in obstacles), default=low)) top = max(high, max((ceil(top + margin) for _, _, _, top in obstacles), default=high)) - pivots = {xmin + half_width, xmax - half_width, start.x + radius + 1, target.x - radius - 1} + left_edge = ceil(xmin + half_width) + right_edge = floor(xmax - half_width) + pivots = {left_edge, right_edge, start.x + radius + 1, target.x - radius - 1} for left, _, right, _ in obstacles: pivots.update((floor(left - margin), ceil(right + margin))) - departures = sorted(x for x in pivots if start.x + radius <= x <= xmax - half_width) - arrivals = sorted((x for x in pivots if xmin + half_width <= x <= target.x - radius), reverse=True) + departures = sorted(x for x in pivots if start.x + radius <= x <= right_edge) + arrivals = sorted((x for x in pivots if left_edge <= x <= target.x - radius), reverse=True) for y in (bottom, top): if not ymin + half_width <= y <= ymax - half_width: continue diff --git a/inire/tests/test_perimeter.py b/inire/tests/test_perimeter.py index 171b93a..8a95105 100644 --- a/inire/tests/test_perimeter.py +++ b/inire/tests/test_perimeter.py @@ -49,3 +49,15 @@ def test_perimeter_detours_choose_a_radius_usable_by_the_planner(smaller_radius) assert result.is_valid assert run.automatic.selected_planner == "perimeter" assert {move.radius for move in result.as_seed().segments if isinstance(move, Bend90Seed)} == {20} + + +def test_return_detours_snap_board_pivots_inward_before_generating_seeds() -> None: + net = NetSpec("return", Port(88, 50, 0), Port(12, 50, 0), width=3) + problem = RoutingProblem((0, 0, 100, 100), (net,), 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 result.path[-1].end_port == net.target