linter fixes

This commit is contained in:
Jan Petykiewicz 2026-03-30 23:54:30 -07:00
commit 1849075b11
6 changed files with 152 additions and 104 deletions

View file

@ -105,9 +105,16 @@ class RoutingWorld:
return reach < length - 0.001
def _is_in_safety_zone_fast(self, idx: int, start_port: Port | None, end_port: Port | None) -> bool:
bounds = self._static_obstacles.bounds_array[idx]
bounds_array = self._static_obstacles.bounds_array
if bounds_array is None:
return False
bounds = bounds_array[idx]
safety_zone = self.safety_zone_radius
if start_port and bounds[0] - safety_zone <= start_port.x <= bounds[2] + safety_zone and bounds[1] - safety_zone <= start_port.y <= bounds[3] + safety_zone:
if (
start_port
and bounds[0] - safety_zone <= start_port.x <= bounds[2] + safety_zone
and bounds[1] - safety_zone <= start_port.y <= bounds[3] + safety_zone
):
return True
return bool(
end_port
@ -176,15 +183,18 @@ class RoutingWorld:
return False
self._ensure_static_tree()
tree = static_obstacles.tree
bounds_array = static_obstacles.bounds_array
if tree is None or bounds_array is None:
return False
hits = static_obstacles.tree.query(box(*result.total_dilated_bounds))
hits = tree.query(box(*result.total_dilated_bounds))
if hits.size == 0:
return False
static_bounds = static_obstacles.bounds_array
move_poly_bounds = result.dilated_bounds
for hit_idx in hits:
obstacle_bounds = static_bounds[hit_idx]
obstacle_bounds = bounds_array[hit_idx]
poly_hits_obstacle_aabb = False
for poly_bounds in move_poly_bounds:
if (
@ -319,7 +329,7 @@ class RoutingWorld:
raw_geometries = static_obstacles.raw_tree.geometries
for component in components:
for polygon in component.physical_geometry:
buffered = polygon.buffer(self.clearance, join_style=2)
buffered = polygon.buffer(self.clearance, join_style="mitre")
hits = static_obstacles.raw_tree.query(buffered, predicate="intersects")
for hit_idx in hits:
obstacle = raw_geometries[hit_idx]
@ -373,6 +383,9 @@ class RoutingWorld:
net_width: float | None = None,
) -> float:
static_obstacles = self._static_obstacles
tree: STRtree | None
is_rect_array: numpy.ndarray | None
bounds_array: numpy.ndarray | None
radians = numpy.radians(angle_deg)
cos_v, sin_v = numpy.cos(radians), numpy.sin(radians)
@ -391,7 +404,7 @@ class RoutingWorld:
is_rect_array = static_obstacles.is_rect_array
bounds_array = static_obstacles.bounds_array
if tree is None:
if tree is None or is_rect_array is None or bounds_array is None:
return max_dist
candidates = tree.query(box(min_x, min_y, max_x, max_y))

View file

@ -3,6 +3,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Sequence
from shapely.geometry import Polygon
from inire.geometry.components import ComponentResult
@ -13,8 +14,8 @@ def components_overlap(
component_b: ComponentResult,
prefer_actual: bool = False,
) -> bool:
polygons_a: tuple[Polygon, ...]
polygons_b: tuple[Polygon, ...]
polygons_a: Sequence[Polygon]
polygons_b: Sequence[Polygon]
if prefer_actual:
polygons_a = component_a.physical_geometry
polygons_b = component_b.physical_geometry

View file

@ -1,7 +1,7 @@
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Literal
from typing import TYPE_CHECKING, Literal
import numpy
from shapely.affinity import rotate as shapely_rotate
@ -13,6 +13,9 @@ from inire.constants import TOLERANCE_ANGULAR
from inire.seeds import Bend90Seed, PathSegmentSeed, SBendSeed, StraightSeed
from .primitives import Port, rotation_matrix2
if TYPE_CHECKING:
from collections.abc import Sequence
MoveKind = Literal["straight", "bend90", "sbend"]
BendCollisionModelName = Literal["arc", "bbox", "clipped_bbox"]
@ -27,14 +30,14 @@ def _normalize_length(value: float) -> float:
@dataclass(frozen=True, slots=True)
class ComponentResult:
start_port: Port
collision_geometry: tuple[Polygon, ...]
collision_geometry: Sequence[Polygon]
end_port: Port
length: float
move_type: MoveKind
move_spec: PathSegmentSeed
physical_geometry: tuple[Polygon, ...]
dilated_collision_geometry: tuple[Polygon, ...]
dilated_physical_geometry: tuple[Polygon, ...]
physical_geometry: Sequence[Polygon]
dilated_collision_geometry: Sequence[Polygon]
dilated_physical_geometry: Sequence[Polygon]
_bounds: tuple[tuple[float, float, float, float], ...] = field(init=False, repr=False)
_total_bounds: tuple[float, float, float, float] = field(init=False, repr=False)
_dilated_bounds: tuple[tuple[float, float, float, float], ...] = field(init=False, repr=False)
@ -146,7 +149,7 @@ def _clip_bbox_legacy(
minx, miny, maxx, maxy = arc_poly.bounds
bbox_poly = box(minx, miny, maxx, maxy)
shrink = min(clip_margin, max(radius, width))
return bbox_poly.buffer(-shrink, join_style=2) if shrink > 0 else bbox_poly
return bbox_poly.buffer(-shrink, join_style="mitre") if shrink > 0 else bbox_poly
def _clip_bbox_polygonal(cxy: tuple[float, float], radius: float, width: float, ts: tuple[float, float]) -> Polygon:

View file

@ -1,17 +1,18 @@
from __future__ import annotations
import math
from collections.abc import Iterator, Mapping
from typing import TypeVar
from typing import TYPE_CHECKING
import numpy
GeometryT = TypeVar("GeometryT")
if TYPE_CHECKING:
from collections.abc import Iterator, Mapping
from shapely.geometry.base import BaseGeometry
def build_index_payload(
geometries: Mapping[int, GeometryT],
) -> tuple[list[int], list[GeometryT], numpy.ndarray]:
geometries: Mapping[int, BaseGeometry],
) -> tuple[list[int], list[BaseGeometry], numpy.ndarray]:
obj_ids = sorted(geometries)
ordered_geometries = [geometries[obj_id] for obj_id in obj_ids]
bounds_array = numpy.array([geometry.bounds for geometry in ordered_geometries], dtype=numpy.float64)
@ -42,7 +43,7 @@ def iter_grid_cells(
yield (gx, gy)
def is_axis_aligned_rect(geometry, *, tolerance: float = 1e-4) -> bool:
def is_axis_aligned_rect(geometry: BaseGeometry, *, tolerance: float = 1e-4) -> bool:
bounds = geometry.bounds
area = (bounds[2] - bounds[0]) * (bounds[3] - bounds[1])
return abs(geometry.area - area) < tolerance

View file

@ -1,10 +1,12 @@
from __future__ import annotations
from dataclasses import dataclass
from typing import Self
from typing import TYPE_CHECKING, Self
import numpy
from numpy.typing import NDArray
if TYPE_CHECKING:
from numpy.typing import NDArray
def _normalize_angle(angle_deg: int | float) -> int:
@ -58,6 +60,6 @@ ROT2_180 = numpy.array(((-1, 0), (0, -1)), dtype=numpy.int32)
ROT2_270 = numpy.array(((0, 1), (-1, 0)), dtype=numpy.int32)
def rotation_matrix2(rotation_deg: int) -> NDArray[numpy.int32]:
def rotation_matrix2(rotation_deg: int | float) -> NDArray[numpy.int32]:
quadrant = (_normalize_angle(rotation_deg) // 90) % 4
return (ROT2_0, ROT2_90, ROT2_180, ROT2_270)[quadrant]

View file

@ -59,7 +59,7 @@ class StaticObstacleIndex:
if dilated_geometry is not None:
dilated = dilated_geometry
else:
dilated = polygon.buffer(self.engine.clearance / 2.0, join_style=2)
dilated = polygon.buffer(self.engine.clearance / 2.0, join_style="mitre")
self.geometries[obj_id] = polygon
self.dilated[obj_id] = dilated
@ -109,7 +109,7 @@ class StaticObstacleIndex:
for obj_id in sorted(self.geometries.keys()):
polygon = self.geometries[obj_id]
dilated = polygon.buffer(total_dilation, join_style=2)
dilated = polygon.buffer(total_dilation, join_style="mitre")
geometries.append(dilated)
bounds_list.append(dilated.bounds)
is_rect_list.append(is_axis_aligned_rect(dilated))