refreshVertices method

  1. @protected
void refreshVertices({
  1. required List<Vector2> newVertices,
  2. bool? shrinkToBoundsOverride,
})

Implementation

@protected
void refreshVertices({
  required List<Vector2> newVertices,
  bool? shrinkToBoundsOverride,
}) {
  assert(
    newVertices.length == _vertices.length,
    'A polygon can not change their number of vertices',
  );
  // If the list isn't ccw we have to reverse the order in order for
  // `containsPoint` to work.
  if (_isClockwise(newVertices)) {
    newVertices.reverse();
  }
  final topLeft = Vector2.zero();
  topLeft.setFrom(newVertices[0]);
  for (var i = 0; i < newVertices.length; i++) {
    final newVertex = newVertices[i];
    _vertices[i].setFrom(newVertex);
    topLeft.x = min(topLeft.x, newVertex.x);
    topLeft.y = min(topLeft.y, newVertex.y);
  }
  for (var i = 0; i < newVertices.length; i++) {
    final newVertex = newVertices[i];
    _vertices[i].setFrom(newVertex - topLeft);
  }
  _path
    ..reset()
    ..addPolygon(
      _vertices.map((p) => p.toOffset()).toList(growable: false),
      true,
    );
  if (shrinkToBoundsOverride ?? shrinkToBounds) {
    final bounds = _path.getBounds();
    size.setValues(bounds.width, bounds.height);
    if (!manuallyPositioned) {
      position = Anchor.topLeft.toOtherAnchorPosition(topLeft, anchor, size);
    }
  }
}