cleanup
This commit is contained in:
parent
ed021e3d81
commit
ff8ca92963
13 changed files with 29 additions and 24 deletions
|
|
@ -400,11 +400,12 @@ class Pather(Builder, PatherMixin):
|
||||||
kwargs_plug = kwargs | {'plug_into': plug_into}
|
kwargs_plug = kwargs | {'plug_into': plug_into}
|
||||||
self.path(portspec, ccw0, length - abs(jog1), **kwargs_no_out)
|
self.path(portspec, ccw0, length - abs(jog1), **kwargs_no_out)
|
||||||
self.path(portspec, not ccw0, abs(jog - jog0), **kwargs_plug)
|
self.path(portspec, not ccw0, abs(jog - jog0), **kwargs_plug)
|
||||||
return self
|
|
||||||
except (BuildError, NotImplementedError):
|
except (BuildError, NotImplementedError):
|
||||||
if not self._dead:
|
if not self._dead:
|
||||||
raise
|
raise
|
||||||
# Fall through to dummy extension below
|
# Fall through to dummy extension below
|
||||||
|
else:
|
||||||
|
return self
|
||||||
except BuildError:
|
except BuildError:
|
||||||
if not self._dead:
|
if not self._dead:
|
||||||
raise
|
raise
|
||||||
|
|
|
||||||
|
|
@ -528,11 +528,12 @@ class RenderPather(PatherMixin):
|
||||||
kwargs_plug = kwargs | {'plug_into': plug_into}
|
kwargs_plug = kwargs | {'plug_into': plug_into}
|
||||||
self.path(portspec, ccw0, length - abs(jog1), **kwargs_no_out)
|
self.path(portspec, ccw0, length - abs(jog1), **kwargs_no_out)
|
||||||
self.path(portspec, not ccw0, abs(jog - jog0), **kwargs_plug)
|
self.path(portspec, not ccw0, abs(jog - jog0), **kwargs_plug)
|
||||||
return self
|
|
||||||
except (BuildError, NotImplementedError):
|
except (BuildError, NotImplementedError):
|
||||||
if not self._dead:
|
if not self._dead:
|
||||||
raise
|
raise
|
||||||
# Fall through to dummy extension below
|
# Fall through to dummy extension below
|
||||||
|
else:
|
||||||
|
return self
|
||||||
except BuildError:
|
except BuildError:
|
||||||
if not self._dead:
|
if not self._dead:
|
||||||
raise
|
raise
|
||||||
|
|
|
||||||
|
|
@ -763,7 +763,7 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
|
||||||
Returns:
|
Returns:
|
||||||
(name, pattern) tuple
|
(name, pattern) tuple
|
||||||
"""
|
"""
|
||||||
from .pattern import Pattern
|
from .pattern import Pattern #noqa: PLC0415
|
||||||
pat = Pattern()
|
pat = Pattern()
|
||||||
self[name] = pat
|
self[name] = pat
|
||||||
return name, pat
|
return name, pat
|
||||||
|
|
@ -803,7 +803,7 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
|
||||||
Raises:
|
Raises:
|
||||||
`LibraryError` if a duplicate name is encountered even after applying `rename_theirs()`.
|
`LibraryError` if a duplicate name is encountered even after applying `rename_theirs()`.
|
||||||
"""
|
"""
|
||||||
from .pattern import map_targets
|
from .pattern import map_targets #noqa: PLC0415
|
||||||
duplicates = set(self.keys()) & set(other.keys())
|
duplicates = set(self.keys()) & set(other.keys())
|
||||||
|
|
||||||
if not duplicates:
|
if not duplicates:
|
||||||
|
|
@ -909,7 +909,7 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
|
||||||
# This currently simplifies globally (same shape in different patterns is
|
# This currently simplifies globally (same shape in different patterns is
|
||||||
# merged into the same ref target).
|
# merged into the same ref target).
|
||||||
|
|
||||||
from .pattern import Pattern
|
from .pattern import Pattern #noqa: PLC0415
|
||||||
|
|
||||||
if exclude_types is None:
|
if exclude_types is None:
|
||||||
exclude_types = ()
|
exclude_types = ()
|
||||||
|
|
@ -1002,7 +1002,7 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
|
||||||
Returns:
|
Returns:
|
||||||
self
|
self
|
||||||
"""
|
"""
|
||||||
from .pattern import Pattern
|
from .pattern import Pattern #noqa: PLC0415
|
||||||
|
|
||||||
if name_func is None:
|
if name_func is None:
|
||||||
def name_func(_pat: Pattern, _shape: Shape | Label) -> str:
|
def name_func(_pat: Pattern, _shape: Shape | Label) -> str:
|
||||||
|
|
@ -1205,7 +1205,7 @@ class Library(ILibrary):
|
||||||
Returns:
|
Returns:
|
||||||
The newly created `Library` and the newly created `Pattern`
|
The newly created `Library` and the newly created `Pattern`
|
||||||
"""
|
"""
|
||||||
from .pattern import Pattern
|
from .pattern import Pattern #noqa: PLC0415
|
||||||
tree = cls()
|
tree = cls()
|
||||||
pat = Pattern()
|
pat = Pattern()
|
||||||
tree[name] = pat
|
tree[name] = pat
|
||||||
|
|
|
||||||
|
|
@ -1066,8 +1066,8 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable):
|
||||||
"""
|
"""
|
||||||
# TODO: add text labels to visualize()
|
# TODO: add text labels to visualize()
|
||||||
try:
|
try:
|
||||||
from matplotlib import pyplot # type: ignore
|
from matplotlib import pyplot # type: ignore #noqa: PLC0415
|
||||||
import matplotlib.collections # type: ignore
|
import matplotlib.collections # type: ignore #noqa: PLC0415
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.exception('Pattern.visualize() depends on matplotlib!\n'
|
logger.exception('Pattern.visualize() depends on matplotlib!\n'
|
||||||
+ 'Make sure to install masque with the [visualize] option to pull in the needed dependencies.')
|
+ 'Make sure to install masque with the [visualize] option to pull in the needed dependencies.')
|
||||||
|
|
|
||||||
|
|
@ -480,5 +480,5 @@ class Polygon(Shape):
|
||||||
Returns:
|
Returns:
|
||||||
A list of resulting Polygons.
|
A list of resulting Polygons.
|
||||||
"""
|
"""
|
||||||
from ..utils.boolean import boolean
|
from ..utils.boolean import boolean #noqa: PLC0415
|
||||||
return boolean([self], other, operation=operation, scale=scale)
|
return boolean([self], other, operation=operation, scale=scale)
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ class Shape(FlippableImpl, PivotableImpl, RepeatableImpl, AnnotatableImpl,
|
||||||
Returns:
|
Returns:
|
||||||
List of `Polygon` objects with grid-aligned edges.
|
List of `Polygon` objects with grid-aligned edges.
|
||||||
"""
|
"""
|
||||||
from . import Polygon
|
from . import Polygon #noqa: PLC0415
|
||||||
|
|
||||||
gx = numpy.unique(grid_x)
|
gx = numpy.unique(grid_x)
|
||||||
gy = numpy.unique(grid_y)
|
gy = numpy.unique(grid_y)
|
||||||
|
|
@ -250,9 +250,9 @@ class Shape(FlippableImpl, PivotableImpl, RepeatableImpl, AnnotatableImpl,
|
||||||
Returns:
|
Returns:
|
||||||
List of `Polygon` objects with grid-aligned edges.
|
List of `Polygon` objects with grid-aligned edges.
|
||||||
"""
|
"""
|
||||||
from . import Polygon
|
from . import Polygon #noqa: PLC0415
|
||||||
import skimage.measure # type: ignore
|
import skimage.measure #noqa: PLC0415
|
||||||
import float_raster
|
import float_raster #noqa: PLC0415
|
||||||
|
|
||||||
grx = numpy.unique(grid_x)
|
grx = numpy.unique(grid_x)
|
||||||
gry = numpy.unique(grid_y)
|
gry = numpy.unique(grid_y)
|
||||||
|
|
|
||||||
|
|
@ -205,8 +205,8 @@ def get_char_as_polygons(
|
||||||
char: str,
|
char: str,
|
||||||
resolution: float = 48 * 64,
|
resolution: float = 48 * 64,
|
||||||
) -> tuple[list[NDArray[numpy.float64]], float]:
|
) -> tuple[list[NDArray[numpy.float64]], float]:
|
||||||
from freetype import Face # type: ignore
|
from freetype import Face # type: ignore #noqa: PLC0415
|
||||||
from matplotlib.path import Path # type: ignore
|
from matplotlib.path import Path # type: ignore #noqa: PLC0415
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Get a list of polygons representing a single character.
|
Get a list of polygons representing a single character.
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
# ruff: noqa: PLC0415
|
||||||
import pytest
|
import pytest
|
||||||
import numpy
|
import numpy
|
||||||
from numpy.testing import assert_allclose
|
from numpy.testing import assert_allclose
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from numpy import pi
|
||||||
|
|
||||||
from ..label import Label
|
from ..label import Label
|
||||||
from ..repetition import Grid
|
from ..repetition import Grid
|
||||||
|
from ..utils import annotations_eq
|
||||||
|
|
||||||
|
|
||||||
def test_label_init() -> None:
|
def test_label_init() -> None:
|
||||||
|
|
@ -39,9 +40,6 @@ def test_label_copy() -> None:
|
||||||
|
|
||||||
print(f"l1: string={l1.string}, offset={l1.offset}, repetition={l1.repetition}, annotations={l1.annotations}")
|
print(f"l1: string={l1.string}, offset={l1.offset}, repetition={l1.repetition}, annotations={l1.annotations}")
|
||||||
print(f"l2: string={l2.string}, offset={l2.offset}, repetition={l2.repetition}, annotations={l2.annotations}")
|
print(f"l2: string={l2.string}, offset={l2.offset}, repetition={l2.repetition}, annotations={l2.annotations}")
|
||||||
|
|
||||||
from ..utils import annotations_eq
|
|
||||||
|
|
||||||
print(f"annotations_eq: {annotations_eq(l1.annotations, l2.annotations)}")
|
print(f"annotations_eq: {annotations_eq(l1.annotations, l2.annotations)}")
|
||||||
|
|
||||||
assert l1 == l2
|
assert l1 == l2
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ class RepeatableImpl(Repeatable, Bounded, metaclass=ABCMeta):
|
||||||
|
|
||||||
@repetition.setter
|
@repetition.setter
|
||||||
def repetition(self, repetition: 'Repetition | None') -> None:
|
def repetition(self, repetition: 'Repetition | None') -> None:
|
||||||
from ..repetition import Repetition
|
from ..repetition import Repetition #noqa: PLC0415
|
||||||
if repetition is not None and not isinstance(repetition, Repetition):
|
if repetition is not None and not isinstance(repetition, Repetition):
|
||||||
raise MasqueError(f'{repetition} is not a valid Repetition object!')
|
raise MasqueError(f'{repetition} is not a valid Repetition object!')
|
||||||
self._repetition = repetition
|
self._repetition = repetition
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,10 @@ from numpy.typing import NDArray
|
||||||
from ..shapes.polygon import Polygon
|
from ..shapes.polygon import Polygon
|
||||||
from ..error import PatternError
|
from ..error import PatternError
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _bridge_holes(outer_path: NDArray[numpy.float64], holes: list[NDArray[numpy.float64]]) -> NDArray[numpy.float64]:
|
def _bridge_holes(outer_path: NDArray[numpy.float64], holes: list[NDArray[numpy.float64]]) -> NDArray[numpy.float64]:
|
||||||
"""
|
"""
|
||||||
Bridge multiple holes into an outer boundary using zero-width slits.
|
Bridge multiple holes into an outer boundary using zero-width slits.
|
||||||
|
|
@ -96,7 +98,7 @@ def boolean(
|
||||||
A list of result Polygons.
|
A list of result Polygons.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
import pyclipper
|
import pyclipper #noqa: PLC0415
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Boolean operations require 'pyclipper'. "
|
"Boolean operations require 'pyclipper'. "
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ def poly_contains_points(
|
||||||
max_bounds = numpy.max(vertices, axis=0)[None, :]
|
max_bounds = numpy.max(vertices, axis=0)[None, :]
|
||||||
|
|
||||||
trivially_outside = ((points < min_bounds).any(axis=1)
|
trivially_outside = ((points < min_bounds).any(axis=1)
|
||||||
| (points > max_bounds).any(axis=1)) # noqa: E128
|
| (points > max_bounds).any(axis=1))
|
||||||
|
|
||||||
nontrivial = ~trivially_outside
|
nontrivial = ~trivially_outside
|
||||||
if trivially_outside.all():
|
if trivially_outside.all():
|
||||||
|
|
@ -105,10 +105,10 @@ def poly_contains_points(
|
||||||
|
|
||||||
dv = numpy.roll(verts, -1, axis=0) - verts
|
dv = numpy.roll(verts, -1, axis=0) - verts
|
||||||
is_left = (dv[:, 0] * (ntpts[..., 1] - verts[:, 1]) # >0 if left of dv, <0 if right, 0 if on the line
|
is_left = (dv[:, 0] * (ntpts[..., 1] - verts[:, 1]) # >0 if left of dv, <0 if right, 0 if on the line
|
||||||
- dv[:, 1] * (ntpts[..., 0] - verts[:, 0])) # noqa: E128
|
- dv[:, 1] * (ntpts[..., 0] - verts[:, 0]))
|
||||||
|
|
||||||
winding_number = ((upward & (is_left > 0)).sum(axis=0)
|
winding_number = ((upward & (is_left > 0)).sum(axis=0)
|
||||||
- (downward & (is_left < 0)).sum(axis=0)) # noqa: E128
|
- (downward & (is_left < 0)).sum(axis=0))
|
||||||
|
|
||||||
nontrivial_inside = winding_number != 0 # filter nontrivial points based on winding number
|
nontrivial_inside = winding_number != 0 # filter nontrivial points based on winding number
|
||||||
if include_boundary:
|
if include_boundary:
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,8 @@ lint.ignore = [
|
||||||
"PLR09", # Too many xxx
|
"PLR09", # Too many xxx
|
||||||
"PLR2004", # magic number
|
"PLR2004", # magic number
|
||||||
"PLC0414", # import x as x
|
"PLC0414", # import x as x
|
||||||
|
# "PLC0415", # non-top-level import
|
||||||
|
"PLW1641", # missing __hash__ with total_ordering
|
||||||
"TRY003", # Long exception message
|
"TRY003", # Long exception message
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue