set method

void set(
  1. Shape shape,
  2. int index
)

Initialize the proxy using the given shape. The shape must remain in scope while the proxy is in use.

Implementation

void set(final Shape shape, int index) {
  switch (shape.shapeType) {
    case ShapeType.CIRCLE:
      final circle = shape as CircleShape;
      vertices[0].setFrom(circle.p);
      _count = 1;
      radius = circle.radius;

      break;
    case ShapeType.POLYGON:
      final poly = shape as PolygonShape;
      _count = poly.count;
      radius = poly.radius;
      for (int 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._count);

      buffer[0] = chain._vertices[index];
      if (index + 1 < chain._count) {
        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);
  }
}