DistanceProxy class
class DistanceProxy { final List<vec2> vertices; int count; num radius; /** * Constructs a new DistanceProxy. */ DistanceProxy() : vertices = new List<vec2>(Settings.MAX_POLYGON_VERTICES), count = 0, radius = 0 { for(int i = 0; i < vertices.length; ++i) vertices[i] = new vec2.zero(); } /** * Initialize the proxy using the given shape. The shape * must remain in scope while the proxy is in use. */ void setFromShape(shape) { // If the shape is a circle... if (shape.type == ShapeType.CIRCLE) { vertices[0].copyFrom(shape.position); count = 1; radius = shape.radius; // If the shape is a polygon... } else if (shape.type == ShapeType.POLYGON) { count = shape.vertexCount; radius = shape.radius; for(int i = 0; i < count; i++) { vertices[i].copyFrom(shape.vertices[i]); } } else { // Should always be a circle or a polygon. assert(false); } } /** * Get the supporting vertex index in the given direction. */ int getSupport(vec2 direction) { int bestIndex = 0; num bestValue = dot(vertices[0], direction); for (int i = 1; i < count; ++i) { num value = dot(vertices[i], direction); if(value > bestValue) { bestIndex = i; bestValue = value; } } return bestIndex; } /** * Get the supporting vertex in the given direction. */ vec2 getSupportVertex(vec2 direction) => vertices[getSupport(direction)]; }
Constructors
new DistanceProxy() #
Constructs a new DistanceProxy.
DistanceProxy() : vertices = new List<vec2>(Settings.MAX_POLYGON_VERTICES), count = 0, radius = 0 { for(int i = 0; i < vertices.length; ++i) vertices[i] = new vec2.zero(); }
Methods
int getSupport(vec2 direction) #
Get the supporting vertex index in the given direction.
int getSupport(vec2 direction) { int bestIndex = 0; num bestValue = dot(vertices[0], direction); for (int i = 1; i < count; ++i) { num value = dot(vertices[i], direction); if(value > bestValue) { bestIndex = i; bestValue = value; } } return bestIndex; }
vec2 getSupportVertex(vec2 direction) #
Get the supporting vertex in the given direction.
vec2 getSupportVertex(vec2 direction) => vertices[getSupport(direction)];
void setFromShape(shape) #
Initialize the proxy using the given shape. The shape must remain in scope while the proxy is in use.
void setFromShape(shape) { // If the shape is a circle... if (shape.type == ShapeType.CIRCLE) { vertices[0].copyFrom(shape.position); count = 1; radius = shape.radius; // If the shape is a polygon... } else if (shape.type == ShapeType.POLYGON) { count = shape.vertexCount; radius = shape.radius; for(int i = 0; i < count; i++) { vertices[i].copyFrom(shape.vertices[i]); } } else { // Should always be a circle or a polygon. assert(false); } }