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