example fixes and improvements
This commit is contained in:
parent
e11132b51d
commit
e2c91076f7
1 changed files with 336 additions and 144 deletions
|
|
@ -17,6 +17,7 @@ from .primitives import Port, rotation_matrix2
|
|||
MoveKind = Literal["straight", "bend90", "sbend"]
|
||||
BendCollisionModelName = Literal["arc", "bbox", "clipped_bbox"]
|
||||
BendCollisionModel = BendCollisionModelName | Polygon
|
||||
BendPhysicalGeometry = Literal["arc"] | Polygon
|
||||
|
||||
|
||||
def _normalize_length(value: float) -> float:
|
||||
|
|
@ -281,6 +282,7 @@ class Bend90:
|
|||
direction: Literal["CW", "CCW"],
|
||||
sagitta: float = 0.01,
|
||||
collision_type: BendCollisionModel = "arc",
|
||||
physical_geometry_type: BendPhysicalGeometry = "arc",
|
||||
clip_margin: float | None = None,
|
||||
dilation: float = 0.0,
|
||||
) -> ComponentResult:
|
||||
|
|
@ -310,16 +312,33 @@ class Bend90:
|
|||
mirror_y=(sign < 0),
|
||||
)
|
||||
|
||||
physical_geometry = arc_polys
|
||||
if dilation > 0:
|
||||
dilated_physical_geometry = _get_arc_polygons(
|
||||
(float(center_xy[0]), float(center_xy[1])),
|
||||
if isinstance(physical_geometry_type, Polygon):
|
||||
physical_geometry = _apply_collision_model(
|
||||
arc_polys[0],
|
||||
physical_geometry_type,
|
||||
radius,
|
||||
width,
|
||||
(float(center_xy[0]), float(center_xy[1])),
|
||||
ts,
|
||||
sagitta,
|
||||
dilation=dilation,
|
||||
rotation_deg=float(start_port.r),
|
||||
mirror_y=(sign < 0),
|
||||
)
|
||||
uses_physical_custom_geometry = True
|
||||
else:
|
||||
physical_geometry = arc_polys
|
||||
uses_physical_custom_geometry = False
|
||||
if dilation > 0:
|
||||
if uses_physical_custom_geometry:
|
||||
dilated_physical_geometry = [poly.buffer(dilation) for poly in physical_geometry]
|
||||
else:
|
||||
dilated_physical_geometry = _get_arc_polygons(
|
||||
(float(center_xy[0]), float(center_xy[1])),
|
||||
radius,
|
||||
width,
|
||||
ts,
|
||||
sagitta,
|
||||
dilation=dilation,
|
||||
)
|
||||
dilated_collision_geometry = (
|
||||
dilated_physical_geometry if collision_type == "arc" else [poly.buffer(dilation) for poly in collision_polys]
|
||||
)
|
||||
|
|
@ -349,6 +368,7 @@ class SBend:
|
|||
width: float,
|
||||
sagitta: float = 0.01,
|
||||
collision_type: BendCollisionModel = "arc",
|
||||
physical_geometry_type: BendPhysicalGeometry = "arc",
|
||||
clip_margin: float | None = None,
|
||||
dilation: float = 0.0,
|
||||
) -> ComponentResult:
|
||||
|
|
@ -402,12 +422,41 @@ class SBend:
|
|||
)[0],
|
||||
]
|
||||
|
||||
physical_geometry = actual_geometry
|
||||
if dilation > 0:
|
||||
dilated_physical_geometry = [
|
||||
_get_arc_polygons((float(c1_xy[0]), float(c1_xy[1])), radius, width, ts1, sagitta, dilation=dilation)[0],
|
||||
_get_arc_polygons((float(c2_xy[0]), float(c2_xy[1])), radius, width, ts2, sagitta, dilation=dilation)[0],
|
||||
if isinstance(physical_geometry_type, Polygon):
|
||||
physical_geometry = [
|
||||
_apply_collision_model(
|
||||
arc1,
|
||||
physical_geometry_type,
|
||||
radius,
|
||||
width,
|
||||
(float(c1_xy[0]), float(c1_xy[1])),
|
||||
ts1,
|
||||
rotation_deg=float(start_port.r),
|
||||
mirror_y=(sign < 0),
|
||||
)[0],
|
||||
_apply_collision_model(
|
||||
arc2,
|
||||
physical_geometry_type,
|
||||
radius,
|
||||
width,
|
||||
(float(c2_xy[0]), float(c2_xy[1])),
|
||||
ts2,
|
||||
rotation_deg=float(start_port.r),
|
||||
mirror_y=(sign > 0),
|
||||
)[0],
|
||||
]
|
||||
uses_physical_custom_geometry = True
|
||||
else:
|
||||
physical_geometry = actual_geometry
|
||||
uses_physical_custom_geometry = False
|
||||
if dilation > 0:
|
||||
if uses_physical_custom_geometry:
|
||||
dilated_physical_geometry = [poly.buffer(dilation) for poly in physical_geometry]
|
||||
else:
|
||||
dilated_physical_geometry = [
|
||||
_get_arc_polygons((float(c1_xy[0]), float(c1_xy[1])), radius, width, ts1, sagitta, dilation=dilation)[0],
|
||||
_get_arc_polygons((float(c2_xy[0]), float(c2_xy[1])), radius, width, ts2, sagitta, dilation=dilation)[0],
|
||||
]
|
||||
dilated_collision_geometry = (
|
||||
dilated_physical_geometry if collision_type == "arc" else [poly.buffer(dilation) for poly in geometry]
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue