DistanceProxy class
A distance proxy is used by the GJK algorithm. It encapsulates any shape.
class DistanceProxy { final List<Vector> vertices; int count; num radius; /** * Constructs a new DistanceProxy. */ DistanceProxy() : vertices = new List<Vector>(Settings.MAX_POLYGON_VERTICES), count = 0, radius = 0 { for(int i = 0; i < vertices.length; ++i) vertices[i] = new Vector(); } /** * 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].setFrom(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].setFrom(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(Vector direction) { int bestIndex = 0; num bestValue = Vector.dot(vertices[0], direction); for (int i = 1; i < count; ++i) { num value = Vector.dot(vertices[i], direction); if(value > bestValue) { bestIndex = i; bestValue = value; } } return bestIndex; } /** * Get the supporting vertex in the given direction. */ Vector getSupportVertex(Vector direction) => vertices[getSupport(direction)]; }
Constructors
new DistanceProxy() #
Constructs a new DistanceProxy.
DistanceProxy() : vertices = new List<Vector>(Settings.MAX_POLYGON_VERTICES), count = 0, radius = 0 { for(int i = 0; i < vertices.length; ++i) vertices[i] = new Vector(); }
Properties
int count #
int count;
num radius #
num radius;
final Type runtimeType #
A representation of the runtime type of the object.
external Type get runtimeType;
Operators
bool operator ==(other) #
The equality operator.
The default behavior for all Object
s is to return true if and
only if this
and
other are the same object.
If a subclass overrides the equality operator it should override
the hashCode
method as well to maintain consistency.
bool operator ==(other) => identical(this, other);
Methods
new DistanceProxy() #
Constructs a new DistanceProxy.
DistanceProxy() : vertices = new List<Vector>(Settings.MAX_POLYGON_VERTICES), count = 0, radius = 0 { for(int i = 0; i < vertices.length; ++i) vertices[i] = new Vector(); }
int getSupport(Vector direction) #
Get the supporting vertex index in the given direction.
int getSupport(Vector direction) { int bestIndex = 0; num bestValue = Vector.dot(vertices[0], direction); for (int i = 1; i < count; ++i) { num value = Vector.dot(vertices[i], direction); if(value > bestValue) { bestIndex = i; bestValue = value; } } return bestIndex; }
Vector getSupportVertex(Vector direction) #
Get the supporting vertex in the given direction.
Vector getSupportVertex(Vector direction) => vertices[getSupport(direction)];
int hashCode() #
Get a hash code for this object.
All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator ==
. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.
If a subclass overrides hashCode
it should override the
equality operator as well to maintain consistency.
external int hashCode();
noSuchMethod(String name, List args) #
noSuchMethod
is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to noSuchMethod
. If noSuchMethod
returns a value, that value becomes the result of the original
invocation.
The default behavior of noSuchMethod
is to throw a
noSuchMethodError
.
external Dynamic noSuchMethod(String name, List args);
const Object() #
Creates a new Object
instance.
Object
instances have no meaningful state, and are only useful
through their identity. An Object
instance is equal to itself
only.
const Object();
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].setFrom(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].setFrom(shape.vertices[i]); } } else { // Should always be a circle or a polygon. assert(false); } }
String toString() #
Returns a string representation of this object.
external String toString();