Dart Documentationbox2d_consoleCircleShape

CircleShape class

A shape commonly known as the circle.

class CircleShape extends Shape {
  /**
   * The current position of the center of this circle.
   */
  final Vector position;

  /**
   * A constructor for internal use only. Instead use Body.createShape with a
   * CircleDef.
   */
  CircleShape() :
    super(ShapeType.CIRCLE, 0),
    position = new Vector() {
  }

  /**
   * Constructs a new CircleShape equal to the given CircleShape.
   */
  CircleShape.copy(CircleShape other) :
    super(other.type, other.radius),
    position = new Vector.copy(other.position) { }


  /**
   * Returns true if the point is contained in the given shape when the given
   * rotation transform is applied. Implements superclass abstract method of
   * the same name.
   */
  bool testPoint(Transform transform, Vector point) {
    Vector center = new Vector();
    transform.rotation.multiplyVectorToOut(position, center);
    center.addLocal(transform.position);

    Vector d = center.subLocal(point).negateLocal();
    return Vector.dot(d, d) <= radius * radius;
  }

  /**
   * Compute the axis aligned box for this Shape when the given transform is
   * applied. Stores the result in the given box.
   */
  void computeAxisAlignedBox(AxisAlignedBox argBox, Transform argTransform) {
    Vector p = new Vector();
    Matrix22.mulMatrixAndVectorToOut(argTransform.rotation, position, p);
    p.addLocal(argTransform.position);

    argBox.lowerBound.setCoords(p.x - radius, p.y - radius);
    argBox.upperBound.setCoords(p.x + radius, p.y + radius);
  }

  /** Returns a clone of this circle. */
  Shape clone() => new CircleShape.copy(this);

  /**
   * Computes the mass properties of this Circle at the given density and stores
   * the result in the given MassData object.
   */
  void computeMass(MassData massData, num density) {
    massData.mass = density * Math.PI * radius * radius;
    massData.center.setFrom(position);

    // Store inertia above the local origin.
    massData.inertia = massData.mass * (.5 * radius * radius +
        Vector.dot(position, position));
  }
}

Extends

Shape > CircleShape

Constructors

new CircleShape() #

A constructor for internal use only. Instead use Body.createShape with a CircleDef.

CircleShape() :
  super(ShapeType.CIRCLE, 0),
  position = new Vector() {
}

new CircleShape.copy(CircleShape other) #

Constructs a new CircleShape equal to the given CircleShape.

CircleShape.copy(CircleShape other) :
  super(other.type, other.radius),
  position = new Vector.copy(other.position) { }

Properties

final Vector position #

The current position of the center of this circle.

final Vector position;

num radius #

inherited from Shape

Shape radius.

num radius;

final Type runtimeType #

inherited from Object

A representation of the runtime type of the object.

external Type get runtimeType;

int type #

inherited from Shape

The type of shape. Either circle or polygon.

int type;

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

A constructor for internal use only. Instead use Body.createShape with a CircleDef.

CircleShape() :
  super(ShapeType.CIRCLE, 0),
  position = new Vector() {
}

new CircleShape.copy(CircleShape other) #

Constructs a new CircleShape equal to the given CircleShape.

CircleShape.copy(CircleShape other) :
  super(other.type, other.radius),
  position = new Vector.copy(other.position) { }

Shape clone() #

Returns a clone of this circle.

Shape clone() => new CircleShape.copy(this);

void computeAxisAlignedBox(AxisAlignedBox argBox, Transform argTransform) #

Compute the axis aligned box for this Shape when the given transform is applied. Stores the result in the given box.

void computeAxisAlignedBox(AxisAlignedBox argBox, Transform argTransform) {
  Vector p = new Vector();
  Matrix22.mulMatrixAndVectorToOut(argTransform.rotation, position, p);
  p.addLocal(argTransform.position);

  argBox.lowerBound.setCoords(p.x - radius, p.y - radius);
  argBox.upperBound.setCoords(p.x + radius, p.y + radius);
}

void computeMass(MassData massData, num density) #

Computes the mass properties of this Circle at the given density and stores the result in the given MassData object.

void computeMass(MassData massData, num density) {
  massData.mass = density * Math.PI * radius * radius;
  massData.center.setFrom(position);

  // Store inertia above the local origin.
  massData.inertia = massData.mass * (.5 * radius * radius +
      Vector.dot(position, position));
}

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

new Shape([int type = ShapeType.UNKNOWN, num radius = 0]) #

inherited from Shape

Constructs a new shape of unknown type.

Shape([int type = ShapeType.UNKNOWN, num radius = 0]) :
  type = type,
  radius = radius { }

bool testPoint(Transform transform, Vector point) #

Returns true if the point is contained in the given shape when the given rotation transform is applied. Implements superclass abstract method of the same name.

bool testPoint(Transform transform, Vector point) {
  Vector center = new Vector();
  transform.rotation.multiplyVectorToOut(position, center);
  center.addLocal(transform.position);

  Vector d = center.subLocal(point).negateLocal();
  return Vector.dot(d, d) <= radius * radius;
}

String toString() #

inherited from Object

Returns a string representation of this object.

external String toString();