summaryrefslogtreecommitdiffstats
path: root/bench
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-10-25 23:27:41 +0000
committerTavian Barnes <tavianator@gmail.com>2009-10-25 23:27:41 +0000
commit5391e7cc0830a9a574fcb24ce86e4b2f37eef1eb (patch)
tree943de0526d7701637893fb9e5a0a029181f19598 /bench
parent58a3e7f99534be1e5fcd501b138e0be8b274b326 (diff)
downloaddimension-5391e7cc0830a9a574fcb24ce86e4b2f37eef1eb.tar.xz
Properly generate random bounding boxes in kD splay tree benchmark.
Diffstat (limited to 'bench')
-rw-r--r--bench/libdimension/kD_splay_tree.c47
1 files changed, 34 insertions, 13 deletions
diff --git a/bench/libdimension/kD_splay_tree.c b/bench/libdimension/kD_splay_tree.c
index ee8e975..44a8ef1 100644
--- a/bench/libdimension/kD_splay_tree.c
+++ b/bench/libdimension/kD_splay_tree.c
@@ -30,17 +30,40 @@ dmnsn_fake_intersection_fn(const dmnsn_object *object, dmnsn_line line)
return intersection;
}
-dmnsn_vector
-dmnsn_random_vector(dmnsn_vector min)
+void
+dmnsn_randomize_bounding_box(dmnsn_object *object)
{
- dmnsn_vector ret;
- ret.x = 2.0*((double)rand())/RAND_MAX - 1.0;
- ret.y = 2.0*((double)rand())/RAND_MAX - 1.0;
- ret.z = 2.0*((double)rand())/RAND_MAX - 1.0;
- if (ret.x < min.x) ret.x += 2.0;
- if (ret.y < min.y) ret.y += 2.0;
- if (ret.z < min.z) ret.z += 2.0;
- return ret;
+ double rand1, rand2;
+
+ rand1 = 2.0*((double)rand())/RAND_MAX - 1.0;
+ rand2 = 2.0*((double)rand())/RAND_MAX - 1.0;
+ if (rand1 < rand2) {
+ object->min.x = rand1;
+ object->max.x = rand2;
+ } else {
+ object->max.x = rand1;
+ object->min.x = rand2;
+ }
+
+ rand1 = 2.0*((double)rand())/RAND_MAX - 1.0;
+ rand2 = 2.0*((double)rand())/RAND_MAX - 1.0;
+ if (rand1 < rand2) {
+ object->min.y = rand1;
+ object->max.y = rand2;
+ } else {
+ object->max.y = rand1;
+ object->min.y = rand2;
+ }
+
+ rand1 = 2.0*((double)rand())/RAND_MAX - 1.0;
+ rand2 = 2.0*((double)rand())/RAND_MAX - 1.0;
+ if (rand1 < rand2) {
+ object->min.z = rand1;
+ object->max.z = rand2;
+ } else {
+ object->max.z = rand1;
+ object->min.z = rand2;
+ }
}
dmnsn_kD_splay_node *
@@ -107,9 +130,7 @@ main()
}
/* Generate a bounding box in (-1, -1, -1), (1, 1, 1) */
- objects[i]->min =
- dmnsn_random_vector(dmnsn_vector_construct(-1.0, -1.0, -1.0));
- objects[i]->max = dmnsn_random_vector(objects[i]->min);
+ dmnsn_randomize_bounding_box(objects[i]);
objects[i]->intersection_fn = &dmnsn_fake_intersection_fn;
}