intersectsWithPlane method Null safety

bool intersectsWithPlane(
  1. Plane other,
  2. {IntersectionResult? result}
)

Return if this intersects with other

Implementation

bool intersectsWithPlane(Plane other, {IntersectionResult? result}) {
  // This line is not necessary with a (center, extents) AABB representation
  copyCenterAndHalfExtents(_aabbCenter, _aabbHalfExtents);

  // Compute the projection interval radius of b onto L(t) = b.c + t * p.n
  final r = _aabbHalfExtents[0] * other.normal[0].abs() +
      _aabbHalfExtents[1] * other.normal[1].abs() +
      _aabbHalfExtents[2] * other.normal[2].abs();
  // Compute distance of box center from plane
  final s = other.normal.dot(_aabbCenter) - other.constant;
  // Intersection occurs when distance s falls within [-r,+r] interval
  if (s.abs() <= r) {
    final a = s - r;
    if (result != null && (result._depth == null || (result._depth!) < a)) {
      result._depth = a;
      result.axis.setFrom(other.normal);
    }
    return true;
  }

  return false;
}