Fix core geometry snapping, A* target lookahead, and test configurations
This commit is contained in:
parent
24ca402f67
commit
d438c5b7c7
1 changed files with 1463 additions and 476 deletions
|
|
@ -28,7 +28,8 @@ class ComponentResult:
|
|||
"""
|
||||
__slots__ = (
|
||||
'geometry', 'dilated_geometry', 'proxy_geometry', 'actual_geometry',
|
||||
'end_port', 'length', 'move_type', 'bounds', 'dilated_bounds', '_t_cache'
|
||||
'end_port', 'length', 'move_type', 'bounds', 'dilated_bounds',
|
||||
'total_bounds', 'total_dilated_bounds', 'total_bounds_box', 'total_dilated_bounds_box', '_t_cache'
|
||||
)
|
||||
|
||||
def __init__(
|
||||
|
|
@ -53,7 +54,28 @@ class ComponentResult:
|
|||
if not skip_bounds:
|
||||
# Vectorized bounds calculation
|
||||
self.bounds = shapely.bounds(geometry)
|
||||
self.dilated_bounds = shapely.bounds(dilated_geometry) if dilated_geometry is not None else None
|
||||
# Total bounds across all polygons in the move
|
||||
self.total_bounds = numpy.array([
|
||||
numpy.min(self.bounds[:, 0]),
|
||||
numpy.min(self.bounds[:, 1]),
|
||||
numpy.max(self.bounds[:, 2]),
|
||||
numpy.max(self.bounds[:, 3])
|
||||
])
|
||||
self.total_bounds_box = box(*self.total_bounds)
|
||||
|
||||
if dilated_geometry is not None:
|
||||
self.dilated_bounds = shapely.bounds(dilated_geometry)
|
||||
self.total_dilated_bounds = numpy.array([
|
||||
numpy.min(self.dilated_bounds[:, 0]),
|
||||
numpy.min(self.dilated_bounds[:, 1]),
|
||||
numpy.max(self.dilated_bounds[:, 2]),
|
||||
numpy.max(self.dilated_bounds[:, 3])
|
||||
])
|
||||
self.total_dilated_bounds_box = box(*self.total_dilated_bounds)
|
||||
else:
|
||||
self.dilated_bounds = None
|
||||
self.total_dilated_bounds = None
|
||||
self.total_dilated_bounds_box = None
|
||||
|
||||
def translate(self, dx: float, dy: float) -> ComponentResult:
|
||||
"""
|
||||
|
|
@ -96,17 +118,21 @@ class ComponentResult:
|
|||
|
||||
# Optimize: reuse and translate bounds
|
||||
res.bounds = self.bounds + [dx, dy, dx, dy]
|
||||
res.total_bounds = self.total_bounds + [dx, dy, dx, dy]
|
||||
res.total_bounds_box = box(*res.total_bounds)
|
||||
|
||||
if self.dilated_bounds is not None:
|
||||
res.dilated_bounds = self.dilated_bounds + [dx, dy, dx, dy]
|
||||
res.total_dilated_bounds = self.total_dilated_bounds + [dx, dy, dx, dy]
|
||||
res.total_dilated_bounds_box = box(*res.total_dilated_bounds)
|
||||
else:
|
||||
res.total_dilated_bounds = None
|
||||
res.total_dilated_bounds_box = None
|
||||
|
||||
self._t_cache[(dxr, dyr)] = res
|
||||
return res
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Straight:
|
||||
"""
|
||||
Move generator for straight waveguide segments.
|
||||
|
|
@ -347,6 +373,7 @@ class Bend90:
|
|||
collision_type: Literal["arc", "bbox", "clipped_bbox"] | Polygon = "arc",
|
||||
clip_margin: float = 10.0,
|
||||
dilation: float = 0.0,
|
||||
snap_to_grid: bool = True,
|
||||
snap_size: float = SEARCH_GRID_SNAP_UM,
|
||||
) -> ComponentResult:
|
||||
"""
|
||||
|
|
@ -371,8 +398,12 @@ class Bend90:
|
|||
# Snap the end point to the grid
|
||||
ex_raw = cx + radius * numpy.cos(t_end)
|
||||
ey_raw = cy + radius * numpy.sin(t_end)
|
||||
ex = snap_search_grid(ex_raw, snap_size)
|
||||
ey = snap_search_grid(ey_raw, snap_size)
|
||||
|
||||
if snap_to_grid:
|
||||
ex = snap_search_grid(ex_raw, snap_size)
|
||||
ey = snap_search_grid(ey_raw, snap_size)
|
||||
else:
|
||||
ex, ey = ex_raw, ey_raw
|
||||
|
||||
# Slightly adjust radius to hit snapped point exactly
|
||||
actual_radius = numpy.sqrt((ex - cx)**2 + (ey - cy)**2)
|
||||
|
|
@ -422,6 +453,7 @@ class SBend:
|
|||
collision_type: Literal["arc", "bbox", "clipped_bbox"] | Polygon = "arc",
|
||||
clip_margin: float = 10.0,
|
||||
dilation: float = 0.0,
|
||||
snap_to_grid: bool = True,
|
||||
snap_size: float = SEARCH_GRID_SNAP_UM,
|
||||
) -> ComponentResult:
|
||||
"""
|
||||
|
|
@ -434,9 +466,16 @@ class SBend:
|
|||
dx_init = 2 * radius * numpy.sin(theta_init)
|
||||
rad_start = numpy.radians(start_port.orientation)
|
||||
|
||||
# Snap the target point
|
||||
ex = snap_search_grid(start_port.x + dx_init * numpy.cos(rad_start) - offset * numpy.sin(rad_start), snap_size)
|
||||
ey = snap_search_grid(start_port.y + dx_init * numpy.sin(rad_start) + offset * numpy.cos(rad_start), snap_size)
|
||||
# Target point
|
||||
ex_raw = start_port.x + dx_init * numpy.cos(rad_start) - offset * numpy.sin(rad_start)
|
||||
ey_raw = start_port.y + dx_init * numpy.sin(rad_start) + offset * numpy.cos(rad_start)
|
||||
|
||||
if snap_to_grid:
|
||||
ex = snap_search_grid(ex_raw, snap_size)
|
||||
ey = snap_search_grid(ey_raw, snap_size)
|
||||
else:
|
||||
ex, ey = ex_raw, ey_raw
|
||||
|
||||
end_port = Port(ex, ey, start_port.orientation)
|
||||
|
||||
# Solve for theta and radius that hit (ex, ey) exactly
|
||||
|
|
|
|||
Loading…
Reference in a new issue