Keep constructive routing available without triangulation
This commit is contained in:
parent
c3e420eadb
commit
760182f25c
1 changed files with 260 additions and 153 deletions
|
|
@ -149,9 +149,6 @@ class RoutingWorld:
|
|||
def _ensure_static_tree(self) -> None:
|
||||
self._static_obstacles.ensure_tree()
|
||||
|
||||
def _ensure_net_static_tree(self, net_width: float) -> STRtree:
|
||||
return self._static_obstacles.ensure_net_tree(net_width)
|
||||
|
||||
def _ensure_static_raw_tree(self) -> None:
|
||||
self._static_obstacles.ensure_raw_tree()
|
||||
|
||||
|
|
@ -200,32 +197,13 @@ class RoutingWorld:
|
|||
)
|
||||
return reach < length - 0.001
|
||||
|
||||
def _is_in_safety_zone_fast(self, idx: int, start_port: Port | None, end_port: Port | None) -> bool:
|
||||
bounds_array = self._static_obstacles.bounds_array
|
||||
if bounds_array is None:
|
||||
return False
|
||||
bounds = bounds_array[idx]
|
||||
safety_zone = self.safety_zone_radius
|
||||
if (
|
||||
start_port
|
||||
and bounds[0] - safety_zone <= start_port.x <= bounds[2] + safety_zone
|
||||
and bounds[1] - safety_zone <= start_port.y <= bounds[3] + safety_zone
|
||||
):
|
||||
return True
|
||||
return bool(
|
||||
end_port
|
||||
and bounds[0] - safety_zone <= end_port.x <= bounds[2] + safety_zone
|
||||
and bounds[1] - safety_zone <= end_port.y <= bounds[3] + safety_zone
|
||||
)
|
||||
|
||||
def _is_in_safety_zone(
|
||||
self,
|
||||
geometry: Polygon,
|
||||
obj_id: int,
|
||||
raw_obstacle: Polygon,
|
||||
start_port: Port | None,
|
||||
end_port: Port | None,
|
||||
) -> bool:
|
||||
raw_obstacle = self._static_obstacles.geometries[obj_id]
|
||||
safety_zone = self.safety_zone_radius
|
||||
|
||||
obstacle_bounds = raw_obstacle.bounds
|
||||
|
|
@ -272,53 +250,20 @@ class RoutingWorld:
|
|||
start_port: Port | None = None,
|
||||
end_port: Port | None = None,
|
||||
) -> bool:
|
||||
# TODO: If static buffering becomes net-width-specific, add dedicated
|
||||
# width-aware geometry/index handling instead of reviving dead args here.
|
||||
static_obstacles = self._static_obstacles
|
||||
if not static_obstacles.dilated:
|
||||
self._ensure_static_raw_tree()
|
||||
tree = self._static_obstacles.raw_tree
|
||||
if tree is None:
|
||||
return False
|
||||
|
||||
self._ensure_static_tree()
|
||||
tree = static_obstacles.tree
|
||||
bounds_array = static_obstacles.bounds_array
|
||||
if tree is None or bounds_array is None:
|
||||
return False
|
||||
|
||||
hits = tree.query(box(*result.total_dilated_bounds))
|
||||
if hits.size == 0:
|
||||
return False
|
||||
|
||||
move_poly_bounds = result.dilated_bounds
|
||||
clearance = self.clearance
|
||||
left, bottom, right, top = result.total_bounds
|
||||
# Expand the whole proxy envelope, including the tangent faces of an arc.
|
||||
hits = tree.query(box(left - clearance, bottom - clearance, right + clearance, top + clearance))
|
||||
obstacles = tree.geometries
|
||||
for hit_idx in hits:
|
||||
obstacle_bounds = bounds_array[hit_idx]
|
||||
poly_hits_obstacle_aabb = False
|
||||
for poly_bounds in move_poly_bounds:
|
||||
if (
|
||||
poly_bounds[0] < obstacle_bounds[2]
|
||||
and poly_bounds[2] > obstacle_bounds[0]
|
||||
and poly_bounds[1] < obstacle_bounds[3]
|
||||
and poly_bounds[3] > obstacle_bounds[1]
|
||||
):
|
||||
poly_hits_obstacle_aabb = True
|
||||
break
|
||||
|
||||
if not poly_hits_obstacle_aabb:
|
||||
continue
|
||||
|
||||
obj_id = static_obstacles.obj_ids[hit_idx]
|
||||
if self._is_in_safety_zone_fast(hit_idx, start_port, end_port):
|
||||
collision_found = False
|
||||
for polygon in result.collision_geometry:
|
||||
if not self._is_in_safety_zone(polygon, obj_id, start_port, end_port):
|
||||
collision_found = True
|
||||
break
|
||||
if collision_found:
|
||||
return True
|
||||
continue
|
||||
|
||||
static_obstacle = static_obstacles.dilated[obj_id]
|
||||
for polygon in result.dilated_collision_geometry:
|
||||
if polygon.intersects(static_obstacle) and not polygon.touches(static_obstacle):
|
||||
obstacle = obstacles[hit_idx]
|
||||
for polygon in result.collision_geometry:
|
||||
if _violates_clearance(polygon, obstacle, clearance) and not self._is_in_safety_zone(polygon, obstacle, start_port, end_port):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
|
@ -792,10 +737,7 @@ class RoutingWorld:
|
|||
min_y, max_y = sorted([origin.y, origin.y + dy])
|
||||
|
||||
if net_width is not None:
|
||||
tree = self._ensure_net_static_tree(net_width)
|
||||
key = (round(net_width, 4), round(self.clearance, 4))
|
||||
is_rect_array = static_obstacles.net_specific_is_rect[key]
|
||||
bounds_array = static_obstacles.net_specific_bounds[key]
|
||||
tree, is_rect_array, bounds_array = static_obstacles.ensure_net_tree(net_width)
|
||||
else:
|
||||
self._ensure_static_tree()
|
||||
tree = static_obstacles.tree
|
||||
|
|
|
|||
Loading…
Reference in a new issue