Dart Documentationbox2d_htmlSweep

Sweep class

class Sweep {
  /** Local center of mass position. */
  final Vector localCenter;

  /** Center world positions. */
  final Vector centerZero;
  final Vector center;

  /** World angles. */
  num angleZero;
  num angle;

  /**
   * Constructs a new Sweep with centers initialized to the origin and angles
   * set to zero.
   */
  Sweep()
      : localCenter = new Vector(),
        centerZero = new Vector(),
        center = new Vector(),
        angleZero = 0,
        angle = 0;

  /**
   * Constructs a new sweep that is a copy of the given Sweep.
   */
  Sweep.copy(Sweep other)
      : localCenter = new Vector.copy(other.localCenter),
        centerZero = new Vector.copy(other.centerZero),
        center = new Vector.copy(other.center),
        angleZero = other.angleZero,
        angle = other.angle;

  /**
   * Returns true if given object is equal to this sweep. Two sweeps are equal
   * if their fields are equal.
   */
  bool operator ==(other) {
    return localCenter == other.localCenter && centerZero == other.centerZero
        && center == other.center && angleZero == other.angleZero &&
        angle == other.angle;
  }

  /**
   * Sets this Sweep equal to the given Sweep.
   */
  void setFrom(Sweep other) {
    localCenter.setFrom(other.localCenter);
    centerZero.setFrom(other.centerZero);
    center.setFrom(other.center);
    angleZero = other.angleZero;
    angle = other.angle;
  }

  void normalize() {
    num d = MathBox.TWO_PI * (angleZero / MathBox.TWO_PI).floor();
    angleZero -= d;
    angle -= d;
  }

  /**
   * Computes the interpolated transform at a specific time.
   * Time is the normalized time in [0,1].
   */
  void getTransform(Transform xf, num alpha) {
    assert (xf != null);

    xf.position.x = (1.0 - alpha) * centerZero.x + alpha * center.x;
    xf.position.y = (1.0 - alpha) * centerZero.y + alpha * center.y;
    xf.rotation.setAngle((1.0 - alpha) * angleZero + alpha * angle);

    // Shift to origin
    xf.position.x -= xf.rotation.col1.x * localCenter.x + xf.rotation.col2.x
        * localCenter.y;
    xf.position.y -= xf.rotation.col1.y * localCenter.x + xf.rotation.col2.y
        * localCenter.y;
  }

  /**
   * Advances the sweep forward, resulting in a new initial state.
   * Time is the new initial time.
   */
  void advance(num time) {
    centerZero.x = (1 - time) * centerZero.x + time * center.x;
    centerZero.y = (1 - time) * centerZero.y + time * center.y;
    angleZero = (1 - time) * angleZero + time * angle;
  }
}

Constructors

new Sweep() #

Constructs a new Sweep with centers initialized to the origin and angles set to zero.

Sweep()
    : localCenter = new Vector(),
      centerZero = new Vector(),
      center = new Vector(),
      angleZero = 0,
      angle = 0;

new Sweep.copy(Sweep other) #

Constructs a new sweep that is a copy of the given Sweep.

Sweep.copy(Sweep other)
    : localCenter = new Vector.copy(other.localCenter),
      centerZero = new Vector.copy(other.centerZero),
      center = new Vector.copy(other.center),
      angleZero = other.angleZero,
      angle = other.angle;

Properties

num angle #

num angle;

num angleZero #

World angles.

num angleZero;

final Vector center #

final Vector center;

final Vector centerZero #

Center world positions.

final Vector centerZero;

final Vector localCenter #

Local center of mass position.

final Vector localCenter;

final Type runtimeType #

inherited from Object

A representation of the runtime type of the object.

external Type get runtimeType;

Operators

bool operator ==(other) #

Returns true if given object is equal to this sweep. Two sweeps are equal if their fields are equal.

bool operator ==(other) {
  return localCenter == other.localCenter && centerZero == other.centerZero
      && center == other.center && angleZero == other.angleZero &&
      angle == other.angle;
}

Methods

void advance(num time) #

Advances the sweep forward, resulting in a new initial state. Time is the new initial time.

void advance(num time) {
  centerZero.x = (1 - time) * centerZero.x + time * center.x;
  centerZero.y = (1 - time) * centerZero.y + time * center.y;
  angleZero = (1 - time) * angleZero + time * angle;
}

void getTransform(Transform xf, num alpha) #

Computes the interpolated transform at a specific time. Time is the normalized time in 0,1.

void getTransform(Transform xf, num alpha) {
  assert (xf != null);

  xf.position.x = (1.0 - alpha) * centerZero.x + alpha * center.x;
  xf.position.y = (1.0 - alpha) * centerZero.y + alpha * center.y;
  xf.rotation.setAngle((1.0 - alpha) * angleZero + alpha * angle);

  // Shift to origin
  xf.position.x -= xf.rotation.col1.x * localCenter.x + xf.rotation.col2.x
      * localCenter.y;
  xf.position.y -= xf.rotation.col1.y * localCenter.x + xf.rotation.col2.y
      * localCenter.y;
}

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

void normalize() #

void normalize() {
  num d = MathBox.TWO_PI * (angleZero / MathBox.TWO_PI).floor();
  angleZero -= d;
  angle -= d;
}

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 setFrom(Sweep other) #

Sets this Sweep equal to the given Sweep.

void setFrom(Sweep other) {
  localCenter.setFrom(other.localCenter);
  centerZero.setFrom(other.centerZero);
  center.setFrom(other.center);
  angleZero = other.angleZero;
  angle = other.angle;
}

new Sweep() #

Constructs a new Sweep with centers initialized to the origin and angles set to zero.

Sweep()
    : localCenter = new Vector(),
      centerZero = new Vector(),
      center = new Vector(),
      angleZero = 0,
      angle = 0;

new Sweep.copy(Sweep other) #

Constructs a new sweep that is a copy of the given Sweep.

Sweep.copy(Sweep other)
    : localCenter = new Vector.copy(other.localCenter),
      centerZero = new Vector.copy(other.centerZero),
      center = new Vector.copy(other.center),
      angleZero = other.angleZero,
      angle = other.angle;

String toString() #

inherited from Object

Returns a string representation of this object.

external String toString();