Refactor routing internals and archive retry benchmarks
This commit is contained in:
parent
a8720ac8c9
commit
ea5cfe7f31
1 changed files with 3481 additions and 2583 deletions
|
|
@ -23,6 +23,9 @@ if TYPE_CHECKING:
|
|||
from inire.geometry.primitives import Port
|
||||
|
||||
|
||||
_RAY_CAST_CACHE_LIMIT = 8192
|
||||
|
||||
|
||||
def _intersection_distance(origin: Port, geometry: BaseGeometry) -> float:
|
||||
if hasattr(geometry, "geoms"):
|
||||
return min(_intersection_distance(origin, sub_geometry) for sub_geometry in geometry.geoms)
|
||||
|
|
@ -103,6 +106,10 @@ class RoutingWorld:
|
|||
def get_static_version(self) -> int:
|
||||
return self._static_obstacles.version
|
||||
|
||||
def iter_static_geometries(self) -> Iterable[Polygon]:
|
||||
"""Iterate over the current raw obstacles in insertion order."""
|
||||
return self._static_obstacles.geometries.values()
|
||||
|
||||
def iter_static_dilated_geometries(self) -> Iterable[Polygon]:
|
||||
return self._static_obstacles.dilated.values()
|
||||
|
||||
|
|
@ -777,6 +784,31 @@ class RoutingWorld:
|
|||
self.metrics.total_ray_cast_calls_visibility_tangent += 1
|
||||
else:
|
||||
self.metrics.total_ray_cast_calls_other += 1
|
||||
|
||||
# Static obstacle changes clear these results along with the trees.
|
||||
cache = self._static_obstacles.ray_cast_cache
|
||||
# Equal NumPy and Python scalars can produce different ray geometry.
|
||||
key = (
|
||||
origin.x, origin.y, angle_deg, max_dist, net_width, self.clearance,
|
||||
type(angle_deg), type(max_dist), type(net_width), type(self.clearance),
|
||||
)
|
||||
reach = cache.get(key)
|
||||
if reach is not None:
|
||||
return reach
|
||||
|
||||
reach = self._cast_static_ray(origin, angle_deg, max_dist, net_width)
|
||||
if len(cache) >= _RAY_CAST_CACHE_LIMIT:
|
||||
cache.clear()
|
||||
cache[key] = reach
|
||||
return reach
|
||||
|
||||
def _cast_static_ray(
|
||||
self,
|
||||
origin: Port,
|
||||
angle_deg: float,
|
||||
max_dist: float,
|
||||
net_width: float | None,
|
||||
) -> float:
|
||||
static_obstacles = self._static_obstacles
|
||||
tree: STRtree | None
|
||||
is_rect_array: numpy.ndarray | None
|
||||
|
|
|
|||
Loading…
Reference in a new issue