Vector2 intersect(Ray r)

Intersects this box with the given ray and returns a vec2 containing the distances to the intersections.

If the v.x > v.y there is no hit point.

Source

Vector2 intersect(Ray r) {
  //TODO 0-direction or 0-divisor yield in NaN and +/- Infinity
  Vector3 t1 = (minCorner - r.origin).divide(r.direction);
  Vector3 t2 = (maxCorner - r.origin).divide(r.direction);

  Vector3 tMin = new Vector3.zero(), tMax = new Vector3.zero();
  Vector3.min(t1, t2, tMin);
  Vector3.max(t1, t2, tMax);

  num hit1 = Math.max(Math.max(tMin.x, tMin.y), tMin.z);
  num hit2 = Math.min(Math.min(tMin.x, tMin.y), tMin.z);

  return new Vector2(hit1, hit2);
}