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
Polygon rotate(double angle, [Point<num>? origin]) {
final rotOrigin = origin ?? centroid;
final ox = rotOrigin.x.toDouble();
final oy = rotOrigin.y.toDouble();
final cosA = math.cos(angle);
final sinA = math.sin(angle);
Point<double> rotatePoint(Point<num> p) {
final px = p.x.toDouble();
final py = p.y.toDouble();
final nx = cosA * (px - ox) - sinA * (py - oy) + ox;
final ny = sinA * (px - ox) + cosA * (py - oy) + oy;
return Point(x: nx, y: ny);
}
return Polygon(vertices.map(rotatePoint).toList(growable: false));
}