summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dimension/parse.c12
-rw-r--r--libdimension/dimension/geometry.h18
-rw-r--r--libdimension/raytrace.c13
3 files changed, 25 insertions, 18 deletions
diff --git a/dimension/parse.c b/dimension/parse.c
index 7edf22a..7b4a35b 100644
--- a/dimension/parse.c
+++ b/dimension/parse.c
@@ -903,6 +903,7 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_make_ast_float(&ret, ((double)l)/r);
}
break;
+
case DMNSN_AST_EQUAL:
dmnsn_make_ast_integer(&ret, l == r);
break;
@@ -989,11 +990,12 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
case DMNSN_AST_DIV:
dmnsn_make_ast_float(&ret, l/r);
break;
+
case DMNSN_AST_EQUAL:
- dmnsn_make_ast_integer(&ret, l == r);
+ dmnsn_make_ast_integer(&ret, fabs(l - r) < dmnsn_epsilon);
break;
case DMNSN_AST_NOT_EQUAL:
- dmnsn_make_ast_integer(&ret, l != r);
+ dmnsn_make_ast_integer(&ret, fabs(l - r) >= dmnsn_epsilon);
break;
case DMNSN_AST_LESS:
dmnsn_make_ast_integer(&ret, l < r);
@@ -1008,10 +1010,12 @@ dmnsn_eval_binary(dmnsn_astnode astnode, dmnsn_symbol_table *symtable)
dmnsn_make_ast_integer(&ret, l >= r);
break;
case DMNSN_AST_AND:
- dmnsn_make_ast_integer(&ret, l && r);
+ dmnsn_make_ast_integer(&ret, fabs(l) >= dmnsn_epsilon
+ && fabs(r) >= dmnsn_epsilon);
break;
case DMNSN_AST_OR:
- dmnsn_make_ast_integer(&ret, l || r);
+ dmnsn_make_ast_integer(&ret, fabs(l) >= dmnsn_epsilon
+ || fabs(r) >= dmnsn_epsilon);
break;
default:
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)