Fix routing clearance, retries, and S-bend verification

This commit is contained in:
Jan Petykiewicz 2026-11-27 21:40:53 -08:00
commit 196cd00445

View file

@ -11,6 +11,7 @@ from inire.geometry.component_overlap import count_path_self_collisions
from inire.geometry.components import check_path_geometry, path_within_board
from inire.geometry.dynamic_path_index import DynamicPathIndex
from inire.geometry.index_helpers import grid_cell_span
from inire.geometry.primitives import rotate_cardinal
from inire.results import RoutingReport
from inire.geometry.static_obstacle_index import StaticObstacleIndex
@ -187,16 +188,6 @@ class RoutingWorld:
def has_dynamic_paths(self) -> bool:
return bool(self._dynamic_paths.geometries)
def check_move_straight_static(self, start_port: Port, length: float, net_width: float) -> bool:
reach = self.ray_cast(
start_port,
start_port.r,
max_dist=length + 0.01,
net_width=net_width,
caller="straight_static",
)
return reach < length - 0.001
def _is_in_safety_zone(
self,
geometry: Polygon,
@ -718,6 +709,37 @@ class RoutingWorld:
cache[key] = reach
return reach
def straight_reach(self, origin: Port, max_dist: float, net_width: float) -> float:
"""Find where a fixed-width, flat-ended trace first enters a keepout."""
self._ensure_static_raw_tree()
tree = self._static_obstacles.raw_tree
if tree is None:
return max_dist
dx, dy = rotate_cardinal(max_dist, 0, int(origin.r))
half_x, half_y = (0.0, net_width / 2) if dx else (net_width / 2, 0.0)
left, right = sorted((origin.x, origin.x + dx))
bottom, top = sorted((origin.y, origin.y + dy))
left, bottom, right, top = left - half_x, bottom - half_y, right + half_x, top + half_y
strip = box(left, bottom, right, top)
clearance = self.clearance
padding = clearance - TOLERANCE_LINEAR * min(1.0, clearance)
candidates = tree.query(box(left - padding, bottom - padding, right + padding, top + padding))
axis = 0 if dx else 1
start = origin.x if dx else origin.y
direction = 1 if (dx or dy) > 0 else -1
face = axis if direction > 0 else axis + 2
reach = max_dist
obstacles = tree.geometries
for index in candidates:
obstacle = obstacles[index]
keepout = obstacle.buffer(padding) if padding > 0 else obstacle
overlap = keepout.intersection(strip)
if overlap.area:
reach = min(reach, direction * (overlap.bounds[face] - start))
return reach
def _cast_static_ray(
self,
origin: Port,