2023-02-23 13:37:34 -08:00
|
|
|
from typing import Self
|
2020-07-22 02:45:16 -07:00
|
|
|
from abc import ABCMeta, abstractmethod
|
|
|
|
|
2020-09-10 20:06:58 -07:00
|
|
|
|
2020-07-22 02:45:16 -07:00
|
|
|
class Mirrorable(metaclass=ABCMeta):
|
|
|
|
"""
|
2023-04-07 23:19:55 -07:00
|
|
|
Trait class for all mirrorable entities
|
2020-07-22 02:45:16 -07:00
|
|
|
"""
|
|
|
|
__slots__ = ()
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-04-14 22:19:56 -07:00
|
|
|
def mirror(self, axis: int = 0) -> Self:
|
2020-07-22 02:45:16 -07:00
|
|
|
"""
|
|
|
|
Mirror the entity across an axis.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
axis: Axis to mirror across.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
self
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2023-04-14 22:19:56 -07:00
|
|
|
def mirror2d(self, across_x: bool = False, across_y: bool = False) -> Self:
|
2020-11-09 22:05:56 -08:00
|
|
|
"""
|
|
|
|
Optionally mirror the entity across both axes
|
|
|
|
|
|
|
|
Args:
|
|
|
|
axes: (mirror_across_x, mirror_across_y)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
self
|
|
|
|
"""
|
2023-04-14 22:19:56 -07:00
|
|
|
if across_x:
|
2020-11-09 22:05:56 -08:00
|
|
|
self.mirror(0)
|
2023-04-14 22:19:56 -07:00
|
|
|
if across_y:
|
2020-11-09 22:05:56 -08:00
|
|
|
self.mirror(1)
|
|
|
|
return self
|
|
|
|
|
2020-07-22 02:45:16 -07:00
|
|
|
|
|
|
|
#class MirrorableImpl(Mirrorable, metaclass=ABCMeta):
|
|
|
|
# """
|
|
|
|
# Simple implementation of `Mirrorable`
|
|
|
|
# """
|
|
|
|
# __slots__ = ()
|
|
|
|
#
|
|
|
|
# _mirrored: numpy.ndarray # ndarray[bool]
|
|
|
|
# """ Whether to mirror the instance across the x and/or y axes. """
|
|
|
|
#
|
2023-04-07 23:19:55 -07:00
|
|
|
# #
|
|
|
|
# # Properties
|
|
|
|
# #
|
2020-07-22 02:45:16 -07:00
|
|
|
# # Mirrored property
|
|
|
|
# @property
|
|
|
|
# def mirrored(self) -> numpy.ndarray: # ndarray[bool]
|
|
|
|
# """ Whether to mirror across the [x, y] axes, respectively """
|
|
|
|
# return self._mirrored
|
|
|
|
#
|
|
|
|
# @mirrored.setter
|
|
|
|
# def mirrored(self, val: Sequence[bool]):
|
|
|
|
# if is_scalar(val):
|
2020-11-09 21:59:28 -08:00
|
|
|
# raise MasqueError('Mirrored must be a 2-element list of booleans')
|
2020-07-22 02:45:16 -07:00
|
|
|
# self._mirrored = numpy.array(val, dtype=bool, copy=True)
|
|
|
|
#
|
2023-04-07 23:19:55 -07:00
|
|
|
# #
|
|
|
|
# # Methods
|
|
|
|
# #
|