RoundedPolygon.fromFeatures constructor

RoundedPolygon.fromFeatures({
  1. required List<Feature> features,
  2. double centerX = .nan,
  3. double centerY = .nan,
})

Implementation

factory RoundedPolygon.fromFeatures({
  required List<Feature> features,
  double centerX = .nan,
  double centerY = .nan,
}) {
  if (features.length < 2) {
    throw ArgumentError("Polygons must have at least 2 features.");
  }

  // TODO: is is the most optimal solution? if not, optimize this implementation
  final vertices = [
    for (final feature in features)
      for (final cubic in feature.cubics) ...[cubic.anchor0X, cubic.anchor0Y],
  ];

  final cX = centerX.isNaN ? calculateCenter(vertices).x : centerX;
  final cY = centerY.isNaN ? calculateCenter(vertices).y : centerY;

  return RoundedPolygon(features, Point(cX, cY));
}