add mirror2d() to Rotatable

This commit is contained in:
Jan Petykiewicz 2020-11-09 22:05:56 -08:00
parent 09a5e4a2db
commit 8e1c05cf73
3 changed files with 19 additions and 3 deletions

View File

@ -121,7 +121,7 @@ class Text(RotatableImpl, Shape, metaclass=AutoSlots):
# Move these polygons to the right of the previous letter
for xys in raw_polys:
poly = Polygon(xys, dose=self.dose, layer=self.layer)
[poly.mirror(ax) for ax, do in enumerate(self.mirrored) if do]
poly.mirror2d(self.mirrored)
poly.scale_by(self.height)
poly.offset = self.offset + [total_advance, 0]
poly.rotate_around(self.offset, self.rotation)

View File

@ -138,7 +138,7 @@ class SubPattern(PositionableImpl, DoseableImpl, RotatableImpl, ScalableImpl, Mi
assert(self.pattern is not None)
pattern = self.pattern.deepcopy().deepunlock()
pattern.scale_by(self.scale)
[pattern.mirror(ax) for ax, do in enumerate(self.mirrored) if do]
pattern.mirror2d(self.mirrored)
pattern.rotate_around((0.0, 0.0), self.rotation)
pattern.translate_elements(self.offset)
pattern.scale_element_doses(self.dose)

View File

@ -1,4 +1,4 @@
from typing import TypeVar
from typing import TypeVar, Tuple
from abc import ABCMeta, abstractmethod
@ -28,6 +28,22 @@ class Mirrorable(metaclass=ABCMeta):
"""
pass
def mirror2d(self: T, axes: Tuple[bool, bool]) -> T:
"""
Optionally mirror the entity across both axes
Args:
axes: (mirror_across_x, mirror_across_y)
Returns:
self
"""
if axes[0]:
self.mirror(0)
if axes[1]:
self.mirror(1)
return self
#class MirrorableImpl(Mirrorable, metaclass=ABCMeta):
# """