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
|
|
@ -6,8 +6,8 @@ from numpy.typing import ArrayLike, NDArray
|
|||
|
||||
from ..error import MasqueError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .positionable import Positionable
|
||||
from .positionable import Positionable
|
||||
from .repeatable import Repeatable
|
||||
|
||||
|
||||
class Mirrorable(metaclass=ABCMeta):
|
||||
|
|
@ -54,7 +54,7 @@ class Flippable(metaclass=ABCMeta):
|
|||
__slots__ = ()
|
||||
|
||||
@staticmethod
|
||||
def _check_flip_args(axis: int | None = None, *, x: float | None = None, y: float | None = None) -> tuple[int, float]:
|
||||
def _check_flip_args(axis: int | None = None, *, x: float | None = None, y: float | None = None) -> tuple[int, NDArray[numpy.float64]]:
|
||||
pivot = numpy.zeros(2)
|
||||
if axis is not None:
|
||||
if x is not None or y is not None:
|
||||
|
|
@ -63,9 +63,9 @@ class Flippable(metaclass=ABCMeta):
|
|||
if x is not None:
|
||||
if y is not None:
|
||||
raise MasqueError('Cannot specify both x and y')
|
||||
return 0, pivot + (x, 0)
|
||||
return 1, pivot + (x, 0)
|
||||
if y is not None:
|
||||
return 1, pivot + (0, y)
|
||||
return 0, pivot + (0, y)
|
||||
raise MasqueError('Must specify one of axis, x, or y')
|
||||
|
||||
@abstractmethod
|
||||
|
|
@ -84,9 +84,10 @@ class Flippable(metaclass=ABCMeta):
|
|||
pass
|
||||
|
||||
|
||||
class FlippableImpl(Flippable, metaclass=ABCMeta):
|
||||
class FlippableImpl(Flippable, Repeatable, metaclass=ABCMeta):
|
||||
"""
|
||||
Implementation of `Flippable` for objects which are `Mirrorable` and `Positionable`.
|
||||
Implementation of `Flippable` for objects which are `Mirrorable`, `Positionable`,
|
||||
and `Repeatable`.
|
||||
"""
|
||||
__slots__ = ()
|
||||
|
||||
|
|
@ -97,6 +98,8 @@ class FlippableImpl(Flippable, metaclass=ABCMeta):
|
|||
axis, pivot = self._check_flip_args(axis=axis, x=x, y=y)
|
||||
cast('Positionable', self).translate(-pivot)
|
||||
cast('Mirrorable', self).mirror(axis)
|
||||
if self.repetition is not None:
|
||||
self.repetition.mirror(axis)
|
||||
self.offset[1 - axis] *= -1
|
||||
cast('Positionable', self).translate(+pivot)
|
||||
return self
|
||||
|
|
|
|||
Loading…
Reference in a new issue