Snap return-detour board pivots inward

This commit is contained in:
Jan Petykiewicz 2026-11-30 11:24:18 -08:00
commit a83b5ed155
2 changed files with 17 additions and 3 deletions

View file

@ -218,11 +218,13 @@ def _return_detours(
high = max(start.y, target.y) + 2 * radius high = max(start.y, target.y) + 2 * radius
bottom = min(low, min((floor(bottom - margin) for _, bottom, _, _ in obstacles), default=low)) 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)) 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: for left, _, right, _ in obstacles:
pivots.update((floor(left - margin), ceil(right + margin))) pivots.update((floor(left - margin), ceil(right + margin)))
departures = sorted(x for x in pivots if start.x + radius <= x <= xmax - half_width) departures = sorted(x for x in pivots if start.x + radius <= x <= right_edge)
arrivals = sorted((x for x in pivots if xmin + half_width <= x <= target.x - radius), reverse=True) arrivals = sorted((x for x in pivots if left_edge <= x <= target.x - radius), reverse=True)
for y in (bottom, top): for y in (bottom, top):
if not ymin + half_width <= y <= ymax - half_width: if not ymin + half_width <= y <= ymax - half_width:
continue continue

View file

@ -49,3 +49,15 @@ def test_perimeter_detours_choose_a_radius_usable_by_the_planner(smaller_radius)
assert result.is_valid assert result.is_valid
assert run.automatic.selected_planner == "perimeter" assert run.automatic.selected_planner == "perimeter"
assert {move.radius for move in result.as_seed().segments if isinstance(move, Bend90Seed)} == {20} 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