overlaps method

bool overlaps(
  1. AABB aabb
)

Returns true if the given AABB overlaps this AABB.

Implementation

bool overlaps(AABB aabb) {
  final l1 = lowerBound;
  final u1 = upperBound;
  final l2 = aabb.lowerBound;
  final u2 = aabb.upperBound;

  //      l2        u2
  //      |---------|
  // |--------|
  // l1       u1

  final overlapsX = (l2.x <= u1.x && u1.x <= u2.x) || (l1.x <= u2.x && u2.x <= u1.x);
  final overlapsY = (l2.y <= u1.y && u1.y <= u2.y) || (l1.y <= u2.y && u2.y <= u1.y);
  final overlapsZ = (l2.z <= u1.z && u1.z <= u2.z) || (l1.z <= u2.z && u2.z <= u1.z);

  return overlapsX && overlapsY && overlapsZ;
}