refreshVertices method
void
refreshVertices(
{ - required List<Vector2> newVertices,
})
Implementation
@protected
void refreshVertices({required List<Vector2> newVertices}) {
assert(
newVertices.length == _vertices.length,
'A polygon can not change their number of vertices',
);
_topLeft.setFrom(newVertices[0]);
newVertices.forEachIndexed((i, _) {
final newVertex = newVertices[i];
_vertices[i].setFrom(newVertex);
_topLeft.x = min(_topLeft.x, newVertex.x);
_topLeft.y = min(_topLeft.y, newVertex.y);
});
_path
..reset()
..addPolygon(
vertices.map((p) => (p - _topLeft).toOffset()).toList(growable: false),
true,
);
if (shrinkToBounds) {
final bounds = _path.getBounds();
size.setValues(bounds.width, bounds.height);
if (!manuallyPositioned) {
position = Anchor.topLeft.toOtherAnchorPosition(_topLeft, anchor, size);
}
}
_vertices.forEach((p) {
p.setValues(
p.x - _topLeft.x,
p.y - _topLeft.y,
);
});
}