make sure to check self-intersections

This commit is contained in:
Jan Petykiewicz 2026-03-21 00:59:29 -07:00
commit de7254f8f5

View file

@ -49,7 +49,7 @@ class ComponentResult:
_offsets: list[int] | None = None,
_coords_cache: numpy.ndarray | None = None,
_base_result: ComponentResult | None = None,
_offset: list[float] | None = None,
_offset: numpy.ndarray | None = None,
snap_size: float = SEARCH_GRID_SNAP_UM,
rel_gx: int | None = None,
rel_gy: int | None = None,
@ -216,17 +216,18 @@ class ComponentResult:
base = self._base_result
if base is not None:
dx, dy = self._offset
shift = numpy.array([dx, dy, dx, dy])
# Vectorized addition is faster if we avoid creating new lists/arrays in the loop
if base._bounds is not None:
self._bounds = base._bounds + [dx, dy, dx, dy]
self._bounds = base._bounds + shift
if base._total_bounds is not None:
b = base._total_bounds
self._total_bounds = numpy.array([b[0]+dx, b[1]+dy, b[2]+dx, b[3]+dy])
self._total_bounds = b + shift
if base._dilated_bounds is not None:
self._dilated_bounds = base._dilated_bounds + [dx, dy, dx, dy]
self._dilated_bounds = base._dilated_bounds + shift
if base._total_dilated_bounds is not None:
b = base._total_dilated_bounds
self._total_dilated_bounds = numpy.array([b[0]+dx, b[1]+dy, b[2]+dx, b[3]+dy])
self._total_dilated_bounds = b + shift
self._bounds_cached = True
def translate(self, dx: float, dy: float, rel_gx: int | None = None, rel_gy: int | None = None, rel_go: int | None = None) -> ComponentResult:
@ -241,10 +242,10 @@ class ComponentResult:
if self._base_result:
base = self._base_result
current_offset = self._offset
new_offset = [current_offset[0] + dx, current_offset[1] + dy]
new_offset = numpy.array([current_offset[0] + dx, current_offset[1] + dy])
else:
base = self
new_offset = [dx, dy]
new_offset = numpy.array([dx, dy])
return ComponentResult(
end_port=new_port,
@ -607,6 +608,11 @@ class SBend:
actual_radius = abs(local_dy) / denom
# Safety Check: Reject SBends with tiny radii that would cause self-overlap
# (inner_radius becomes negative if actual_radius < width/2)
if actual_radius < width:
raise ValueError(f"SBend actual_radius {actual_radius:.3f} is too small (width={width})")
# Limit radius to prevent giant arcs
if actual_radius > 100000.0:
actual_len = numpy.sqrt(local_dx**2 + local_dy**2)