From 032c410b430c60c132ad0f026c46c82a4f1d987f Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Fri, 17 May 2019 00:41:26 -0700 Subject: [PATCH] Add mirror_x to extrinsic properties It's not implemented for Polygon shapes, since I haven't thought about how to normalize those for reflection yet --- masque/pattern.py | 4 ++-- masque/shapes/arc.py | 2 +- masque/shapes/circle.py | 2 +- masque/shapes/ellipse.py | 2 +- masque/shapes/path.py | 2 +- masque/shapes/polygon.py | 2 +- masque/shapes/shape.py | 4 ++-- masque/shapes/text.py | 15 ++++++++++++--- 8 files changed, 21 insertions(+), 12 deletions(-) diff --git a/masque/pattern.py b/masque/pattern.py index 4e9d730..785b6d4 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -261,9 +261,9 @@ class Pattern: pat = Pattern(shapes=[shape]) for i, values in shape_table[label][1]: - (offset, scale, rotation, dose) = values + (offset, scale, rotation, mirror_x, dose) = values subpat = SubPattern(pattern=pat, offset=offset, scale=scale, - rotation=rotation, dose=dose) + rotation=rotation, dose=dose, mirrored=(mirror_x, False)) self.subpatterns.append(subpat) shapes_to_remove.append(i) diff --git a/masque/shapes/arc.py b/masque/shapes/arc.py index 6972e3d..c47840a 100644 --- a/masque/shapes/arc.py +++ b/masque/shapes/arc.py @@ -319,7 +319,7 @@ class Arc(Shape): width = self.width return (type(self), radii, angles, width/norm_value, self.layer), \ - (self.offset, scale/norm_value, rotation, self.dose), \ + (self.offset, scale/norm_value, rotation, False, self.dose), \ lambda: Arc(radii=radii*norm_value, angles=angles, width=width*norm_value, layer=self.layer) def get_cap_edges(self) -> numpy.ndarray: diff --git a/masque/shapes/circle.py b/masque/shapes/circle.py index 247aa78..c706856 100644 --- a/masque/shapes/circle.py +++ b/masque/shapes/circle.py @@ -102,6 +102,6 @@ class Circle(Shape): rotation = 0.0 magnitude = self.radius / norm_value return (type(self), self.layer), \ - (self.offset, magnitude, rotation, self.dose), \ + (self.offset, magnitude, rotation, False, self.dose), \ lambda: Circle(radius=norm_value, layer=self.layer) diff --git a/masque/shapes/ellipse.py b/masque/shapes/ellipse.py index 6be05c8..498d281 100644 --- a/masque/shapes/ellipse.py +++ b/masque/shapes/ellipse.py @@ -169,6 +169,6 @@ class Ellipse(Shape): scale = self.radius_y angle = (self.rotation + pi / 2) % pi return (type(self), radii, self.layer), \ - (self.offset, scale/norm_value, angle, self.dose), \ + (self.offset, scale/norm_value, angle, False, self.dose), \ lambda: Ellipse(radii=radii*norm_value, layer=self.layer) diff --git a/masque/shapes/path.py b/masque/shapes/path.py index 6525ec1..5bd612c 100644 --- a/masque/shapes/path.py +++ b/masque/shapes/path.py @@ -353,7 +353,7 @@ class Path(Shape): width0 = self.width / norm_value return (type(self), reordered_vertices.data.tobytes(), width0, self.cap, self.layer), \ - (offset, scale/norm_value, rotation, self.dose), \ + (offset, scale/norm_value, rotation, False, self.dose), \ lambda: Polygon(reordered_vertices*norm_value, width=self.width*norm_value, cap=self.cap, layer=self.layer) diff --git a/masque/shapes/polygon.py b/masque/shapes/polygon.py index 503d9a5..e42d71b 100644 --- a/masque/shapes/polygon.py +++ b/masque/shapes/polygon.py @@ -265,7 +265,7 @@ class Polygon(Shape): reordered_vertices = numpy.roll(rotated_vertices, -x_min, axis=0) return (type(self), reordered_vertices.data.tobytes(), self.layer), \ - (offset, scale/norm_value, rotation, self.dose), \ + (offset, scale/norm_value, rotation, False, self.dose), \ lambda: Polygon(reordered_vertices*norm_value, layer=self.layer) def clean_vertices(self) -> 'Polygon': diff --git a/masque/shapes/shape.py b/masque/shapes/shape.py index 00d9c18..497e7e9 100644 --- a/masque/shapes/shape.py +++ b/masque/shapes/shape.py @@ -12,7 +12,7 @@ __author__ = 'Jan Petykiewicz' # Type definitions normalized_shape_tuple = Tuple[Tuple, - Tuple[numpy.ndarray, float, float, float], + Tuple[numpy.ndarray, float, float, bool, float], Callable[[], 'Shape']] # ## Module-wide defaults @@ -101,7 +101,7 @@ class Shape(metaclass=ABCMeta): (intrinsic, extrinsic, constructor). These are further broken down as: intrinsic: A tuple of basic types containing all information about the instance that is not contained in 'extrinsic'. Usually, intrinsic[0] == type(self). - extrinsic: ([x_offset, y_offset], scale, rotation, dose) + extrinsic: ([x_offset, y_offset], scale, rotation, mirror_across_x_axis, dose) constructor: A callable (no arguments) which returns an instance of type(self) with internal state equivalent to 'intrinsic'. """ diff --git a/masque/shapes/text.py b/masque/shapes/text.py index 5c6b115..0349f4b 100644 --- a/masque/shapes/text.py +++ b/masque/shapes/text.py @@ -131,12 +131,21 @@ class Text(Shape): return self def normalized_form(self, norm_value: float) -> normalized_shape_tuple: - return (type(self), self.string, self.font_path, self.mirrored, self.layer), \ - (self.offset, self.height / norm_value, self.rotation, self.dose), \ + mirror_x, mirror_y = self.mirrored + rotation = self.rotation + if mirror_x and mirror_y: + rotation += pi + elif mirror_y: + rotation += pi + mirror_x = True + rotation %= 2 * pi + return (type(self), self.string, self.font_path, self.layer), \ + (self.offset, self.height / norm_value, rotation, mirror_x, self.dose), \ lambda: Text(string=self.string, height=self.height * norm_value, font_path=self.font_path, - mirrored=self.mirrored, + rotation=rotation, + mirrored=(mirror_x, False), layer=self.layer) def get_bounds(self) -> numpy.ndarray: