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]) {
if (transform.isAxisAligned && transform.isConformal) {
final v1 = transform.localToGlobal(Vector2(_left, _top));
final v2 = transform.localToGlobal(Vector2(_right, _bottom));
final newLeft = min(v1.x, v2.x);
final newRight = max(v1.x, v2.x);
final newTop = min(v1.y, v2.y);
final newBottom = max(v1.y, v2.y);
final newRadius = transform.scale.x.abs() * _radius;
if (target is RoundedRectangle) {
target._left = newLeft;
target._right = newRight;
target._top = newTop;
target._bottom = newBottom;
target._radius = newRadius;
target._aabb = null;
return target;
} else {
return RoundedRectangle.fromLTRBR(
newLeft,
newTop,
newRight,
newBottom,
newRadius,
);
}
}
throw UnimplementedError();
}