refactor
This commit is contained in:
parent
0c432bd229
commit
dcc4d6436c
1 changed files with 1385 additions and 715 deletions
|
|
@ -8,7 +8,7 @@ from shapely.affinity import scale as shapely_scale
|
|||
from shapely.affinity import translate as shapely_translate
|
||||
from shapely.geometry import Polygon, box
|
||||
|
||||
from inire.constants import TOLERANCE_ANGULAR, TOLERANCE_LINEAR
|
||||
from inire.constants import TOLERANCE_ANGULAR
|
||||
from .primitives import Port, rotation_matrix2
|
||||
|
||||
|
||||
|
|
@ -18,6 +18,7 @@ def _normalize_length(value: float) -> float:
|
|||
|
||||
class ComponentResult:
|
||||
__slots__ = (
|
||||
"start_port",
|
||||
"geometry",
|
||||
"dilated_geometry",
|
||||
"proxy_geometry",
|
||||
|
|
@ -34,6 +35,7 @@ class ComponentResult:
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
start_port: Port,
|
||||
geometry: list[Polygon],
|
||||
end_port: Port,
|
||||
length: float,
|
||||
|
|
@ -43,6 +45,7 @@ class ComponentResult:
|
|||
actual_geometry: list[Polygon] | None = None,
|
||||
dilated_actual_geometry: list[Polygon] | None = None,
|
||||
) -> None:
|
||||
self.start_port = start_port
|
||||
self.geometry = geometry
|
||||
self.dilated_geometry = dilated_geometry
|
||||
self.proxy_geometry = proxy_geometry
|
||||
|
|
@ -80,6 +83,7 @@ class ComponentResult:
|
|||
|
||||
def translate(self, dx: int | float, dy: int | float) -> ComponentResult:
|
||||
return ComponentResult(
|
||||
start_port=self.start_port + [dx, dy, 0],
|
||||
geometry=[shapely_translate(poly, dx, dy) for poly in self.geometry],
|
||||
end_port=self.end_port + [dx, dy, 0],
|
||||
length=self.length,
|
||||
|
|
@ -87,7 +91,11 @@ class ComponentResult:
|
|||
dilated_geometry=None if self.dilated_geometry is None else [shapely_translate(poly, dx, dy) for poly in self.dilated_geometry],
|
||||
proxy_geometry=None if self.proxy_geometry is None else [shapely_translate(poly, dx, dy) for poly in self.proxy_geometry],
|
||||
actual_geometry=None if self.actual_geometry is None else [shapely_translate(poly, dx, dy) for poly in self.actual_geometry],
|
||||
dilated_actual_geometry=None if self.dilated_actual_geometry is None else [shapely_translate(poly, dx, dy) for poly in self.dilated_actual_geometry],
|
||||
dilated_actual_geometry=(
|
||||
None
|
||||
if self.dilated_actual_geometry is None
|
||||
else [shapely_translate(poly, dx, dy) for poly in self.dilated_actual_geometry]
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -226,11 +234,19 @@ class Straight:
|
|||
dilated_geometry = None
|
||||
if dilation > 0:
|
||||
half_w_d = half_w + dilation
|
||||
pts_d = numpy.array(((-dilation, half_w_d), (length_f + dilation, half_w_d), (length_f + dilation, -half_w_d), (-dilation, -half_w_d)))
|
||||
pts_d = numpy.array(
|
||||
(
|
||||
(-dilation, half_w_d),
|
||||
(length_f + dilation, half_w_d),
|
||||
(length_f + dilation, -half_w_d),
|
||||
(-dilation, -half_w_d),
|
||||
)
|
||||
)
|
||||
poly_points_d = (pts_d @ rot2.T) + numpy.array((start_port.x, start_port.y))
|
||||
dilated_geometry = [Polygon(poly_points_d)]
|
||||
|
||||
return ComponentResult(
|
||||
start_port=start_port,
|
||||
geometry=geometry,
|
||||
end_port=end_port,
|
||||
length=abs(length_f),
|
||||
|
|
@ -299,10 +315,18 @@ class Bend90:
|
|||
dilated_actual_geometry = [poly.buffer(dilation) for poly in collision_polys]
|
||||
dilated_geometry = dilated_actual_geometry
|
||||
else:
|
||||
dilated_actual_geometry = _get_arc_polygons((float(center_xy[0]), float(center_xy[1])), radius, width, ts, sagitta, dilation=dilation)
|
||||
dilated_actual_geometry = _get_arc_polygons(
|
||||
(float(center_xy[0]), float(center_xy[1])),
|
||||
radius,
|
||||
width,
|
||||
ts,
|
||||
sagitta,
|
||||
dilation=dilation,
|
||||
)
|
||||
dilated_geometry = dilated_actual_geometry if collision_type == "arc" else [poly.buffer(dilation) for poly in collision_polys]
|
||||
|
||||
return ComponentResult(
|
||||
start_port=start_port,
|
||||
geometry=collision_polys,
|
||||
end_port=end_port,
|
||||
length=abs(radius) * numpy.pi / 2.0,
|
||||
|
|
@ -398,6 +422,7 @@ class SBend:
|
|||
dilated_geometry = dilated_actual_geometry if collision_type == "arc" else [poly.buffer(dilation) for poly in geometry]
|
||||
|
||||
return ComponentResult(
|
||||
start_port=start_port,
|
||||
geometry=geometry,
|
||||
end_port=end_port,
|
||||
length=2.0 * radius * theta,
|
||||
|
|
|
|||
Loading…
Reference in a new issue