rotate method
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
Rectangle rotate(double angle, [Point<num>? 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;
final absCos = cosA.abs();
final absSin = sinA.abs();
final newWidth = width * absCos + height * absSin;
final newHeight = width * absSin + height * absCos;
return Rectangle(width: newWidth, height: newHeight, center: Point(x: nx, y: ny));
}