Choose forward detour lanes from nearby keepouts
This commit is contained in:
parent
c32148c312
commit
4537392641
2 changed files with 29 additions and 10 deletions
|
|
@ -262,25 +262,30 @@ def perimeter_detour_candidates(problem: RoutingProblem, search: SearchOptions)
|
|||
spare = net.target.x - net.start.x - 4 * radius
|
||||
if spare < 0 or not obstacles:
|
||||
continue
|
||||
padding = problem.clearance + net.width / 2
|
||||
nearby = tuple(bounds for bounds in obstacles if bounds[0] <= net.target.x + padding and bounds[2] >= net.start.x - padding)
|
||||
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):
|
||||
if all(bottom > high or top < low or right < net.start.x or left > net.target.x for left, bottom, right, top in nearby):
|
||||
continue
|
||||
margin = ceil(problem.clearance + net.width / 2 + 1)
|
||||
lanes = (max(ceil(top + margin) for _, _, _, top in obstacles), min(floor(bottom - margin) for _, bottom, _, _ in obstacles))
|
||||
margin = ceil(padding + 1)
|
||||
top = max(ceil(top + margin) for _, _, _, top in nearby)
|
||||
bottom = min(floor(bottom - margin) for _, bottom, _, _ in nearby)
|
||||
lanes, fallback_lanes = [], []
|
||||
for y, fallback in ((top, high + 2 * radius), (bottom, low - 2 * radius)):
|
||||
if min(abs(y - low), abs(y - high)) >= 2 * radius:
|
||||
lanes.append(y)
|
||||
else:
|
||||
fallback_lanes.append(fallback)
|
||||
end_slack = 1 if spare >= 2 else 0
|
||||
pivots = {net.start.x + radius + end_slack, net.target.x - radius - end_slack}
|
||||
pivots.update(
|
||||
x
|
||||
for left, _, right, _ in obstacles
|
||||
for left, _, right, _ in nearby
|
||||
for x in (floor(left - radius - margin), ceil(right + radius + margin))
|
||||
if net.start.x + radius <= x <= net.target.x - radius
|
||||
)
|
||||
for y in lanes:
|
||||
if (
|
||||
abs(y - net.start.y) < 2 * radius
|
||||
or abs(y - net.target.y) < 2 * radius
|
||||
or not problem.bounds[1] + net.width / 2 <= y <= problem.bounds[3] - net.width / 2
|
||||
):
|
||||
for y in (*lanes, *fallback_lanes):
|
||||
if not problem.bounds[1] + net.width / 2 <= y <= problem.bounds[3] - net.width / 2:
|
||||
continue
|
||||
for first, last in combinations(sorted(pivots), 2):
|
||||
if last - first < 2 * radius:
|
||||
|
|
|
|||
|
|
@ -53,6 +53,20 @@ def test_tight_forward_perimeter_detours_use_pivots_without_extra_end_spacing(fo
|
|||
assert sum(isinstance(move, Bend90Seed) for move in result.as_seed().segments) == 4
|
||||
|
||||
|
||||
def test_forward_perimeter_lanes_ignore_keepouts_beyond_the_target() -> None:
|
||||
net = NetSpec("through", Port(20, 60, 0), Port(120, 60, 0))
|
||||
problem = RoutingProblem((0, 0, 200, 120), (net,), (box(55, 30, 85, 90),), clearance=0)
|
||||
distant = (box(150, 0, 160, 4), box(150, 116, 160, 120))
|
||||
|
||||
clean = route(problem, options=OPTIONS).results_by_net[net.net_id]
|
||||
cluttered = route(replace(problem, static_obstacles=(*problem.static_obstacles, *distant)), options=OPTIONS)
|
||||
|
||||
result = cluttered.results_by_net[net.net_id]
|
||||
assert cluttered.automatic.selected_planner == "perimeter"
|
||||
assert result.is_valid
|
||||
assert result.as_seed() == clean.as_seed()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("smaller_radius", [10, 17.5])
|
||||
def test_perimeter_detours_choose_a_radius_usable_by_the_planner(smaller_radius) -> None:
|
||||
net = NetSpec("wide", Port(20, 70, 0), Port(220, 70, 0), width=30)
|
||||
|
|
|
|||
Loading…
Reference in a new issue