Dart Documentationbox2dCircleShape

CircleShape class

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 #

position

num radius #

inherited from Shape
radius

int type #

inherited from Shape
type

Methods

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

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;
}