selectionUnionBounds function
Axis-aligned union of the provided ids' bounds.
getBounds should return world-space AABBs for individual elements.
In runtime/editor, getBounds is typically backed by
ComputedScene.visualBoundsWorldById (computed once in the compute stage).
Returns null when there are no ids or no available bounds.
Implementation
Rect2D? selectionUnionBounds(
Iterable<ElementId> ids, {
required Rect2D? Function(ElementId id) getBounds,
}) {
Rect2D? acc;
for (final id in ids) {
final b = getBounds(id);
if (b == null) continue;
acc = (acc == null) ? b : Rect2DX.union(acc, b);
}
return acc;
}