GraphSpatialIndex<T> class
Simplified, type-safe spatial index for graph elements.
This is the primary API for spatial operations in the node flow system. It provides:
- Type-safe operations (accepts domain objects directly)
- Automatic batching (no manual flush needed)
- Simple core operations: add, update, remove, query
Core Operations
// Adding/updating elements
index.update(node);
index.updateAnnotation(annotation);
index.updateConnection(connection, segmentBounds);
// Removing elements
index.remove(node);
index.removeAnnotation(annotationId);
index.removeConnection(connectionId);
// Querying
final result = index.hitTest(point);
final nodes = index.nodesAt(point);
final nodes = index.nodesIn(bounds);
Batch Operations
For multiple operations, use batch to defer index updates:
index.batch(() {
for (final node in nodes) {
index.update(node);
}
});
Constructors
- GraphSpatialIndex({double gridSize = 500.0, double portSnapDistance = 15.0})
Properties
- annotationCount → int
-
no setter
- connectionCount → int
-
no setter
- connectionHitTester ↔ bool Function(Connection connection, Offset point)?
-
getter/setter pair
-
connectionSegmentItems
→ Iterable<
ConnectionSegmentItem> -
Gets all connection segment items for debug visualization.
no setter
- gridSize → double
-
The grid size used for spatial hashing (default: 500.0 pixels).
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- nodeCount → int
-
no setter
-
nodeItems
→ Iterable<
NodeSpatialItem> -
Gets all node spatial items for debug visualization.
no setter
-
nodeShapeBuilder
↔ NodeShape? Function(Node<
T> node)? -
getter/setter pair
- portCount → int
-
no setter
-
portItems
→ Iterable<
PortSpatialItem> -
Gets all port spatial items for debug visualization.
no setter
- portSizeResolver ↔ Size Function(Port port)?
-
getter/setter pair
- portSnapDistance → double
-
Distance within which a port is considered "hit"
final
-
renderOrderProvider
← List<
Node< Function()?T> > -
Sets the render order provider for accurate hit testing.
no getter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stats → SpatialIndexStats
-
no setter
-
version
→ Observable<
int> -
Observable version counter that increments on every spatial index change.
final
Methods
-
annotationsAt(
Offset point, {double radius = 0}) → List< Annotation> - Gets all annotations at a point.
-
batch(
void operations()) → void - Executes multiple operations in a batch.
-
cellBounds(
int cellX, int cellY) → Rect - Converts grid cell coordinates to world bounds.
-
clear(
) → void - Clears all items from the spatial index.
-
connectionsAt(
Offset point, {double radius = 0}) → List< Connection> - Gets all connections at a point.
-
getActiveCellsInfo(
) → List< CellDebugInfo> - Gets information about all active spatial grid cells for debug visualization.
-
getAnnotation(
String id) → Annotation? - Gets an annotation by ID.
-
getConnection(
String id) → Connection? - Gets a connection by ID.
-
getNode(
String id) → Node< T> ? - Gets a node by ID.
-
hitTest(
Offset point) → HitTestResult - Performs hit testing at a point.
-
nodesAt(
Offset point, {double radius = 0}) → List< Node< T> > - Gets all nodes at a point.
-
nodesIn(
Rect bounds) → List< Node< T> > - Gets all nodes within bounds.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyChanged(
) → void - Forces a notification to observers that the spatial index has changed.
-
rebuild(
{required Iterable< Node< nodes, required Iterable<T> >Connection> connections, required Iterable<Annotation> annotations, required List<Rect> connectionSegmentCalculator(Connection)}) → void - Rebuilds the entire index from the given elements.
-
rebuildConnections(
Iterable< Connection> connections, Rect boundsCalculator(Connection)) → void - Rebuilds connections using single bounds calculator. Convenience wrapper that converts single-bound results to segment lists.
-
rebuildConnectionsWithSegments(
Iterable< Connection> connections, List<Rect> segmentBoundsCalculator(Connection)) → void - Rebuilds connections using segment bounds calculator.
-
rebuildFromAnnotations(
Iterable< Annotation> annotations) → void - Rebuilds only annotations from the given iterable.
-
rebuildFromNodes(
Iterable< Node< nodes) → voidT> > - Rebuilds only nodes from the given iterable. Also rebuilds all port spatial items.
-
remove(
Node< T> node) → void - Removes a node from the spatial index.
-
removeAnnotation(
String annotationId) → void - Removes an annotation from the spatial index.
-
removeConnection(
String connectionId) → void - Removes a connection from the spatial index.
-
removeNode(
String nodeId) → void - Removes a node by ID. Also removes all port spatial items for this node.
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
Node< T> node) → void - Updates a node in the spatial index.
-
updateAnnotation(
Annotation annotation) → void - Updates an annotation in the spatial index.
-
updateConnection(
Connection connection, List< Rect> segmentBounds) → void - Updates a connection in the spatial index with segment bounds.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited