Score refinement moves before materializing geometry
This commit is contained in:
parent
9ddef652e1
commit
d9f0e78330
1 changed files with 128 additions and 45 deletions
|
|
@ -16,6 +16,8 @@ from .primitives import Port, rotation_matrix2
|
|||
if TYPE_CHECKING:
|
||||
from collections.abc import Sequence
|
||||
|
||||
from numpy.typing import NDArray
|
||||
|
||||
|
||||
MoveKind = Literal["straight", "bend90", "sbend"]
|
||||
BendCollisionModelName = Literal["arc", "bbox", "clipped_bbox"]
|
||||
|
|
@ -27,6 +29,15 @@ def _normalize_length(value: float) -> float:
|
|||
return float(value)
|
||||
|
||||
|
||||
def _advance_port(start: Port, rotation: NDArray[numpy.int32], forward: float, lateral: float = 0.0, turn: int = 0) -> Port:
|
||||
dx, dy = rotation @ numpy.array((forward, lateral))
|
||||
return Port(start.x + dx, start.y + dy, start.r + turn)
|
||||
|
||||
|
||||
def _bend90_length(radius: float) -> float:
|
||||
return abs(radius) * numpy.pi / 2.0
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class ComponentResult:
|
||||
start_port: Port
|
||||
|
|
@ -240,8 +251,7 @@ class Straight:
|
|||
) -> ComponentResult:
|
||||
rot2 = rotation_matrix2(start_port.r)
|
||||
length_f = _normalize_length(length)
|
||||
disp = rot2 @ numpy.array((length_f, 0.0))
|
||||
end_port = Port(start_port.x + disp[0], start_port.y + disp[1], start_port.r)
|
||||
end_port = _advance_port(start_port, rot2, length_f)
|
||||
|
||||
half_w = width / 2.0
|
||||
pts = numpy.array(((0.0, half_w), (length_f, half_w), (length_f, -half_w), (0.0, -half_w)))
|
||||
|
|
@ -293,10 +303,8 @@ class Bend90:
|
|||
sign = 1 if direction == "CCW" else -1
|
||||
|
||||
center_local = numpy.array((0.0, sign * radius))
|
||||
end_local = numpy.array((radius, sign * radius))
|
||||
center_xy = (rot2 @ center_local) + numpy.array((start_port.x, start_port.y))
|
||||
end_xy = (rot2 @ end_local) + numpy.array((start_port.x, start_port.y))
|
||||
end_port = Port(end_xy[0], end_xy[1], start_port.r + sign * 90)
|
||||
end_port = _advance_port(start_port, rot2, radius, sign * radius, sign * 90)
|
||||
|
||||
start_theta = start_port.r - sign * 90
|
||||
end_theta = start_port.r
|
||||
|
|
@ -353,7 +361,7 @@ class Bend90:
|
|||
start_port=start_port,
|
||||
collision_geometry=collision_polys,
|
||||
end_port=end_port,
|
||||
length=abs(radius) * numpy.pi / 2.0,
|
||||
length=_bend90_length(radius),
|
||||
move_type="bend90",
|
||||
move_spec=Bend90Seed(radius=radius, direction=direction),
|
||||
physical_geometry=physical_geometry,
|
||||
|
|
|
|||
Loading…
Reference in a new issue