routing.core.world#

Custom world class for routing.

class routing.core.world.SmartWorld(grids: dict[int, SmartGrid], world_matrix_shape: tuple[int, int, int], world_origin: tuple[float, float, float], voxel_size: float)[source]#

Bases: SmartGridInterface

A class representing a world that connects multiple SmartGrids, allowing for pathfinding across them.

This class inherits from World and SmartGridInterface, and enables multi-grid and multi-scale pathfinding by connecting multiple SmartGrid objects with potentially different voxel sizes and origins. It provides a unified interface for pathfinding across grid boundaries.

Parameters:
  • grids – The dictionary mapping grid IDs to SmartGrid instances. Each grid can have different voxel sizes and origins.

  • world_matrix_shape – The overall world dimensions as (width, height, depth) in voxels at the coarsest scale.

  • world_origin – The origin point of the world in global coordinates as (x, y, z) tuple.

  • voxel_size – The coarsest voxel size (used for world-scale coordinates). Should match max_voxel_size of all grids.

block_port_tail(grid_port: GridPort, radius: float) → None[source]#

Block the tail of grid_port on the grid its node stands on.

block_ports_tail(start: GridPort, end: GridPort, radius: float) → None[source]#

Block voxels between port and extension for avoiding self interference in generation.

cleanup() → None[source]#

Reset the nodes the world itself wrote (port extension, k-shortest edits) and clean every grid.

property decomposition: list[dict[str, tuple[int, int]]]#

Compute the index bounds each grid spans in the world frame.

property design_rules: list[DesignRule]#

Design rules of the world, read back from a sub-grid.

The sub-CadMaps all carry the same rules, so any grid names the same set; each SmartGrid.update() rebuilds its own voxelized copies, so this view never goes stale. A move is priced with the copies of the grid hosting it (grid_hosting()): the voxelized values differ between scales.

extend_port(port: Port, port_length: float) → SmartGridNode[source]#

Extend port over port_length: across the scales when the world has several, else as one grid.

extend_port_multi_scale(port: Port, port_length: float) → SmartGridNode[source]#

Extend port in its orientation direction by given length (multi-scale aware).

finest_node_at(coords: tuple[float, float, float] | ndarray) → SmartGridNode | None[source]#

Get the node hosting a global coordinate on the finest grid that holds it; None outside every grid.

property finest_voxel_size: float#

The finest step among the grids.

grid_hosting(node: SmartGridNode) → SmartGrid[source]#

Give the grid whose cells node belongs to: each scale voxelizes the rules’ lengths at its own step.

property is_multi_scale: bool#

Check if the world contains multiple scales.

property nbytes: int#

Calculate the total memory usage in bytes of all grids in SmartWorld.

node(x: int, y: int, z: int, grid_id: int | None = None, return_all: bool = False) → SmartGridNode | list[SmartGridNode] | None[source]#

Get node(s) at the specified coordinates.

Parameters:
  • x – X coordinate (in world scale if no grid_id, local scale otherwise)

  • y – Y coordinate

  • z – Z coordinate

  • grid_id – If specified, look in this specific grid with local coordinates

  • return_all – If True and is_multi_scale, return all nodes at this position

Returns:

Single node, list of nodes (if return_all), or None

search_states() → dict[int, GridSearchState][source]#

Open the search states of every grid of the world, by grid id: a search walks them all.

set_source_and_target(source: SmartGridNode, target: SmartGridNode) → None[source]#

Set the ports’ nodes on the world and on every grid: a grid serving the target cell must know it.

property turn_penalty: float#

The turn penalty of the world, read back from a sub-grid: every grid carries the same rules.