CircleShape class
class CircleShape extends Shape { /** * The current position of the center of this circle. */ final Vector2 position; /** * A constructor for internal use only. Instead use Body.createShape with a * CircleDef. */ CircleShape() : super(ShapeType.CIRCLE, 0.0), position = new Vector2.zero(); /** * Constructs a new CircleShape equal to the given CircleShape. */ CircleShape.copy(CircleShape other) : super(other.type, other.radius), position = new Vector2.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, Vector2 point) { Vector2 center = new Vector2.zero(); transform.rotation.transformed(position, center); center.add(transform.position); Vector2 d = center.sub(point).negate(); return d.dot(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) { Vector2 p = new Vector2.zero(); argTransform.rotation.transformed(position, p); p.add(argTransform.position); argBox.lowerBound.setValues(p.x - radius, p.y - radius); argBox.upperBound.setValues(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 + position.dot(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.0), position = new Vector2.zero();
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 Vector2.copy(other.position) { }
Properties
Methods
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) { Vector2 p = new Vector2.zero(); argTransform.rotation.transformed(position, p); p.add(argTransform.position); argBox.lowerBound.setValues(p.x - radius, p.y - radius); argBox.upperBound.setValues(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 + position.dot(position)); }
bool testPoint(Transform transform, Vector2 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, Vector2 point) { Vector2 center = new Vector2.zero(); transform.rotation.transformed(position, center); center.add(transform.position); Vector2 d = center.sub(point).negate(); return d.dot(d) <= radius * radius; }