Various type-checking improvements
This commit is contained in:
parent
5a4be88672
commit
debb27cdc8
@ -661,7 +661,7 @@ def repetition_masq2fata(
|
|||||||
diffs = numpy.diff(rep.displacements, axis=0)
|
diffs = numpy.diff(rep.displacements, axis=0)
|
||||||
diff_ints = rint_cast(diffs)
|
diff_ints = rint_cast(diffs)
|
||||||
frep = fatamorgana.ArbitraryRepetition(diff_ints[:, 0], diff_ints[:, 1]) # type: ignore
|
frep = fatamorgana.ArbitraryRepetition(diff_ints[:, 0], diff_ints[:, 1]) # type: ignore
|
||||||
offset = rep.displacements[0, :]
|
offset = tuple(rep.displacements[0, :])
|
||||||
else:
|
else:
|
||||||
assert rep is None
|
assert rep is None
|
||||||
frep = None
|
frep = None
|
||||||
|
|||||||
@ -584,7 +584,7 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable):
|
|||||||
bounds = numpy.vstack((numpy.min(corners, axis=0),
|
bounds = numpy.vstack((numpy.min(corners, axis=0),
|
||||||
numpy.max(corners, axis=0))) * ref.scale + [ref.offset]
|
numpy.max(corners, axis=0))) * ref.scale + [ref.offset]
|
||||||
if ref.repetition is not None:
|
if ref.repetition is not None:
|
||||||
bounds += ref.repetition.get_bounds()
|
bounds += ref.repetition.get_bounds_nonempty()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Non-manhattan rotation, have to figure out bounds by rotating the pattern
|
# Non-manhattan rotation, have to figure out bounds by rotating the pattern
|
||||||
|
|||||||
@ -64,7 +64,7 @@ class Port(PositionableImpl, Rotatable, PivotableImpl, Copyable, Mirrorable):
|
|||||||
return self._rotation
|
return self._rotation
|
||||||
|
|
||||||
@rotation.setter
|
@rotation.setter
|
||||||
def rotation(self, val: float) -> None:
|
def rotation(self, val: float | None) -> None:
|
||||||
if val is None:
|
if val is None:
|
||||||
self._rotation = None
|
self._rotation = None
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import numpy
|
|||||||
from numpy import pi
|
from numpy import pi
|
||||||
from numpy.typing import NDArray, ArrayLike
|
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 .repetition import Repetition
|
||||||
from .traits import (
|
from .traits import (
|
||||||
PositionableImpl, RotatableImpl, ScalableImpl,
|
PositionableImpl, RotatableImpl, ScalableImpl,
|
||||||
@ -50,11 +50,11 @@ class Ref(
|
|||||||
|
|
||||||
# Mirrored property
|
# Mirrored property
|
||||||
@property
|
@property
|
||||||
def mirrored(self) -> bool: # mypy#3004, setter should be SupportsBool
|
def mirrored(self) -> bool:
|
||||||
return self._mirrored
|
return self._mirrored
|
||||||
|
|
||||||
@mirrored.setter
|
@mirrored.setter
|
||||||
def mirrored(self, val: bool) -> None:
|
def mirrored(self, val: SupportsBool) -> None:
|
||||||
self._mirrored = bool(val)
|
self._mirrored = bool(val)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|||||||
@ -327,7 +327,7 @@ class Arbitrary(Repetition):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def displacements(self) -> Any: # mypy#3004 NDArray[numpy.float64]:
|
def displacements(self) -> NDArray[numpy.float64]:
|
||||||
return self._displacements
|
return self._displacements
|
||||||
|
|
||||||
@displacements.setter
|
@displacements.setter
|
||||||
|
|||||||
@ -42,7 +42,7 @@ class Arc(Shape):
|
|||||||
|
|
||||||
# radius properties
|
# radius properties
|
||||||
@property
|
@property
|
||||||
def radii(self) -> Any: # mypy#3004 NDArray[numpy.float64]:
|
def radii(self) -> NDArray[numpy.float64]:
|
||||||
"""
|
"""
|
||||||
Return the radii `[rx, ry]`
|
Return the radii `[rx, ry]`
|
||||||
"""
|
"""
|
||||||
@ -79,7 +79,7 @@ class Arc(Shape):
|
|||||||
|
|
||||||
# arc start/stop angle properties
|
# arc start/stop angle properties
|
||||||
@property
|
@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]`.
|
Return the start and stop angles `[a_start, a_stop]`.
|
||||||
Angles are measured from x-axis after rotation
|
Angles are measured from x-axis after rotation
|
||||||
@ -412,15 +412,15 @@ class Arc(Shape):
|
|||||||
start_angle -= pi
|
start_angle -= pi
|
||||||
rotation += pi
|
rotation += pi
|
||||||
|
|
||||||
angles = (start_angle, start_angle + delta_angle)
|
norm_angles = (start_angle, start_angle + delta_angle)
|
||||||
rotation %= 2 * pi
|
rotation %= 2 * pi
|
||||||
width = self.width
|
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),
|
(self.offset, scale / norm_value, rotation, False),
|
||||||
lambda: Arc(
|
lambda: Arc(
|
||||||
radii=radii * norm_value,
|
radii=radii * norm_value,
|
||||||
angles=angles,
|
angles=norm_angles,
|
||||||
width=width * norm_value,
|
width=width * norm_value,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ class Ellipse(Shape):
|
|||||||
|
|
||||||
# radius properties
|
# radius properties
|
||||||
@property
|
@property
|
||||||
def radii(self) -> Any: # mypy#3004 NDArray[numpy.float64]:
|
def radii(self) -> NDArray[numpy.float64]:
|
||||||
"""
|
"""
|
||||||
Return the radii `[rx, ry]`
|
Return the radii `[rx, ry]`
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -87,7 +87,7 @@ class Path(Shape):
|
|||||||
|
|
||||||
# cap_extensions property
|
# cap_extensions property
|
||||||
@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
|
Path end-cap extension
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ class Path(Shape):
|
|||||||
|
|
||||||
# vertices property
|
# vertices property
|
||||||
@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], ...]`
|
Vertices of the path (Nx2 ndarray: `[[x0, y0], [x1, y1], ...]`
|
||||||
|
|
||||||
|
|||||||
@ -37,14 +37,14 @@ class PolyCollection(Shape):
|
|||||||
""" 1D NDArray specifying the starting offset for each polygon """
|
""" 1D NDArray specifying the starting offset for each polygon """
|
||||||
|
|
||||||
@property
|
@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`.
|
Vertices of the polygons, ((N+M+...) x 2). Use with `vertex_offsets`.
|
||||||
"""
|
"""
|
||||||
return self._vertex_lists
|
return self._vertex_lists
|
||||||
|
|
||||||
@property
|
@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
|
Starting offset (in `vertex_lists`) for each polygon
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -38,7 +38,7 @@ class Polygon(Shape):
|
|||||||
|
|
||||||
# vertices property
|
# vertices property
|
||||||
@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], ...]`)
|
Vertices of the polygon (Nx2 ndarray: `[[x0, y0], [x1, y1], ...]`)
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from . import Shape, Polygon, normalized_shape_tuple
|
|||||||
from ..error import PatternError
|
from ..error import PatternError
|
||||||
from ..repetition import Repetition
|
from ..repetition import Repetition
|
||||||
from ..traits import RotatableImpl
|
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:
|
# Loaded on use:
|
||||||
# from freetype import Face
|
# from freetype import Face
|
||||||
@ -55,11 +55,11 @@ class Text(RotatableImpl, Shape):
|
|||||||
self._height = val
|
self._height = val
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mirrored(self) -> bool: # mypy#3004, should be bool
|
def mirrored(self) -> bool:
|
||||||
return self._mirrored
|
return self._mirrored
|
||||||
|
|
||||||
@mirrored.setter
|
@mirrored.setter
|
||||||
def mirrored(self, val: bool) -> None:
|
def mirrored(self, val: SupportsBool) -> None:
|
||||||
self._mirrored = bool(val)
|
self._mirrored = bool(val)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -201,7 +201,7 @@ def get_char_as_polygons(
|
|||||||
font_path: str,
|
font_path: str,
|
||||||
char: str,
|
char: str,
|
||||||
resolution: float = 48 * 64,
|
resolution: float = 48 * 64,
|
||||||
) -> tuple[list[list[list[float]]], float]:
|
) -> tuple[list[NDArray[numpy.float64]], float]:
|
||||||
from freetype import Face # type: ignore
|
from freetype import Face # type: ignore
|
||||||
from matplotlib.path import Path # type: ignore
|
from matplotlib.path import Path # type: ignore
|
||||||
|
|
||||||
@ -276,11 +276,12 @@ def get_char_as_polygons(
|
|||||||
|
|
||||||
advance = slot.advance.x / resolution
|
advance = slot.advance.x / resolution
|
||||||
|
|
||||||
|
polygons: list[NDArray[numpy.float64]]
|
||||||
if len(all_verts) == 0:
|
if len(all_verts) == 0:
|
||||||
polygons = []
|
polygons = []
|
||||||
else:
|
else:
|
||||||
path = Path(all_verts, all_codes)
|
path = Path(all_verts, all_codes)
|
||||||
path.should_simplify = False
|
path.should_simplify = False
|
||||||
polygons = path.to_polygons()
|
polygons = [numpy.asarray(poly) for poly in path.to_polygons()]
|
||||||
|
|
||||||
return polygons, advance
|
return polygons, advance
|
||||||
|
|||||||
@ -73,7 +73,7 @@ class PositionableImpl(Positionable, metaclass=ABCMeta):
|
|||||||
#
|
#
|
||||||
# offset property
|
# offset property
|
||||||
@property
|
@property
|
||||||
def offset(self) -> Any: # mypy#3004 NDArray[numpy.float64]:
|
def offset(self) -> NDArray[numpy.float64]:
|
||||||
"""
|
"""
|
||||||
[x, y] offset
|
[x, y] offset
|
||||||
"""
|
"""
|
||||||
@ -95,7 +95,7 @@ class PositionableImpl(Positionable, metaclass=ABCMeta):
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
def translate(self, offset: ArrayLike) -> Self:
|
def translate(self, offset: ArrayLike) -> Self:
|
||||||
self._offset += offset # type: ignore # NDArray += ArrayLike should be fine??
|
self._offset += numpy.asarray(offset)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -116,7 +116,7 @@ class PivotableImpl(Pivotable, metaclass=ABCMeta):
|
|||||||
pivot = numpy.asarray(pivot, dtype=float)
|
pivot = numpy.asarray(pivot, dtype=float)
|
||||||
cast('Positionable', self).translate(-pivot)
|
cast('Positionable', self).translate(-pivot)
|
||||||
cast('Rotatable', self).rotate(rotation)
|
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)
|
cast('Positionable', self).translate(+pivot)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user