Add repetitions and split up code into traits

This commit is contained in:
Jan Petykiewicz 2020-07-22 02:45:16 -07:00
commit bab40474a0
27 changed files with 1183 additions and 929 deletions

View file

@ -5,22 +5,23 @@ from numpy import pi, inf
from . import Shape, Polygon, normalized_shape_tuple
from .. import PatternError
from ..utils import is_scalar, vector2, get_bit, normalize_mirror, layer_t
from ..traits import RotatableImpl
from ..utils import is_scalar, vector2, get_bit, normalize_mirror, layer_t, AutoSlots
# Loaded on use:
# from freetype import Face
# from matplotlib.path import Path
class Text(Shape):
class Text(RotatableImpl, Shape, metaclass=AutoSlots):
"""
Text (to be printed e.g. as a set of polygons).
This is distinct from non-printed Label objects.
"""
__slots__ = ('_string', '_height', '_rotation', '_mirrored', 'font_path')
__slots__ = ('_string', '_height', '_mirrored', 'font_path')
_string: str
_height: float
_rotation: float
_mirrored: numpy.ndarray #ndarray[bool]
font_path: str
@ -33,17 +34,6 @@ class Text(Shape):
def string(self, val: str):
self._string = val
# Rotation property
@property
def rotation(self) -> float:
return self._rotation
@rotation.setter
def rotation(self, val: float):
if not is_scalar(val):
raise PatternError('Rotation must be a scalar')
self._rotation = val % (2 * pi)
# Height property
@property
def height(self) -> float:
@ -120,10 +110,6 @@ class Text(Shape):
return all_polygons
def rotate(self, theta: float) -> 'Text':
self.rotation += theta
return self
def mirror(self, axis: int) -> 'Text':
self.mirrored[axis] = not self.mirrored[axis]
return self