diff --git a/masque/file/oasis.py b/masque/file/oasis.py index 642ad44..672af25 100644 --- a/masque/file/oasis.py +++ b/masque/file/oasis.py @@ -661,7 +661,7 @@ def repetition_masq2fata( diffs = numpy.diff(rep.displacements, axis=0) diff_ints = rint_cast(diffs) frep = fatamorgana.ArbitraryRepetition(diff_ints[:, 0], diff_ints[:, 1]) # type: ignore - offset = rep.displacements[0, :] + offset = tuple(rep.displacements[0, :]) else: assert rep is None frep = None diff --git a/masque/pattern.py b/masque/pattern.py index f77c64f..01ddf6a 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -584,7 +584,7 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable): bounds = numpy.vstack((numpy.min(corners, axis=0), numpy.max(corners, axis=0))) * ref.scale + [ref.offset] if ref.repetition is not None: - bounds += ref.repetition.get_bounds() + bounds += ref.repetition.get_bounds_nonempty() else: # Non-manhattan rotation, have to figure out bounds by rotating the pattern diff --git a/masque/ports.py b/masque/ports.py index 1cc711a..8060616 100644 --- a/masque/ports.py +++ b/masque/ports.py @@ -64,7 +64,7 @@ class Port(PositionableImpl, Rotatable, PivotableImpl, Copyable, Mirrorable): return self._rotation @rotation.setter - def rotation(self, val: float) -> None: + def rotation(self, val: float | None) -> None: if val is None: self._rotation = None else: diff --git a/masque/ref.py b/masque/ref.py index 09e00b1..b3a684c 100644 --- a/masque/ref.py +++ b/masque/ref.py @@ -11,7 +11,7 @@ import numpy from numpy import pi from numpy.typing import NDArray, ArrayLike -from .utils import annotations_t, rotation_matrix_2d, annotations_eq, annotations_lt, rep2key +from .utils import annotations_t, rotation_matrix_2d, annotations_eq, annotations_lt, rep2key, SupportsBool from .repetition import Repetition from .traits import ( PositionableImpl, RotatableImpl, ScalableImpl, @@ -50,11 +50,11 @@ class Ref( # Mirrored property @property - def mirrored(self) -> bool: # mypy#3004, setter should be SupportsBool + def mirrored(self) -> bool: return self._mirrored @mirrored.setter - def mirrored(self, val: bool) -> None: + def mirrored(self, val: SupportsBool) -> None: self._mirrored = bool(val) def __init__( diff --git a/masque/repetition.py b/masque/repetition.py index e6d00fc..5e7a7f0 100644 --- a/masque/repetition.py +++ b/masque/repetition.py @@ -327,7 +327,7 @@ class Arbitrary(Repetition): """ @property - def displacements(self) -> Any: # mypy#3004 NDArray[numpy.float64]: + def displacements(self) -> NDArray[numpy.float64]: return self._displacements @displacements.setter diff --git a/masque/shapes/arc.py b/masque/shapes/arc.py index 9fe8b31..7eb310a 100644 --- a/masque/shapes/arc.py +++ b/masque/shapes/arc.py @@ -42,7 +42,7 @@ class Arc(Shape): # radius properties @property - def radii(self) -> Any: # mypy#3004 NDArray[numpy.float64]: + def radii(self) -> NDArray[numpy.float64]: """ Return the radii `[rx, ry]` """ @@ -79,7 +79,7 @@ class Arc(Shape): # arc start/stop angle properties @property - def angles(self) -> Any: # mypy#3004 NDArray[numpy.float64]: + def angles(self) -> NDArray[numpy.float64]: """ Return the start and stop angles `[a_start, a_stop]`. Angles are measured from x-axis after rotation @@ -412,15 +412,15 @@ class Arc(Shape): start_angle -= pi rotation += pi - angles = (start_angle, start_angle + delta_angle) + norm_angles = (start_angle, start_angle + delta_angle) rotation %= 2 * pi width = self.width - return ((type(self), radii, angles, width / norm_value), + return ((type(self), radii, norm_angles, width / norm_value), (self.offset, scale / norm_value, rotation, False), lambda: Arc( radii=radii * norm_value, - angles=angles, + angles=norm_angles, width=width * norm_value, )) diff --git a/masque/shapes/ellipse.py b/masque/shapes/ellipse.py index 56ee73f..40d67d7 100644 --- a/masque/shapes/ellipse.py +++ b/masque/shapes/ellipse.py @@ -33,7 +33,7 @@ class Ellipse(Shape): # radius properties @property - def radii(self) -> Any: # mypy#3004 NDArray[numpy.float64]: + def radii(self) -> NDArray[numpy.float64]: """ Return the radii `[rx, ry]` """ diff --git a/masque/shapes/path.py b/masque/shapes/path.py index 700f02f..48f3776 100644 --- a/masque/shapes/path.py +++ b/masque/shapes/path.py @@ -87,7 +87,7 @@ class Path(Shape): # cap_extensions property @property - def cap_extensions(self) -> Any | None: # mypy#3004 NDArray[numpy.float64]]: + def cap_extensions(self) -> NDArray[numpy.float64] | None: """ Path end-cap extension @@ -113,7 +113,7 @@ class Path(Shape): # vertices property @property - def vertices(self) -> Any: # mypy#3004 NDArray[numpy.float64]]: + def vertices(self) -> NDArray[numpy.float64]: """ Vertices of the path (Nx2 ndarray: `[[x0, y0], [x1, y1], ...]` diff --git a/masque/shapes/poly_collection.py b/masque/shapes/poly_collection.py index bd2c23c..0369fd4 100644 --- a/masque/shapes/poly_collection.py +++ b/masque/shapes/poly_collection.py @@ -37,14 +37,14 @@ class PolyCollection(Shape): """ 1D NDArray specifying the starting offset for each polygon """ @property - def vertex_lists(self) -> Any: # mypy#3004 NDArray[numpy.float64]: + def vertex_lists(self) -> NDArray[numpy.float64]: """ Vertices of the polygons, ((N+M+...) x 2). Use with `vertex_offsets`. """ return self._vertex_lists @property - def vertex_offsets(self) -> Any: # mypy#3004 NDArray[numpy.intp]: + def vertex_offsets(self) -> NDArray[numpy.intp]: """ Starting offset (in `vertex_lists`) for each polygon """ diff --git a/masque/shapes/polygon.py b/masque/shapes/polygon.py index 9c228d4..16e8729 100644 --- a/masque/shapes/polygon.py +++ b/masque/shapes/polygon.py @@ -38,7 +38,7 @@ class Polygon(Shape): # vertices property @property - def vertices(self) -> Any: # mypy#3004 NDArray[numpy.float64]: + def vertices(self) -> NDArray[numpy.float64]: """ Vertices of the polygon (Nx2 ndarray: `[[x0, y0], [x1, y1], ...]`) diff --git a/masque/shapes/text.py b/masque/shapes/text.py index e8b97ed..e30fe1c 100644 --- a/masque/shapes/text.py +++ b/masque/shapes/text.py @@ -10,7 +10,7 @@ from . import Shape, Polygon, normalized_shape_tuple from ..error import PatternError from ..repetition import Repetition from ..traits import RotatableImpl -from ..utils import is_scalar, get_bit, annotations_t, annotations_lt, annotations_eq, rep2key +from ..utils import is_scalar, get_bit, annotations_t, annotations_lt, annotations_eq, rep2key, SupportsBool # Loaded on use: # from freetype import Face @@ -55,11 +55,11 @@ class Text(RotatableImpl, Shape): self._height = val @property - def mirrored(self) -> bool: # mypy#3004, should be bool + def mirrored(self) -> bool: return self._mirrored @mirrored.setter - def mirrored(self, val: bool) -> None: + def mirrored(self, val: SupportsBool) -> None: self._mirrored = bool(val) def __init__( @@ -201,7 +201,7 @@ def get_char_as_polygons( font_path: str, char: str, resolution: float = 48 * 64, - ) -> tuple[list[list[list[float]]], float]: + ) -> tuple[list[NDArray[numpy.float64]], float]: from freetype import Face # type: ignore from matplotlib.path import Path # type: ignore @@ -276,11 +276,12 @@ def get_char_as_polygons( advance = slot.advance.x / resolution + polygons: list[NDArray[numpy.float64]] if len(all_verts) == 0: polygons = [] else: path = Path(all_verts, all_codes) path.should_simplify = False - polygons = path.to_polygons() + polygons = [numpy.asarray(poly) for poly in path.to_polygons()] return polygons, advance diff --git a/masque/traits/positionable.py b/masque/traits/positionable.py index 66e6e7d..fd8551b 100644 --- a/masque/traits/positionable.py +++ b/masque/traits/positionable.py @@ -73,7 +73,7 @@ class PositionableImpl(Positionable, metaclass=ABCMeta): # # offset property @property - def offset(self) -> Any: # mypy#3004 NDArray[numpy.float64]: + def offset(self) -> NDArray[numpy.float64]: """ [x, y] offset """ @@ -95,7 +95,7 @@ class PositionableImpl(Positionable, metaclass=ABCMeta): return self def translate(self, offset: ArrayLike) -> Self: - self._offset += offset # type: ignore # NDArray += ArrayLike should be fine?? + self._offset += numpy.asarray(offset) return self diff --git a/masque/traits/rotatable.py b/masque/traits/rotatable.py index 04816f1..2fa86c1 100644 --- a/masque/traits/rotatable.py +++ b/masque/traits/rotatable.py @@ -116,7 +116,7 @@ class PivotableImpl(Pivotable, metaclass=ABCMeta): pivot = numpy.asarray(pivot, dtype=float) cast('Positionable', self).translate(-pivot) cast('Rotatable', self).rotate(rotation) - self.offset = numpy.dot(rotation_matrix_2d(rotation), self.offset) # type: ignore # mypy#3004 + self.offset = numpy.dot(rotation_matrix_2d(rotation), self.offset) cast('Positionable', self).translate(+pivot) return self