diff --git a/masque/pattern.py b/masque/pattern.py index a63bb6d..fe75fb6 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -70,6 +70,15 @@ class Pattern: self.name = name + def __deepcopy__(self, memo: Dict = None) -> 'Pattern': + memo = {} if memo is None else memo + new = copy.copy(self) + new.name = self.name + new.shapes = copy.deepcopy(self.shapes, memo) + new.labels = copy.deepcopy(self.labels, memo) + new.subpatterns = copy.deepcopy(self.subpatterns, memo) + return new + def append(self, other_pattern: 'Pattern') -> 'Pattern': """ Appends all shapes, labels and subpatterns from other_pattern to self's shapes, diff --git a/masque/repetition.py b/masque/repetition.py index 2d153e3..efa91a7 100644 --- a/masque/repetition.py +++ b/masque/repetition.py @@ -3,7 +3,7 @@ instances of a Pattern in the same parent Pattern. """ -from typing import Union, List +from typing import Union, List, Dict import copy import numpy @@ -86,6 +86,16 @@ class GridRepetition: mirrored = [False, False] self.mirrored = mirrored + def __deepcopy__(self, memo: Dict = None) -> 'GridReptition': + memo = {} if memo is None else memo + new = copy.copy(self) + new.pattern = copy.deepcopy(self.pattern, memo) + new._offset = self._offset.copy() + new._mirrored = copy.deepcopy(self._mirrored, memo) + new._a_vector = self._a_vector.copy() + new._b_vector = copy.copy(self._b_vector) # ndarray or None so don't need deepcopy + return new + # offset property @property def offset(self) -> numpy.ndarray: diff --git a/masque/shapes/arc.py b/masque/shapes/arc.py index bb2da3a..ee6bf15 100644 --- a/masque/shapes/arc.py +++ b/masque/shapes/arc.py @@ -1,4 +1,4 @@ -from typing import List, Tuple +from typing import List, Tuple, Dict import math import numpy from numpy import pi @@ -159,6 +159,14 @@ class Arc(Shape): self.poly_num_points = poly_num_points self.poly_max_arclen = poly_max_arclen + def __deepcopy__(self, memo: Dict = None) -> 'Arc': + memo = {} if memo is None else memo + new = copy.copy(self) + new._offset = self._offset.copy() + new._radii = self._radii.copy() + new._angles = self._angles.copy() + return new + def to_polygons(self, poly_num_points: int=None, poly_max_arclen: float=None) -> List[Polygon]: if poly_num_points is None: poly_num_points = self.poly_num_points diff --git a/masque/shapes/circle.py b/masque/shapes/circle.py index 489a608..785a382 100644 --- a/masque/shapes/circle.py +++ b/masque/shapes/circle.py @@ -1,4 +1,4 @@ -from typing import List +from typing import List, Dict import numpy from numpy import pi @@ -53,6 +53,12 @@ class Circle(Shape): self.poly_num_points = poly_num_points self.poly_max_arclen = poly_max_arclen + def __deepcopy__(self, memo: Dict = None) -> 'Circle': + memo = {} if memo is None else memo + new = copy.copy(self) + new._offset = self._offset.copy() + return new + def to_polygons(self, poly_num_points: int=None, poly_max_arclen: float=None) -> List[Polygon]: if poly_num_points is None: poly_num_points = self.poly_num_points diff --git a/masque/shapes/ellipse.py b/masque/shapes/ellipse.py index 724c11d..7064bd5 100644 --- a/masque/shapes/ellipse.py +++ b/masque/shapes/ellipse.py @@ -1,4 +1,4 @@ -from typing import List, Tuple +from typing import List, Tuple, Dict import math import numpy from numpy import pi @@ -98,6 +98,13 @@ class Ellipse(Shape): self.poly_num_points = poly_num_points self.poly_max_arclen = poly_max_arclen + def __deepcopy__(self, memo: Dict = None) -> 'Ellipse': + memo = {} if memo is None else memo + new = copy.copy(self) + new._offset = self._offset.copy() + new._radii = self._radii.copy() + return new + def to_polygons(self, poly_num_points: int=None, poly_max_arclen: float=None diff --git a/masque/shapes/path.py b/masque/shapes/path.py index 8edcf21..a09bae1 100644 --- a/masque/shapes/path.py +++ b/masque/shapes/path.py @@ -1,4 +1,4 @@ -from typing import List, Tuple +from typing import List, Tuple, Dict import copy from enum import Enum import numpy @@ -162,6 +162,15 @@ class Path(Shape): self.rotate(rotation) [self.mirror(a) for a, do in enumerate(mirrored) if do] + def __deepcopy__(self, memo: Dict = None) -> 'Path': + memo = {} if memo is None else memo + new = copy.copy(self) + new._offset = self._offset.copy() + new._vertices = self._vertices.copy() + new._cap = copy.deepcopy(self._cap, memo) + new._cap_extensions = copy.deepcopy(self._cap_extensions, memo) + return new + @staticmethod def travel(travel_pairs: Tuple[Tuple[float, float]], width: float = 0.0, diff --git a/masque/shapes/polygon.py b/masque/shapes/polygon.py index afb47a6..403689c 100644 --- a/masque/shapes/polygon.py +++ b/masque/shapes/polygon.py @@ -1,4 +1,4 @@ -from typing import List, Tuple +from typing import List, Tuple, Dict import copy import numpy from numpy import pi @@ -84,6 +84,13 @@ class Polygon(Shape): self.rotate(rotation) [self.mirror(a) for a, do in enumerate(mirrored) if do] + def __deepcopy__(self, memo: Dict = None) -> 'Polygon': + memo = {} if memo is None else memo + new = copy.copy(self) + new._offset = self._offset.copy() + new._vertices = self._vertices.copy() + return new + @staticmethod def square(side_length: float, rotation: float=0.0, diff --git a/masque/shapes/text.py b/masque/shapes/text.py index 8da2a65..d265d64 100644 --- a/masque/shapes/text.py +++ b/masque/shapes/text.py @@ -1,4 +1,5 @@ -from typing import List, Tuple +from typing import List, Tuple, Dict +import copy import numpy from numpy import pi, inf @@ -81,6 +82,13 @@ class Text(Shape): self.font_path = font_path self.mirrored = mirrored + def __deepcopy__(self, memo: Dict = None) -> 'Text': + memo = {} if memo is None else memo + new = copy.copy(self) + new._offset = self._offset.copy() + new._mirrored = copy.deepcopy(self._mirrored, memo) + return new + def to_polygons(self, _poly_num_points: int=None, _poly_max_arclen: float=None diff --git a/masque/subpattern.py b/masque/subpattern.py index 0415894..88fe2ee 100644 --- a/masque/subpattern.py +++ b/masque/subpattern.py @@ -3,7 +3,7 @@ offset, rotation, scaling, and other such properties to the reference. """ -from typing import Union, List +from typing import Union, List, Dict import copy import numpy @@ -45,6 +45,14 @@ class SubPattern: mirrored = [False, False] self.mirrored = mirrored + def __deepcopy__(self, memo: Dict = None) -> 'SubPattern': + memo = {} if memo is None else memo + new = copy.copy(self) + new.pattern = copy.deepcopy(self.pattern, memo) + new._offset = self._offset.copy() + new._mirrored = copy.deepcopy(self._mirrored, memo) + return new + # offset property @property def offset(self) -> numpy.ndarray: