RoundedPolygon.fromFeatures constructor
RoundedPolygon.fromFeatures(
- List<
PolygonFeature> features, { - Offset? center,
Creates a polygon from features, which describe each segment of its
outline.
Specifying the features directly controls precisely how the polygon's CubicBeziers are grouped into curves, and it is those groups that Morph maps: it pairs each curve with one of the same type in the other shape, convex with convex and concave with concave.
center defaults to the average of every cubic's starting anchor point.
Throws ArgumentError if features has fewer than 2 elements, or if the
features don't describe a closed shape.
Implementation
factory fromFeatures(List<PolygonFeature> features, {Offset? center}) {
if (features.length < 2) {
throw ArgumentError("Polygons must have at least 2 features.");
}
if (center != null) return ._raw(features, center);
final vertices = <Point>[];
for (final feature in features) {
for (final cubic in feature.cubics) {
vertices.add(.new(cubic.anchor0X, cubic.anchor0Y));
}
}
return ._raw(features, calculateCenter(vertices));
}