Cosmetic changes to argument lists

This commit is contained in:
Jan Petykiewicz 2019-05-17 00:39:46 -07:00
parent 58353b7884
commit 16c6bfc70a
9 changed files with 85 additions and 73 deletions

View File

@ -94,10 +94,10 @@ class Pattern:
return self return self
def subset(self, def subset(self,
shapes_func: Callable[[Shape], bool]=None, shapes_func: Callable[[Shape], bool] = None,
labels_func: Callable[[Label], bool]=None, labels_func: Callable[[Label], bool] = None,
subpatterns_func: Callable[[SubPattern], bool]=None, subpatterns_func: Callable[[SubPattern], bool] = None,
recursive: bool=False, recursive: bool = False,
) -> 'Pattern': ) -> 'Pattern':
""" """
Returns a Pattern containing only the entities (e.g. shapes) for which the Returns a Pattern containing only the entities (e.g. shapes) for which the
@ -133,7 +133,7 @@ class Pattern:
def apply(self, def apply(self,
func: Callable[['Pattern'], 'Pattern'], func: Callable[['Pattern'], 'Pattern'],
memo: Dict[int, 'Pattern']=None, memo: Dict[int, 'Pattern'] = None,
) -> 'Pattern': ) -> 'Pattern':
""" """
Recursively apply func() to this pattern and any pattern it references. Recursively apply func() to this pattern and any pattern it references.
@ -166,8 +166,8 @@ class Pattern:
return pat return pat
def polygonize(self, def polygonize(self,
poly_num_points: int=None, poly_num_points: int = None,
poly_max_arclen: float=None poly_max_arclen: float = None,
) -> 'Pattern': ) -> 'Pattern':
""" """
Calls .to_polygons(...) on all the shapes in this Pattern and any referenced patterns, Calls .to_polygons(...) on all the shapes in this Pattern and any referenced patterns,
@ -191,7 +191,7 @@ class Pattern:
def manhattanize(self, def manhattanize(self,
grid_x: numpy.ndarray, grid_x: numpy.ndarray,
grid_y: numpy.ndarray grid_y: numpy.ndarray,
) -> 'Pattern': ) -> 'Pattern':
""" """
Calls .polygonize() and .flatten on the pattern, then calls .manhattanize() on all the Calls .polygonize() and .flatten on the pattern, then calls .manhattanize() on all the
@ -209,9 +209,9 @@ class Pattern:
return self return self
def subpatternize(self, def subpatternize(self,
recursive: bool=True, recursive: bool = True,
norm_value: int=1e6, norm_value: int = int(1e6),
exclude_types: Tuple[Shape]=(Polygon,) exclude_types: Tuple[Shape] = (Polygon,)
) -> 'Pattern': ) -> 'Pattern':
""" """
Iterates through this Pattern and all referenced Patterns. Within each Pattern, it iterates Iterates through this Pattern and all referenced Patterns. Within each Pattern, it iterates
@ -529,10 +529,10 @@ class Pattern:
return self return self
def visualize(self, def visualize(self,
offset: vector2=(0., 0.), offset: vector2 = (0., 0.),
line_color: str='k', line_color: str = 'k',
fill_color: str='none', fill_color: str = 'none',
overdraw: bool=False): overdraw: bool = False):
""" """
Draw a picture of the Pattern and wait for the user to inspect it Draw a picture of the Pattern and wait for the user to inspect it

View File

@ -140,13 +140,13 @@ class Arc(Shape):
radii: vector2, radii: vector2,
angles: vector2, angles: vector2,
width: float, width: float,
poly_num_points: int=DEFAULT_POLY_NUM_POINTS, poly_num_points: int = DEFAULT_POLY_NUM_POINTS,
poly_max_arclen: float=None, poly_max_arclen: float = None,
offset: vector2=(0.0, 0.0), offset: vector2 = (0.0, 0.0),
rotation: float=0, rotation: float = 0,
mirrored: Tuple[bool] = (False, False), mirrored: Tuple[bool] = (False, False),
layer: int=0, layer: int = 0,
dose: float=1.0): dose: float = 1.0):
self.identifier = () self.identifier = ()
self.radii = radii self.radii = radii
self.angles = angles self.angles = angles
@ -167,7 +167,10 @@ class Arc(Shape):
new._angles = self._angles.copy() new._angles = self._angles.copy()
return new return new
def to_polygons(self, poly_num_points: int=None, poly_max_arclen: float=None) -> List[Polygon]: def to_polygons(self,
poly_num_points: int = None,
poly_max_arclen: float = None,
) -> List[Polygon]:
if poly_num_points is None: if poly_num_points is None:
poly_num_points = self.poly_num_points poly_num_points = self.poly_num_points
if poly_max_arclen is None: if poly_max_arclen is None:

View File

@ -39,11 +39,11 @@ class Circle(Shape):
def __init__(self, def __init__(self,
radius: float, radius: float,
poly_num_points: int=DEFAULT_POLY_NUM_POINTS, poly_num_points: int = DEFAULT_POLY_NUM_POINTS,
poly_max_arclen: float=None, poly_max_arclen: float = None,
offset: vector2=(0.0, 0.0), offset: vector2 = (0.0, 0.0),
layer: int=0, layer: int = 0,
dose: float=1.0): dose: float = 1.0):
self.identifier = () self.identifier = ()
self.offset = numpy.array(offset, dtype=float) self.offset = numpy.array(offset, dtype=float)
self.layer = layer self.layer = layer
@ -58,7 +58,10 @@ class Circle(Shape):
new._offset = self._offset.copy() new._offset = self._offset.copy()
return new return new
def to_polygons(self, poly_num_points: int=None, poly_max_arclen: float=None) -> List[Polygon]: def to_polygons(self,
poly_num_points: int = None,
poly_max_arclen: float = None,
) -> List[Polygon]:
if poly_num_points is None: if poly_num_points is None:
poly_num_points = self.poly_num_points poly_num_points = self.poly_num_points
if poly_max_arclen is None: if poly_max_arclen is None:

View File

@ -81,13 +81,13 @@ class Ellipse(Shape):
def __init__(self, def __init__(self,
radii: vector2, radii: vector2,
poly_num_points: int=DEFAULT_POLY_NUM_POINTS, poly_num_points: int = DEFAULT_POLY_NUM_POINTS,
poly_max_arclen: float=None, poly_max_arclen: float = None,
offset: vector2=(0.0, 0.0), offset: vector2 = (0.0, 0.0),
rotation: float=0, rotation: float = 0,
mirrored: Tuple[bool] = (False, False), mirrored: Tuple[bool] = (False, False),
layer: int=0, layer: int = 0,
dose: float=1.0): dose: float = 1.0):
self.identifier = () self.identifier = ()
self.radii = radii self.radii = radii
self.offset = offset self.offset = offset
@ -106,8 +106,8 @@ class Ellipse(Shape):
return new return new
def to_polygons(self, def to_polygons(self,
poly_num_points: int=None, poly_num_points: int = None,
poly_max_arclen: float=None poly_max_arclen: float = None,
) -> List[Polygon]: ) -> List[Polygon]:
if poly_num_points is None: if poly_num_points is None:
poly_num_points = self.poly_num_points poly_num_points = self.poly_num_points

View File

@ -149,8 +149,8 @@ class Path(Shape):
offset: vector2 = (0.0, 0.0), offset: vector2 = (0.0, 0.0),
rotation: float = 0, rotation: float = 0,
mirrored: Tuple[bool] = (False, False), mirrored: Tuple[bool] = (False, False),
layer: int=0, layer: int = 0,
dose: float=1.0, dose: float = 1.0,
) -> 'Path': ) -> 'Path':
self._cap_extensions = None # Since .cap setter might access it self._cap_extensions = None # Since .cap setter might access it
@ -180,11 +180,11 @@ class Path(Shape):
width: float = 0.0, width: float = 0.0,
cap: 'Path.Cap' = Cap.Flush, cap: 'Path.Cap' = Cap.Flush,
cap_extensions = None, cap_extensions = None,
offset: vector2=(0.0, 0.0), offset: vector2 = (0.0, 0.0),
rotation: float = 0, rotation: float = 0,
mirrored: Tuple[bool] = (False, False), mirrored: Tuple[bool] = (False, False),
layer: int=0, layer: int = 0,
dose: float=1.0, dose: float = 1.0,
) -> 'Path': ) -> 'Path':
""" """
Build a path by specifying the turn angles and travel distances Build a path by specifying the turn angles and travel distances
@ -220,8 +220,8 @@ class Path(Shape):
layer=layer, dose=dose) layer=layer, dose=dose)
def to_polygons(self, def to_polygons(self,
poly_num_points: int=None, poly_num_points: int = None,
poly_max_arclen: float=None, poly_max_arclen: float = None,
) -> List['Polygon']: ) -> List['Polygon']:
extensions = self._calculate_cap_extensions() extensions = self._calculate_cap_extensions()

View File

@ -72,11 +72,11 @@ class Polygon(Shape):
def __init__(self, def __init__(self,
vertices: numpy.ndarray, vertices: numpy.ndarray,
offset: vector2=(0.0, 0.0), offset: vector2 = (0.0, 0.0),
rotation: float=0.0, rotation: float = 0.0,
mirrored: Tuple[bool] = (False, False), mirrored: Tuple[bool] = (False, False),
layer: int=0, layer: int = 0,
dose: float=1.0, dose: float = 1.0,
): ):
self.identifier = () self.identifier = ()
self.layer = layer self.layer = layer
@ -95,10 +95,10 @@ class Polygon(Shape):
@staticmethod @staticmethod
def square(side_length: float, def square(side_length: float,
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,
dose: float=1.0 dose: float = 1.0,
) -> 'Polygon': ) -> 'Polygon':
""" """
Draw a square given side_length, centered on the origin. Draw a square given side_length, centered on the origin.
@ -122,10 +122,10 @@ class Polygon(Shape):
@staticmethod @staticmethod
def rectangle(lx: float, def rectangle(lx: float,
ly: float, ly: float,
rotation: float=0, rotation: float = 0,
offset: vector2=(0.0, 0.0), offset: vector2 = (0.0, 0.0),
layer: int=0, layer: int = 0,
dose: float=1.0 dose: float = 1.0,
) -> 'Polygon': ) -> 'Polygon':
""" """
Draw a rectangle with side lengths lx and ly, centered on the origin. Draw a rectangle with side lengths lx and ly, centered on the origin.
@ -156,7 +156,7 @@ class Polygon(Shape):
ymax: float = None, ymax: float = None,
ly: float = None, ly: float = None,
layer: int = 0, layer: int = 0,
dose: float = 1.0 dose: float = 1.0,
) -> 'Polygon': ) -> 'Polygon':
""" """
Draw a rectangle by specifying side/center positions. Draw a rectangle by specifying side/center positions.
@ -222,8 +222,8 @@ class Polygon(Shape):
def to_polygons(self, def to_polygons(self,
_poly_num_points: int=None, _poly_num_points: int = None,
_poly_max_arclen: float=None, _poly_max_arclen: float = None,
) -> List['Polygon']: ) -> List['Polygon']:
return [copy.deepcopy(self)] return [copy.deepcopy(self)]

View File

@ -193,7 +193,10 @@ class Shape(metaclass=ABCMeta):
self.translate(+pivot) self.translate(+pivot)
return self return self
def manhattanize_fast(self, grid_x: numpy.ndarray, grid_y: numpy.ndarray) -> List['Polygon']: def manhattanize_fast(self,
grid_x: numpy.ndarray,
grid_y: numpy.ndarray,
) -> List['Polygon']:
""" """
Returns a list of polygons with grid-aligned ("Manhattan") edges approximating the shape. Returns a list of polygons with grid-aligned ("Manhattan") edges approximating the shape.
@ -295,7 +298,10 @@ class Shape(metaclass=ABCMeta):
return manhattan_polygons return manhattan_polygons
def manhattanize(self, grid_x: numpy.ndarray, grid_y: numpy.ndarray) -> List['Polygon']: def manhattanize(self,
grid_x: numpy.ndarray,
grid_y: numpy.ndarray
) -> List['Polygon']:
""" """
Returns a list of polygons with grid-aligned ("Manhattan") edges approximating the shape. Returns a list of polygons with grid-aligned ("Manhattan") edges approximating the shape.

View File

@ -73,11 +73,11 @@ class Text(Shape):
string: str, string: str,
height: float, height: float,
font_path: str, font_path: str,
offset: vector2=(0.0, 0.0), offset: vector2 = (0.0, 0.0),
rotation: float=0.0, rotation: float = 0.0,
mirrored: Tuple[bool]=(False, False), mirrored: Tuple[bool] = (False, False),
layer: int=0, layer: int = 0,
dose: float=1.0): dose: float = 1.0):
self.offset = offset self.offset = offset
self.layer = layer self.layer = layer
self.dose = dose self.dose = dose
@ -95,8 +95,8 @@ class Text(Shape):
return new return new
def to_polygons(self, def to_polygons(self,
_poly_num_points: int=None, _poly_num_points: int = None,
_poly_max_arclen: float=None _poly_max_arclen: float = None,
) -> List[Polygon]: ) -> List[Polygon]:
all_polygons = [] all_polygons = []
total_advance = 0 total_advance = 0
@ -153,7 +153,7 @@ class Text(Shape):
def get_char_as_polygons(font_path: str, def get_char_as_polygons(font_path: str,
char: str, char: str,
resolution: float=48*64, resolution: float = 48*64,
) -> Tuple[List[List[List[float]]], float]: ) -> Tuple[List[List[List[float]]], float]:
from freetype import Face from freetype import Face
from matplotlib.path import Path from matplotlib.path import Path

View File

@ -32,11 +32,11 @@ class SubPattern:
def __init__(self, def __init__(self,
pattern: 'Pattern', pattern: 'Pattern',
offset: vector2=(0.0, 0.0), offset: vector2 = (0.0, 0.0),
rotation: float=0.0, rotation: float = 0.0,
mirrored: List[bool]=None, mirrored: List[bool] = None,
dose: float=1.0, dose: float = 1.0,
scale: float=1.0): scale: float = 1.0):
self.identifier = () self.identifier = ()
self.pattern = pattern self.pattern = pattern
self.offset = offset self.offset = offset