project method
Returns the result of applying an affine transformation to the shape.
Certain shapes may be transformed into shapes of a different kind during
the projection. For example, a Circle
may transform into an Ellipse
,
and Rectangle
into a Polygon
.
If target
is provided and it has a proper type, then this method should
modify the target in-place and return it. If target
is null, or if its
type is not compatible with the requested transform
, then the method
should create and return a new Shape.
Implementation
@override
Shape project(Transform2D transform, [Shape? target]) {
final n = _vertices.length;
if (target is Polygon && target.vertices.length == n) {
for (var i = 0; i < n; i++) {
target._vertices[i].setFrom(transform.localToGlobal(_vertices[i]));
}
target._initializeEdges();
target._convex = _convex;
if (transform.hasReflection) {
target._reverseVertices();
target._initializeEdges();
}
return target;
}
final newVertices = _vertices
.map((vertex) => transform.localToGlobal(vertex))
.toList(growable: false);
final convex = transform.hasReflection ? null : _convex;
return Polygon(newVertices, convex: convex);
}