Dart Documentationbox2d_consoleDistanceProxy

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 #

inherited from Object

A representation of the runtime type of the object.

external Type get runtimeType;

final List<Vector> vertices #

final List<Vector> vertices;

Operators

bool operator ==(other) #

inherited from Object

The equality operator.

The default behavior for all Objects 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() #

inherited from Object

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) #

inherited from Object

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() #

inherited from 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() #

inherited from Object

Returns a string representation of this object.

external String toString();