Add mirror() to shapes
Might need to fix ordering on Text.to_polygons()
This commit is contained in:
parent
358f45c5fd
commit
d5a255a9d7
@ -280,6 +280,12 @@ class Arc(Shape):
|
|||||||
self.rotation += theta
|
self.rotation += theta
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def mirror(self, axis: int) -> 'Arc':
|
||||||
|
self.offset[axis - 1] *= -1
|
||||||
|
self.rotation *= -1
|
||||||
|
self.angles *= -1
|
||||||
|
return self
|
||||||
|
|
||||||
def scale_by(self, c: float) -> 'Arc':
|
def scale_by(self, c: float) -> 'Arc':
|
||||||
self.radii *= c
|
self.radii *= c
|
||||||
self.width *= c
|
self.width *= c
|
||||||
|
@ -82,6 +82,10 @@ class Circle(Shape):
|
|||||||
def rotate(self, theta: float) -> 'Circle':
|
def rotate(self, theta: float) -> 'Circle':
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def mirror(self, axis: int) -> 'Circle':
|
||||||
|
self.offset *= -1
|
||||||
|
return self
|
||||||
|
|
||||||
def scale_by(self, c: float) -> 'Circle':
|
def scale_by(self, c: float) -> 'Circle':
|
||||||
self.radius *= c
|
self.radius *= c
|
||||||
return self
|
return self
|
||||||
|
@ -142,6 +142,11 @@ class Ellipse(Shape):
|
|||||||
self.rotation += theta
|
self.rotation += theta
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def mirror(self, axis: int) -> 'Ellipse':
|
||||||
|
self.offset[axis - 1] *= -1
|
||||||
|
self.rotation *= -1
|
||||||
|
return self
|
||||||
|
|
||||||
def scale_by(self, c: float) -> 'Ellipse':
|
def scale_by(self, c: float) -> 'Ellipse':
|
||||||
self.radii *= c
|
self.radii *= c
|
||||||
return self
|
return self
|
||||||
|
@ -146,6 +146,10 @@ class Polygon(Shape):
|
|||||||
self.vertices = numpy.dot(rotation_matrix_2d(theta), self.vertices.T).T
|
self.vertices = numpy.dot(rotation_matrix_2d(theta), self.vertices.T).T
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def mirror(self, axis: int) -> 'Polygon':
|
||||||
|
self.vertices[:, axis - 1] *= -1
|
||||||
|
return self
|
||||||
|
|
||||||
def scale_by(self, c: float) -> 'Polygon':
|
def scale_by(self, c: float) -> 'Polygon':
|
||||||
self.vertices *= c
|
self.vertices *= c
|
||||||
return self
|
return self
|
||||||
|
@ -71,6 +71,16 @@ class Shape(metaclass=ABCMeta):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def mirror(self, axis: int) -> 'Shape':
|
||||||
|
"""
|
||||||
|
Mirror the shape across an axis.
|
||||||
|
|
||||||
|
:param axis: Axis to mirror across.
|
||||||
|
:return: self
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def scale_by(self, c: float) -> 'Shape':
|
def scale_by(self, c: float) -> 'Shape':
|
||||||
"""
|
"""
|
||||||
|
@ -18,6 +18,7 @@ class Text(Shape):
|
|||||||
_string = ''
|
_string = ''
|
||||||
_height = 1.0
|
_height = 1.0
|
||||||
_rotation = 0.0
|
_rotation = 0.0
|
||||||
|
_mirrored = None
|
||||||
font_path = ''
|
font_path = ''
|
||||||
|
|
||||||
# vertices property
|
# vertices property
|
||||||
@ -51,10 +52,22 @@ class Text(Shape):
|
|||||||
raise PatternError('Height must be a scalar')
|
raise PatternError('Height must be a scalar')
|
||||||
self._height = val
|
self._height = val
|
||||||
|
|
||||||
|
# Mirrored property
|
||||||
|
@property
|
||||||
|
def mirrored(self) -> List[bool]:
|
||||||
|
return self._mirrored
|
||||||
|
|
||||||
|
@mirrored.setter
|
||||||
|
def mirrored(self, val: List[bool]):
|
||||||
|
if is_scalar(val):
|
||||||
|
raise PatternError('Mirrored must be a 2-element list of booleans')
|
||||||
|
self._mirrored = val
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
string: str,
|
string: str,
|
||||||
height: float,
|
height: float,
|
||||||
font_path: str,
|
font_path: str,
|
||||||
|
mirrored: List[bool]=None,
|
||||||
rotation: float=0.0,
|
rotation: float=0.0,
|
||||||
offset: vector2=(0.0, 0.0),
|
offset: vector2=(0.0, 0.0),
|
||||||
layer: int=0,
|
layer: int=0,
|
||||||
@ -66,6 +79,9 @@ class Text(Shape):
|
|||||||
self.height = height
|
self.height = height
|
||||||
self.rotation = rotation
|
self.rotation = rotation
|
||||||
self.font_path = font_path
|
self.font_path = font_path
|
||||||
|
if mirrored is None:
|
||||||
|
mirrored = [False, False]
|
||||||
|
self.mirrored = mirrored
|
||||||
|
|
||||||
def to_polygons(self,
|
def to_polygons(self,
|
||||||
_poly_num_points: int=None,
|
_poly_num_points: int=None,
|
||||||
@ -79,9 +95,9 @@ class Text(Shape):
|
|||||||
# Move these polygons to the right of the previous letter
|
# Move these polygons to the right of the previous letter
|
||||||
for xys in raw_polys:
|
for xys in raw_polys:
|
||||||
poly = Polygon(xys, dose=self.dose, layer=self.layer)
|
poly = Polygon(xys, dose=self.dose, layer=self.layer)
|
||||||
|
[poly.mirror(ax) for ax, do in enumerate(self.mirrored) if do]
|
||||||
poly.scale_by(self.height)
|
poly.scale_by(self.height)
|
||||||
poly.offset = self.offset + [total_advance, 0]
|
poly.offset = self.offset + [total_advance, 0]
|
||||||
# poly.scale_by(self.height)
|
|
||||||
poly.rotate_around(self.offset, self.rotation)
|
poly.rotate_around(self.offset, self.rotation)
|
||||||
all_polygons += [poly]
|
all_polygons += [poly]
|
||||||
|
|
||||||
@ -94,16 +110,21 @@ class Text(Shape):
|
|||||||
self.rotation += theta
|
self.rotation += theta
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def mirror(self, axis: int) -> 'Text':
|
||||||
|
self.mirrored[axis] = not self.mirrored[axis]
|
||||||
|
return self
|
||||||
|
|
||||||
def scale_by(self, c: float) -> 'Text':
|
def scale_by(self, c: float) -> 'Text':
|
||||||
self.height *= c
|
self.height *= c
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def normalized_form(self, norm_value: float) -> normalized_shape_tuple:
|
def normalized_form(self, norm_value: float) -> normalized_shape_tuple:
|
||||||
return (type(self), self.string, self.font_path, self.layer), \
|
return (type(self), self.string, self.font_path, self.mirrored, self.layer), \
|
||||||
(self.offset, self.height / norm_value, self.rotation, self.dose), \
|
(self.offset, self.height / norm_value, self.rotation, self.dose), \
|
||||||
lambda: Text(string=self.string,
|
lambda: Text(string=self.string,
|
||||||
height=self.height * norm_value,
|
height=self.height * norm_value,
|
||||||
font_path=self.font_path,
|
font_path=self.font_path,
|
||||||
|
mirrored=self.mirrored,
|
||||||
layer=self.layer)
|
layer=self.layer)
|
||||||
|
|
||||||
def get_bounds(self) -> numpy.ndarray:
|
def get_bounds(self) -> numpy.ndarray:
|
||||||
|
Loading…
Reference in New Issue
Block a user