updateIndex method

  1. @override
void updateIndex(
  1. SpatialIndex<InteractiveOverlayImage> index,
  2. Op<InteractiveOverlayImage> op,
  3. InteractiveOverlayImage? getItem(
    1. Key
    )
)
override

Updates the spatial index based on the operation. getItem allows retrieving the current state of an item by key (useful for Move ops).

Implementation

@override
void updateIndex(
  SpatialIndex<InteractiveOverlayImage> index,
  Op<InteractiveOverlayImage> op,
  InteractiveOverlayImage? Function(Key) getItem,
) {
  switch (op) {
    case AddOverlayOp(:final overlay):
      index.add(overlay.key!, overlay, getBounds(overlay));
    case RemoveOverlayOp(:final key):
      index.remove(key);
    case UpdateOverlayOp(:final newOverlay):
      index.add(newOverlay.key!, newOverlay, getBounds(newOverlay));
    case MoveCornerOverlayOp(:final key):
      final item = getItem(key);
      if (item != null) index.add(key, item, getBounds(item));
  }
}