Custom deepcopy() implementations to help speed things up

This commit is contained in:
Jan Petykiewicz 2019-05-15 00:19:37 -07:00
commit a461446059
9 changed files with 80 additions and 8 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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,

View file

@ -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