diagramContainingOwner function

ResolvedShape? diagramContainingOwner(
  1. ResolvedScene scene,
  2. DiagramPoint world, {
  3. Set<String> excluding = const {},
})

Topmost child-owning clipped shape containing the point, using scene order.

Implementation

ResolvedShape? diagramContainingOwner(
  ResolvedScene scene,
  DiagramPoint world, {
  Set<String> excluding = const {},
}) {
  final candidates = scene.spatialIndex
      .query(
        DiagramRect.fromCenter(
          center: world,
          size: const DiagramSize(0.001, 0.001),
        ),
      )
      .toList(growable: false);
  for (final element in candidates.reversed) {
    if (element is ResolvedShape &&
        !excluding.contains(element.id) &&
        (element.definition.container?.clips ?? false) &&
        element.hitTest(world)) {
      return element;
    }
  }
  return null;
}