diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-07-09 20:18:25 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-07-09 20:18:53 -0600 |
commit | dda43d0adc1fb7323a6578f61565275694364bbd (patch) | |
tree | 1cfb6a39d7bd75f4b7a3b146f742c38e5297db0b | |
parent | 0abbb7511caf0039f13d0e2a8b1298545e7cdb25 (diff) | |
download | dimension-dda43d0adc1fb7323a6578f61565275694364bbd.tar.xz |
Save some degeneracy tests in ray-AABB intersection tests.
-rw-r--r-- | libdimension/prtree.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/libdimension/prtree.c b/libdimension/prtree.c index 04e7de9..e950917 100644 --- a/libdimension/prtree.c +++ b/libdimension/prtree.c @@ -529,7 +529,11 @@ dmnsn_ray_box_intersection(dmnsn_line line, dmnsn_bounding_box box, double t) { double tmin = -INFINITY, tmax = INFINITY; - if (line.n.x != 0.0 && box.min.x < box.max.x) { + /* Detenerate box test */ + if (box.min.x >= box.max.x) + return false; + + if (line.n.x != 0.0) { double tx1 = (box.min.x - line.x0.x)/line.n.x; double tx2 = (box.max.x - line.x0.x)/line.n.x; @@ -538,12 +542,11 @@ dmnsn_ray_box_intersection(dmnsn_line line, dmnsn_bounding_box box, double t) if (tmin > tmax) return false; - } else { - if (line.x0.x < box.min.x || line.x0.x > box.max.x) - return false; + } else if (line.x0.x < box.min.x || line.x0.x > box.max.x) { + return false; } - if (line.n.y != 0.0 && box.min.y < box.max.y) { + if (line.n.y != 0.0) { double ty1 = (box.min.y - line.x0.y)/line.n.y; double ty2 = (box.max.y - line.x0.y)/line.n.y; @@ -552,12 +555,11 @@ dmnsn_ray_box_intersection(dmnsn_line line, dmnsn_bounding_box box, double t) if (tmin > tmax) return false; - } else { - if (line.x0.y < box.min.y || line.x0.y > box.max.y) - return false; + } else if (line.x0.y < box.min.y || line.x0.y > box.max.y) { + return false; } - if (line.n.z != 0.0 && box.min.z < box.max.z) { + if (line.n.z != 0.0) { double tz1 = (box.min.z - line.x0.z)/line.n.z; double tz2 = (box.max.z - line.x0.z)/line.n.z; @@ -566,15 +568,11 @@ dmnsn_ray_box_intersection(dmnsn_line line, dmnsn_bounding_box box, double t) if (tmin > tmax) return false; - } else { - if (line.x0.z < box.min.z || line.x0.z > box.max.z) - return false; - } - - if (tmax < 0.0) + } else if (line.x0.z < box.min.z || line.x0.z > box.max.z) { return false; + } - return tmin < t; + return tmax >= 0.0 && tmin < t; } static void |