PolygonComponent constructor

PolygonComponent(
  1. List<Vector2> _vertices, {
  2. Vector2? position,
  3. Vector2? size,
  4. Vector2? scale,
  5. double? angle,
  6. Anchor? anchor,
  7. Iterable<Component>? children,
  8. int? priority,
  9. Paint? paint,
  10. List<Paint>? paintLayers,
  11. ComponentKey? key,
  12. bool? shrinkToBounds,
})

With this constructor you create your PolygonComponent from positions in anywhere in the 2d-space. It will automatically calculate the size of the Polygon (the bounding box) if no size it given.

Implementation

PolygonComponent(
  this._vertices, {
  super.position,
  super.size,
  super.scale,
  super.angle,
  super.anchor,
  super.children,
  super.priority,
  super.paint,
  super.paintLayers,
  super.key,
  bool? shrinkToBounds,
})  : assert(
        _vertices.length > 2,
        'Number of vertices are too few to create a polygon',
      ),
      shrinkToBounds = shrinkToBounds ?? size == null,
      manuallyPositioned = position != null {
  refreshVertices(newVertices: _vertices);

  final verticesLength = _vertices.length;
  _globalVertices = List.generate(
    verticesLength,
    (_) => Vector2.zero(),
    growable: false,
  );
  _lineSegments = List.generate(
    verticesLength,
    (_) => LineSegment.zero(),
    growable: false,
  );
}