computeAABB method

  1. @override
void computeAABB(
  1. AABB aabb,
  2. Transform xf,
  3. int childIndex
)
override

Given a transform, compute the associated axis aligned bounding box for a child shape.

Implementation

@override
void computeAABB(AABB aabb, Transform xf, int childIndex) {
  assert(childIndex < vertexCount);
  final lower = aabb.lowerBound;
  final upper = aabb.upperBound;

  final i1 = childIndex;
  var i2 = childIndex + 1;
  if (i2 == vertexCount) {
    i2 = 0;
  }

  final vi1 = vertices[i1];
  final vi2 = vertices[i2];
  final xfq = xf.q;
  final xfp = xf.p;
  final v1x = (xfq.cos * vi1.x - xfq.sin * vi1.y) + xfp.x;
  final v1y = (xfq.sin * vi1.x + xfq.cos * vi1.y) + xfp.y;
  final v2x = (xfq.cos * vi2.x - xfq.sin * vi2.y) + xfp.x;
  final v2y = (xfq.sin * vi2.x + xfq.cos * vi2.y) + xfp.y;

  lower.x = v1x < v2x ? v1x : v2x;
  lower.y = v1y < v2y ? v1y : v2y;
  upper.x = v1x > v2x ? v1x : v2x;
  upper.y = v1y > v2y ? v1y : v2y;
}