summaryrefslogtreecommitdiffstats
path: root/libdimension/dimension
diff options
context:
space:
mode:
Diffstat (limited to 'libdimension/dimension')
-rw-r--r--libdimension/dimension/geometry.h24
-rw-r--r--libdimension/dimension/object.h2
2 files changed, 20 insertions, 6 deletions
diff --git a/libdimension/dimension/geometry.h b/libdimension/dimension/geometry.h
index 0be0c6a..754e46d 100644
--- a/libdimension/dimension/geometry.h
+++ b/libdimension/dimension/geometry.h
@@ -26,19 +26,23 @@
#define DIMENSION_GEOMETRY_H
#include <math.h>
+#include <stdbool.h>
-/* Vector and matrix types. */
+/* Vector and matrix types */
-typedef struct { double x, y, z; } dmnsn_vector;
+typedef struct dmnsn_vector { double x, y, z; } dmnsn_vector;
-typedef struct { double n[4][4]; } dmnsn_matrix;
+typedef struct dmnsn_matrix { double n[4][4]; } dmnsn_matrix;
-/* A line, or ray. */
-typedef struct {
+/* A line, or ray */
+typedef struct dmnsn_line {
dmnsn_vector x0; /* A point on the line */
dmnsn_vector n; /* A normal vector; the direction of the line */
} dmnsn_line;
+/* A bounding box */
+typedef struct dmnsn_bounding_box { dmnsn_vector min, max; } dmnsn_bounding_box;
+
/* Constants */
#define dmnsn_epsilon 1.0e-9
@@ -189,6 +193,8 @@ double dmnsn_vector_axis_angle(dmnsn_vector v1, dmnsn_vector v2,
dmnsn_matrix dmnsn_matrix_inverse(dmnsn_matrix A);
dmnsn_matrix dmnsn_matrix_mul(dmnsn_matrix lhs, dmnsn_matrix rhs);
dmnsn_vector dmnsn_matrix_vector_mul(dmnsn_matrix lhs, dmnsn_vector rhs);
+dmnsn_bounding_box dmnsn_matrix_bounding_box_mul(dmnsn_matrix lhs,
+ dmnsn_bounding_box rhs);
/* Affine line transformation; n = lhs*(x0 + n) - lhs*x0, x0 *= lhs */
DMNSN_INLINE dmnsn_line
@@ -227,4 +233,12 @@ dmnsn_line_add_epsilon(dmnsn_line l)
/* Solve for the t value such that x0 + t*n = x */
double dmnsn_line_index(dmnsn_line l, dmnsn_vector x);
+/* Return whether p is within the axis-aligned bounding box */
+DMNSN_INLINE bool
+dmnsn_bounding_box_contains(dmnsn_bounding_box box, dmnsn_vector p)
+{
+ return (p.x >= box.min.x && p.y >= box.min.y && p.z >= box.min.z)
+ && (p.x <= box.max.x && p.y <= box.max.y && p.z <= box.max.z);
+}
+
#endif /* DIMENSION_GEOMETRY_H */
diff --git a/libdimension/dimension/object.h b/libdimension/dimension/object.h
index bd78a35..525c637 100644
--- a/libdimension/dimension/object.h
+++ b/libdimension/dimension/object.h
@@ -68,7 +68,7 @@ struct dmnsn_object {
dmnsn_matrix trans, trans_inv;
/* Bounding box */
- dmnsn_vector min, max;
+ dmnsn_bounding_box bounding_box;
/* Callback functions */
dmnsn_object_intersection_fn *intersection_fn;