selectionGeometry function

MultiSelectGeometry? selectionGeometry(
  1. Iterable<ElementId> ids, {
  2. required Rect2D? getBounds(
    1. ElementId id
    ),
})

Convenience wrapper that builds MultiSelectGeometry from element bounds.

Implementation

MultiSelectGeometry? selectionGeometry(
  Iterable<ElementId> ids, {
  required Rect2D? Function(ElementId id) getBounds,
}) {
  final bounds = selectionUnionBounds(ids, getBounds: getBounds);
  if (bounds == null) return null;

  final corners = <Vec2>[
    Vec2(bounds.left, bounds.top),
    Vec2(bounds.right, bounds.top),
    Vec2(bounds.right, bounds.bottom),
    Vec2(bounds.left, bounds.bottom),
  ];

  final handles = <Vec2>[
    ...corners,
    Vec2((bounds.left + bounds.right) * 0.5, bounds.top),
    Vec2(bounds.right, (bounds.top + bounds.bottom) * 0.5),
    Vec2((bounds.left + bounds.right) * 0.5, bounds.bottom),
    Vec2(bounds.left, (bounds.top + bounds.bottom) * 0.5),
  ];

  return MultiSelectGeometry(
    bounds: bounds,
    corners: corners,
    handles: handles,
    pivotWorld: bounds.center,
  );
}