collideCircles method

void collideCircles(
  1. Manifold manifold,
  2. CircleShape circle1,
  3. Transform xfA,
  4. CircleShape circle2,
  5. Transform xfB
)

Compute the collision manifold between two circles.

Implementation

void collideCircles(Manifold manifold, final CircleShape circle1,
    final Transform xfA, final CircleShape circle2, final Transform xfB) {
  manifold.pointCount = 0;
  // before inline:
  // Transform.mulToOut(xfA, circle1.p, pA);
  // Transform.mulToOut(xfB, circle2.p, pB);
  // d.set(pB).subLocal(pA);
  // double distSqr = d.x * d.x + d.y * d.y;

  // after inline:
  Vector2 circle1p = circle1.p;
  Vector2 circle2p = circle2.p;
  double pAx = (xfA.q.c * circle1p.x - xfA.q.s * circle1p.y) + xfA.p.x;
  double pAy = (xfA.q.s * circle1p.x + xfA.q.c * circle1p.y) + xfA.p.y;
  double pBx = (xfB.q.c * circle2p.x - xfB.q.s * circle2p.y) + xfB.p.x;
  double pBy = (xfB.q.s * circle2p.x + xfB.q.c * circle2p.y) + xfB.p.y;
  double dx = pBx - pAx;
  double dy = pBy - pAy;
  double distSqr = dx * dx + dy * dy;
  // end inline

  final double radius = circle1.radius + circle2.radius;
  if (distSqr > radius * radius) {
    return;
  }

  manifold.type = ManifoldType.CIRCLES;
  manifold.localPoint.setFrom(circle1p);
  manifold.localNormal.setZero();
  manifold.pointCount = 1;

  manifold.points[0].localPoint.setFrom(circle2p);
  manifold.points[0].id.zero();
}