rotate static method

DiagramElement rotate(
  1. DiagramElement element, {
  2. required DiagramPoint pivot,
  3. required double radians,
})

Rotate by radians about a world-space pivot.

Shape sizes and local paths remain unchanged. Free endpoints rotate and bound endpoints remain attached to their owners. Control points are relative to the endpoint chord, so they follow it unchanged. A saved elbow route cannot be rotated and is discarded for normal routing.

Implementation

static DiagramElement rotate(
  DiagramElement element, {
  required DiagramPoint pivot,
  required double radians,
}) {
  _requireFinitePoint(pivot, 'pivot');
  if (!radians.isFinite) {
    throw ArgumentError.value(radians, 'radians', 'must be finite');
  }
  if (radians == 0) return element;
  DiagramPoint rotatePoint(DiagramPoint point) =>
      point.rotateAround(pivot, radians);
  return switch (element) {
    FramedElement() => element.copyWith(
      frame: element.frame.center == pivot
          ? element.frame
          : DiagramRect.fromCenter(
              center: rotatePoint(element.frame.center),
              size: element.frame.size,
            ),
      rotation: element.rotation + radians,
    ),
    ConnectorElement() => element.copyWith(
      start: _mapEndpoint(element.start, rotatePoint),
      end: _mapEndpoint(element.end, rotatePoint),
      routedPoints: const [],
    ),
  };
}