diff options
author | Tavian Barnes <tavianator@gmail.com> | 2012-02-06 10:11:22 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2012-02-06 10:11:22 -0500 |
commit | 22baedd972429c03c4c4d836a11f81f646ce0c92 (patch) | |
tree | cd90704829fe2484b582e010b73c642aad34a8cb | |
parent | f658e4728c53b5a772b0fcd06bd2647e35e9d59c (diff) | |
download | dimension-22baedd972429c03c4c4d836a11f81f646ce0c92.tar.xz |
Add debugging tests for NaN values.
-rw-r--r-- | libdimension/canvas.c | 1 | ||||
-rw-r--r-- | libdimension/dimension/color.h | 7 | ||||
-rw-r--r-- | libdimension/dimension/geometry.h | 36 | ||||
-rw-r--r-- | libdimension/dimension/object.h | 4 | ||||
-rw-r--r-- | libdimension/dimension/tcolor.h | 7 |
5 files changed, 55 insertions, 0 deletions
diff --git a/libdimension/canvas.c b/libdimension/canvas.c index 2bcc502..8671402 100644 --- a/libdimension/canvas.c +++ b/libdimension/canvas.c @@ -72,6 +72,7 @@ dmnsn_canvas_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y, { dmnsn_assert(x < canvas->width && y < canvas->height, "Canvas access out of bounds."); + dmnsn_assert(!dmnsn_tcolor_isnan(tcolor), "Pixel has NaN component."); /* Set the pixel */ canvas->pixels[y*canvas->width + x] = tcolor; diff --git a/libdimension/dimension/color.h b/libdimension/dimension/color.h index 34f3884..967e9a5 100644 --- a/libdimension/dimension/color.h +++ b/libdimension/dimension/color.h @@ -164,6 +164,13 @@ dmnsn_color_saturate(dmnsn_color color) return color; } +/** Return whether a color contains any NaN components. */ +DMNSN_INLINE bool +dmnsn_color_isnan(dmnsn_color color) +{ + return isnan(color.R) || isnan(color.G) || isnan(color.B); +} + /* Standard colors */ /** Black. */ diff --git a/libdimension/dimension/geometry.h b/libdimension/dimension/geometry.h index 80da735..38afa3b 100644 --- a/libdimension/dimension/geometry.h +++ b/libdimension/dimension/geometry.h @@ -445,3 +445,39 @@ dmnsn_bounding_box_is_infinite(dmnsn_bounding_box box) { return box.min.x == -INFINITY; } + +/** Return whether a vector contains any NaN components. */ +DMNSN_INLINE bool +dmnsn_vector_isnan(dmnsn_vector v) +{ + return isnan(v.x) || isnan(v.y) || isnan(v.z); +} + +/** Return whether a matrix contains any NaN components. */ +DMNSN_INLINE bool +dmnsn_matrix_isnan(dmnsn_matrix m) +{ + size_t i, j; + for (i = 0; i < 3; ++i) { + for (j = 0; j < 4; ++j) { + if (isnan(m.n[i][j])) { + return true; + } + } + } + return false; +} + +/** Return whether a line contains any NaN entries. */ +DMNSN_INLINE bool +dmnsn_line_isnan(dmnsn_line l) +{ + return dmnsn_vector_isnan(l.x0) || dmnsn_vector_isnan(l.n); +} + +/** Return whether a bounding box has any NaN components. */ +DMNSN_INLINE bool +dmnsn_bounding_box_isnan(dmnsn_bounding_box box) +{ + return dmnsn_vector_isnan(box.min) || dmnsn_vector_isnan(box.max); +} diff --git a/libdimension/dimension/object.h b/libdimension/dimension/object.h index 9019c69..28cc266 100644 --- a/libdimension/dimension/object.h +++ b/libdimension/dimension/object.h @@ -134,6 +134,10 @@ dmnsn_object_intersection(const dmnsn_object *object, dmnsn_line line, intersection->object = object; } + dmnsn_assert(!isnan(intersection->t), "Intersection point is NaN."); + dmnsn_assert(!dmnsn_vector_isnan(intersection->normal), + "Intersection normal is NaN."); + return true; } else { return false; diff --git a/libdimension/dimension/tcolor.h b/libdimension/dimension/tcolor.h index 5ccec3b..50bdf8c 100644 --- a/libdimension/dimension/tcolor.h +++ b/libdimension/dimension/tcolor.h @@ -99,6 +99,13 @@ dmnsn_tcolor_saturate(dmnsn_tcolor tcolor) return tcolor; } +/** Return whether a tcolor contains any NaN components. */ +DMNSN_INLINE bool +dmnsn_tcolor_isnan(dmnsn_tcolor tcolor) +{ + return dmnsn_color_isnan(tcolor.c) || isnan(tcolor.T) || isnan(tcolor.F); +} + /* Standard tcolors */ /** Clear. */ |