go to a tunable 5um grid
This commit is contained in:
parent
7b0dddfe45
commit
91256cbcf9
1 changed files with 222 additions and 233 deletions
|
|
@ -10,21 +10,24 @@ from .primitives import Port
|
|||
|
||||
|
||||
|
||||
# Search Grid Snap (1.0 µm)
|
||||
SEARCH_GRID_SNAP_UM = 1.0
|
||||
# Search Grid Snap (5.0 µm default)
|
||||
SEARCH_GRID_SNAP_UM = 5.0
|
||||
|
||||
|
||||
def snap_search_grid(value: float) -> float:
|
||||
def snap_search_grid(value: float, snap_size: float = SEARCH_GRID_SNAP_UM) -> float:
|
||||
"""
|
||||
Snap a coordinate to the nearest search grid unit.
|
||||
|
||||
Args:
|
||||
value: Value to snap.
|
||||
snap_size: The grid size to snap to.
|
||||
|
||||
Returns:
|
||||
Snapped value.
|
||||
"""
|
||||
return round(value / SEARCH_GRID_SNAP_UM) * SEARCH_GRID_SNAP_UM
|
||||
if snap_size <= 0:
|
||||
return value
|
||||
return round(value / snap_size) * snap_size
|
||||
|
||||
|
||||
class ComponentResult:
|
||||
|
|
@ -144,6 +147,7 @@ class Straight:
|
|||
width: float,
|
||||
snap_to_grid: bool = True,
|
||||
dilation: float = 0.0,
|
||||
snap_size: float = SEARCH_GRID_SNAP_UM,
|
||||
) -> ComponentResult:
|
||||
"""
|
||||
Generate a straight waveguide segment.
|
||||
|
|
@ -154,6 +158,7 @@ class Straight:
|
|||
width: Waveguide width.
|
||||
snap_to_grid: Whether to snap the end port to the search grid.
|
||||
dilation: Optional dilation distance for pre-calculating collision geometry.
|
||||
snap_size: Grid size for snapping.
|
||||
|
||||
Returns:
|
||||
A ComponentResult containing the straight segment.
|
||||
|
|
@ -166,8 +171,8 @@ class Straight:
|
|||
ey = start_port.y + length * sin_val
|
||||
|
||||
if snap_to_grid:
|
||||
ex = snap_search_grid(ex)
|
||||
ey = snap_search_grid(ey)
|
||||
ex = snap_search_grid(ex, snap_size)
|
||||
ey = snap_search_grid(ey, snap_size)
|
||||
|
||||
end_port = Port(ex, ey, start_port.orientation)
|
||||
actual_length = numpy.sqrt((end_port.x - start_port.x)**2 + (end_port.y - start_port.y)**2)
|
||||
|
|
@ -415,6 +420,7 @@ class Bend90:
|
|||
collision_type: Literal["arc", "bbox", "clipped_bbox"] | Polygon = "arc",
|
||||
clip_margin: float = 10.0,
|
||||
dilation: float = 0.0,
|
||||
snap_size: float = SEARCH_GRID_SNAP_UM,
|
||||
) -> ComponentResult:
|
||||
"""
|
||||
Generate a 90-degree bend.
|
||||
|
|
@ -430,8 +436,8 @@ class Bend90:
|
|||
t_end_init = t_start_init + (numpy.pi / 2 if direction == "CCW" else -numpy.pi / 2)
|
||||
|
||||
# Snap the target point
|
||||
ex = snap_search_grid(cx_init + radius * numpy.cos(t_end_init))
|
||||
ey = snap_search_grid(cy_init + radius * numpy.sin(t_end_init))
|
||||
ex = snap_search_grid(cx_init + radius * numpy.cos(t_end_init), snap_size)
|
||||
ey = snap_search_grid(cy_init + radius * numpy.sin(t_end_init), snap_size)
|
||||
end_port = Port(ex, ey, float((start_port.orientation + turn_angle) % 360))
|
||||
|
||||
# Adjust geometry to perfectly hit snapped port
|
||||
|
|
@ -503,6 +509,7 @@ class SBend:
|
|||
collision_type: Literal["arc", "bbox", "clipped_bbox"] | Polygon = "arc",
|
||||
clip_margin: float = 10.0,
|
||||
dilation: float = 0.0,
|
||||
snap_size: float = SEARCH_GRID_SNAP_UM,
|
||||
) -> ComponentResult:
|
||||
"""
|
||||
Generate a parametric S-bend (two tangent arcs).
|
||||
|
|
@ -515,8 +522,8 @@ class SBend:
|
|||
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))
|
||||
ey = snap_search_grid(start_port.y + dx_init * numpy.sin(rad_start) + offset * numpy.cos(rad_start))
|
||||
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)
|
||||
end_port = Port(ex, ey, start_port.orientation)
|
||||
|
||||
# Solve for theta and radius that hit (ex, ey) exactly
|
||||
|
|
|
|||
Loading…
Reference in a new issue