set method
Initialize the proxy using the given shape. The shape must remain in scope while the proxy is in use.
Implementation
void set(Shape shape, int index) {
switch (shape.shapeType) {
case ShapeType.circle:
final circle = shape as CircleShape;
vertices[0].setFrom(circle.position);
_count = 1;
radius = circle.radius;
break;
case ShapeType.polygon:
final poly = shape as PolygonShape;
_count = poly.vertices.length;
radius = poly.radius;
for (var i = 0; i < _count; i++) {
vertices[i].setFrom(poly.vertices[i]);
}
break;
case ShapeType.chain:
final chain = shape as ChainShape;
assert(0 <= index && index < chain.vertexCount);
buffer[0] = chain.vertices[index];
if (index + 1 < chain.vertexCount) {
buffer[1] = chain.vertices[index + 1];
} else {
buffer[1] = chain.vertices[0];
}
vertices[0].setFrom(buffer[0]);
vertices[1].setFrom(buffer[1]);
_count = 2;
radius = chain.radius;
break;
case ShapeType.edge:
final edge = shape as EdgeShape;
vertices[0].setFrom(edge.vertex1);
vertices[1].setFrom(edge.vertex2);
_count = 2;
radius = edge.radius;
break;
default:
assert(false);
}
}