summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-03-19 13:38:22 -0400
committerTavian Barnes <tavianator@gmail.com>2010-03-19 13:38:22 -0400
commitfc06cb624d79788923ab2dedb3cd2ccab53cb2b4 (patch)
tree081c1267b2661b53dfcb02b636c6594e05c6e195 /libdimension
parentc01e193e19d45e2c5b1e86928cedc11cdbdda476 (diff)
downloaddimension-fc06cb624d79788923ab2dedb3cd2ccab53cb2b4.tar.xz
Make float equality comparisons more relaxed.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/dimension/geometry.h18
-rw-r--r--libdimension/raytrace.c13
2 files changed, 17 insertions, 14 deletions
diff --git a/libdimension/dimension/geometry.h b/libdimension/dimension/geometry.h
index d44c7db..2276d5b 100644
--- a/libdimension/dimension/geometry.h
+++ b/libdimension/dimension/geometry.h
@@ -39,7 +39,10 @@ typedef struct {
dmnsn_vector n; /* A normal vector; the direction of the line */
} dmnsn_line;
-/* Vector constants */
+/* Constants */
+
+#define dmnsn_epsilon 1.0e-9
+
static const dmnsn_vector dmnsn_zero = { 0.0, 0.0, 0.0 };
static const dmnsn_vector dmnsn_x = { 1.0, 0.0, 0.0 };
static const dmnsn_vector dmnsn_y = { 0.0, 1.0, 0.0 };
@@ -188,6 +191,19 @@ dmnsn_line_point(dmnsn_line l, double t)
return dmnsn_vector_add(l.x0, dmnsn_vector_mul(t, l.n));
}
+/* Add epsilon*l.n to l.x0, to avoid self-intersections */
+DMNSN_INLINE dmnsn_line
+dmnsn_line_add_epsilon(dmnsn_line l)
+{
+ return dmnsn_new_line(
+ dmnsn_vector_add(
+ l.x0,
+ dmnsn_vector_mul(dmnsn_epsilon, l.n)
+ ),
+ l.n
+ );
+}
+
/* Solve for the t value such that x0 + t*n = x */
double dmnsn_line_index(dmnsn_line l, dmnsn_vector x);
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c
index 9d6397e..61ebd08 100644
--- a/libdimension/raytrace.c
+++ b/libdimension/raytrace.c
@@ -279,19 +279,6 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene,
return 0;
}
-/* Add epsilon*l.n to l.x0, to avoid self-intersections */
-static dmnsn_line
-dmnsn_line_add_epsilon(dmnsn_line l)
-{
- return dmnsn_new_line(
- dmnsn_vector_add(
- l.x0,
- dmnsn_vector_mul(1.0e-9, l.n)
- ),
- l.n
- );
-}
-
#define ITEXTURE(state) (state->intersection->texture)
#define DTEXTURE(state) (state->scene->default_texture)