fixup! [Mirrorable / Flippable] Bifurcate mirror into flip (relative to line) vs mirror (relative to own offset/origin)
This commit is contained in:
parent
51ced2fe83
commit
2d63e72802
6 changed files with 41 additions and 17 deletions
|
|
@ -10,7 +10,7 @@ import numpy
|
|||
from numpy import pi
|
||||
from numpy.typing import ArrayLike, NDArray
|
||||
|
||||
from .traits import PositionableImpl, Rotatable, PivotableImpl, Copyable, Mirrorable, Flippable, FlippableImpl
|
||||
from .traits import PositionableImpl, Rotatable, PivotableImpl, Copyable, Mirrorable, Flippable
|
||||
from .utils import rotate_offsets_around, rotation_matrix_2d
|
||||
from .error import PortError, format_stacktrace
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
@functools.total_ordering
|
||||
class Port(PositionableImpl, Rotatable, PivotableImpl, Copyable, FlippableImpl):
|
||||
class Port(PositionableImpl, Rotatable, PivotableImpl, Copyable, Flippable):
|
||||
"""
|
||||
A point at which a `Device` can be snapped to another `Device`.
|
||||
|
||||
|
|
@ -99,6 +99,25 @@ class Port(PositionableImpl, Rotatable, PivotableImpl, Copyable, FlippableImpl):
|
|||
self.ptype = ptype
|
||||
return self
|
||||
|
||||
def flip_across(self, axis: int | None = None, *, x: float | None = None, y: float | None = None) -> Self:
|
||||
"""
|
||||
Mirror the object across a line.
|
||||
|
||||
Args:
|
||||
axis: Axis to mirror across. 0 mirrors across y=0. 1 mirrors across x=0.
|
||||
x: Vertical line x=val to mirror across.
|
||||
y: Horizontal line y=val to mirror across.
|
||||
|
||||
Returns:
|
||||
self
|
||||
"""
|
||||
axis, pivot = self._check_flip_args(axis=axis, x=x, y=y)
|
||||
self.translate(-pivot)
|
||||
self.mirror(axis)
|
||||
self.offset[1 - axis] *= -1
|
||||
self.translate(+pivot)
|
||||
return self
|
||||
|
||||
def mirror(self, axis: int = 0) -> Self:
|
||||
if self.rotation is not None:
|
||||
self.rotation *= -1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue