rotate method

  1. @override
Ellipse rotate(
  1. double angle, [
  2. Point<num>? origin
])
override

Rotates the shape by the given angle (in radians) around the origin. If origin is omitted, rotates around the shape's centroid.

Implementation

@override
Ellipse rotate(double angle, [Point<num>? origin]) {
  // For an axis-aligned Ellipse, rotating perfectly requires transforming it into a general polygon
  // or tracking an orientation angle. To maintain mathematical purity of our CRTP
  // without expanding state unnecessarily, we rotate its geometric center around the origin.
  final rotOrigin = origin ?? centroid;
  final ox = rotOrigin.x.toDouble();
  final oy = rotOrigin.y.toDouble();
  final cx = _center.x.toDouble();
  final cy = _center.y.toDouble();

  final cosA = math.cos(angle);
  final sinA = math.sin(angle);

  final nx = cosA * (cx - ox) - sinA * (cy - oy) + ox;
  final ny = sinA * (cx - ox) + cosA * (cy - oy) + oy;

  return Ellipse(semiMajorAxis: semiMajorAxis, semiMinorAxis: semiMinorAxis, center: Point(x: nx, y: ny));
}