summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-05-29 17:12:23 -0600
committerTavian Barnes <tavianator@gmail.com>2010-05-29 17:12:23 -0600
commiteb020a7251cdd1671218448f9456a6a6f30e59d5 (patch)
treef45a945bdfeec33b64f415b2ad52edf840140ade /libdimension
parent7ca4d094639ffc302cdc7da5cdc291cc32005ecb (diff)
downloaddimension-eb020a7251cdd1671218448f9456a6a6f30e59d5.tar.xz
Slight prtree search optimization.
Exploit floating-point infinities to eliminate special t < 0.0 condition.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/prtree.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/libdimension/prtree.c b/libdimension/prtree.c
index c9c4f9a..a806850 100644
--- a/libdimension/prtree.c
+++ b/libdimension/prtree.c
@@ -575,7 +575,7 @@ dmnsn_ray_box_intersection(dmnsn_line line, dmnsn_bounding_box box, double t)
if (tmax < 0.0)
return false;
- return t < 0.0 || tmin < t;
+ return tmin < t;
}
static void
@@ -592,7 +592,7 @@ dmnsn_prtree_search_recursive(const dmnsn_prtree_node *node, dmnsn_line ray,
dmnsn_intersection local_intersection;
if ((*object->intersection_fn)(object, ray, &local_intersection)) {
- if (*t < 0.0 || local_intersection.t < *t) {
+ if (local_intersection.t < *t) {
*intersection = local_intersection;
*t = local_intersection.t;
}
@@ -608,13 +608,13 @@ bool
dmnsn_prtree_search(const dmnsn_prtree *tree, dmnsn_line ray,
dmnsn_intersection *intersection)
{
- double t = -1.0;
+ double t = INFINITY;
/* Search the unbounded objects */
DMNSN_ARRAY_FOREACH (dmnsn_object **, object, tree->unbounded) {
dmnsn_intersection local_intersection;
if ((*(*object)->intersection_fn)(*object, ray, &local_intersection)) {
- if (t < 0.0 || local_intersection.t < t) {
+ if (local_intersection.t < t) {
*intersection = local_intersection;
t = local_intersection.t;
}
@@ -626,5 +626,5 @@ dmnsn_prtree_search(const dmnsn_prtree *tree, dmnsn_line ray,
dmnsn_prtree_search_recursive(tree->root, ray, intersection, &t);
}
- return t >= 0.0;
+ return !isinf(t);
}