This commit is contained in:
jan 2026-02-16 20:48:15 -08:00
commit ff8ca92963
13 changed files with 29 additions and 24 deletions

View file

@ -400,11 +400,12 @@ class Pather(Builder, PatherMixin):
kwargs_plug = kwargs | {'plug_into': plug_into}
self.path(portspec, ccw0, length - abs(jog1), **kwargs_no_out)
self.path(portspec, not ccw0, abs(jog - jog0), **kwargs_plug)
return self
except (BuildError, NotImplementedError):
if not self._dead:
raise
# Fall through to dummy extension below
else:
return self
except BuildError:
if not self._dead:
raise

View file

@ -528,11 +528,12 @@ class RenderPather(PatherMixin):
kwargs_plug = kwargs | {'plug_into': plug_into}
self.path(portspec, ccw0, length - abs(jog1), **kwargs_no_out)
self.path(portspec, not ccw0, abs(jog - jog0), **kwargs_plug)
return self
except (BuildError, NotImplementedError):
if not self._dead:
raise
# Fall through to dummy extension below
else:
return self
except BuildError:
if not self._dead:
raise

View file

@ -763,7 +763,7 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
Returns:
(name, pattern) tuple
"""
from .pattern import Pattern
from .pattern import Pattern #noqa: PLC0415
pat = Pattern()
self[name] = pat
return name, pat
@ -803,7 +803,7 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
Raises:
`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())
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
# merged into the same ref target).
from .pattern import Pattern
from .pattern import Pattern #noqa: PLC0415
if exclude_types is None:
exclude_types = ()
@ -1002,7 +1002,7 @@ class ILibrary(ILibraryView, MutableMapping[str, 'Pattern'], metaclass=ABCMeta):
Returns:
self
"""
from .pattern import Pattern
from .pattern import Pattern #noqa: PLC0415
if name_func is None:
def name_func(_pat: Pattern, _shape: Shape | Label) -> str:
@ -1205,7 +1205,7 @@ class Library(ILibrary):
Returns:
The newly created `Library` and the newly created `Pattern`
"""
from .pattern import Pattern
from .pattern import Pattern #noqa: PLC0415
tree = cls()
pat = Pattern()
tree[name] = pat

View file

@ -1066,8 +1066,8 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable):
"""
# TODO: add text labels to visualize()
try:
from matplotlib import pyplot # type: ignore
import matplotlib.collections # type: ignore
from matplotlib import pyplot # type: ignore #noqa: PLC0415
import matplotlib.collections # type: ignore #noqa: PLC0415
except ImportError:
logger.exception('Pattern.visualize() depends on matplotlib!\n'
+ 'Make sure to install masque with the [visualize] option to pull in the needed dependencies.')

View file

@ -480,5 +480,5 @@ class Polygon(Shape):
Returns:
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)

View file

@ -121,7 +121,7 @@ class Shape(FlippableImpl, PivotableImpl, RepeatableImpl, AnnotatableImpl,
Returns:
List of `Polygon` objects with grid-aligned edges.
"""
from . import Polygon
from . import Polygon #noqa: PLC0415
gx = numpy.unique(grid_x)
gy = numpy.unique(grid_y)
@ -250,9 +250,9 @@ class Shape(FlippableImpl, PivotableImpl, RepeatableImpl, AnnotatableImpl,
Returns:
List of `Polygon` objects with grid-aligned edges.
"""
from . import Polygon
import skimage.measure # type: ignore
import float_raster
from . import Polygon #noqa: PLC0415
import skimage.measure #noqa: PLC0415
import float_raster #noqa: PLC0415
grx = numpy.unique(grid_x)
gry = numpy.unique(grid_y)

View file

@ -205,8 +205,8 @@ def get_char_as_polygons(
char: str,
resolution: float = 48 * 64,
) -> tuple[list[NDArray[numpy.float64]], float]:
from freetype import Face # type: ignore
from matplotlib.path import Path # type: ignore
from freetype import Face # type: ignore #noqa: PLC0415
from matplotlib.path import Path # type: ignore #noqa: PLC0415
"""
Get a list of polygons representing a single character.

View file

@ -1,3 +1,4 @@
# ruff: noqa: PLC0415
import pytest
import numpy
from numpy.testing import assert_allclose

View file

@ -4,6 +4,7 @@ from numpy import pi
from ..label import Label
from ..repetition import Grid
from ..utils import annotations_eq
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"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)}")
assert l1 == l2

View file

@ -76,7 +76,7 @@ class RepeatableImpl(Repeatable, Bounded, metaclass=ABCMeta):
@repetition.setter
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):
raise MasqueError(f'{repetition} is not a valid Repetition object!')
self._repetition = repetition

View file

@ -8,8 +8,10 @@ from numpy.typing import NDArray
from ..shapes.polygon import Polygon
from ..error import PatternError
logger = logging.getLogger(__name__)
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.
@ -96,7 +98,7 @@ def boolean(
A list of result Polygons.
"""
try:
import pyclipper
import pyclipper #noqa: PLC0415
except ImportError:
raise ImportError(
"Boolean operations require 'pyclipper'. "

View file

@ -87,7 +87,7 @@ def poly_contains_points(
max_bounds = numpy.max(vertices, axis=0)[None, :]
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
if trivially_outside.all():
@ -105,10 +105,10 @@ def poly_contains_points(
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
- dv[:, 1] * (ntpts[..., 0] - verts[:, 0])) # noqa: E128
- dv[:, 1] * (ntpts[..., 0] - verts[:, 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
if include_boundary: