commit 495b9419cbf97dda1b52967d7f9ac25afb52fa1b
parent f599633b14950ea4679099d9695e9b056ac05662
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 29 Jun 2016 18:21:21 +0200
Test the s2d_scene_trace_ray_3d function
Diffstat:
4 files changed, 152 insertions(+), 2 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -133,6 +133,7 @@ if(NOT NO_TEST)
new_test(test_s2d_session_advanced)
new_test(test_s2d_shape)
new_test(test_s2d_trace_ray)
+ new_test(test_s2d_trace_ray_3d)
endif(NOT NO_TEST)
################################################################################
diff --git a/src/s2d_scene.c b/src/s2d_scene.c
@@ -795,7 +795,7 @@ s2d_scene_trace_ray
}
res_T
-s2d_scene_trance_ray_3d
+s2d_scene_trace_ray_3d
(struct s2d_scene* scn,
const float org[3],
const float dir[3],
@@ -808,6 +808,9 @@ s2d_scene_trance_ray_3d
float dot;
res_T res = RES_OK;
+ if(!dir || !range || !hit) {
+ return RES_BAD_ARG;
+ }
if(!f3_is_normalized(dir)) {
log_error(scn->dev,
"%s: The ray direction should be normalized.\n", __FUNCTION__);
diff --git a/src/test_s2d_trace_ray.c b/src/test_s2d_trace_ray.c
@@ -130,8 +130,15 @@ main(int argc, char** argv)
CHECK(eq_epsf(hit.u, 0.5f, 1.e-6f), 1);
CHECK(eq_epsf(hit.distance, 1.0f, 1.e-6f), 1);
- f2(dir, 0.f, -1.f);
prim = hit.prim;
+
+ f2(dir, 0.f, -1.f);
+ range[1] = 0.5f;
+ CHECK(s2d_scene_trace_ray(scn, org, dir, range, NULL, &hit), RES_OK);
+ CHECK(S2D_HIT_NONE(&hit), 1);
+ range[1] = FLT_MAX;
+
+ f2(dir, 0.f, -1.f);
CHECK(s2d_scene_trace_ray(scn, org, dir, range, &prim, &hit), RES_OK);
CHECK(S2D_HIT_NONE(&hit), 1);
diff --git a/src/test_s2d_trace_ray_3d.c b/src/test_s2d_trace_ray_3d.c
@@ -0,0 +1,139 @@
+/* Copyright (C) |Meso|Star> 2016 (contact@meso-star.com)
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms. */
+
+#include "s2d.h"
+#include "test_s2d_utils.h"
+
+#include <rsys/float2.h>
+#include <rsys/float3.h>
+
+int
+main(int argc, char** argv)
+{
+ struct mem_allocator allocator;
+ struct s2d_device* dev;
+ struct s2d_scene* scn;
+ struct s2d_shape* shape;
+ struct s2d_vertex_data vdata;
+ struct s2d_hit hit;
+ float org[3];
+ float dir[3];
+ float range[2];
+ float tmp[2];
+ float dot;
+ (void)argc, (void)argv;
+
+ mem_init_proxy_allocator(&allocator, &mem_default_allocator);
+
+ CHECK(s2d_device_create(NULL, &allocator, 1, &dev), RES_OK);
+ CHECK(s2d_scene_create(dev, &scn), RES_OK);
+ CHECK(s2d_shape_create_line_segments(dev, &shape), RES_OK);
+ CHECK(s2d_scene_attach_shape(scn, shape), RES_OK);
+
+ vdata.get = line_segments_get_position;
+ vdata.type = S2D_FLOAT2;
+ vdata.usage = S2D_POSITION;
+ CHECK(s2d_line_segments_setup_indexed_vertices
+ (shape, box_nsegs, line_segments_get_ids, box_nverts, &vdata, 1,
+ (void*)&box_desc), RES_OK);
+
+ f3_splat(org, 0.f);
+ f3(dir, 1, 0, 0);
+ f2(range, 0, FLT_MAX);
+
+ CHECK(s2d_scene_begin_session(scn, S2D_TRACE), RES_OK);
+
+ #define TRACE_3D s2d_scene_trace_ray_3d
+ CHECK(TRACE_3D(NULL, NULL, NULL, NULL, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, NULL, NULL, NULL, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, org, NULL, NULL, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, org, NULL, NULL, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, NULL, dir, NULL, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, NULL, dir, NULL, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, org, dir, NULL, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, org, dir, NULL, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, NULL, NULL, range, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, NULL, NULL, range, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, org, NULL, range, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, org, NULL, range, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, NULL, dir, range, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, NULL, dir, range, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, org, dir, range, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, org, dir, range, NULL, NULL), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, NULL, NULL, NULL, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, NULL, NULL, NULL, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, org, NULL, NULL, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, org, NULL, NULL, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, NULL, dir, NULL, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, NULL, dir, NULL, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, org, dir, NULL, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, org, dir, NULL, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, NULL, NULL, range, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, NULL, NULL, range, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, org, NULL, range, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, org, NULL, range, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, NULL, dir, range, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, NULL, dir, range, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(NULL, org, dir, range, NULL, &hit), RES_BAD_ARG);
+ CHECK(TRACE_3D(scn, org, dir, range, NULL, &hit), RES_OK);
+
+ CHECK(S2D_HIT_NONE(&hit), 0);
+ f2_normalize(hit.normal, hit.normal);
+ CHECK(f2_eq_eps(hit.normal, f2(tmp, -1.f, 0.f), 1.e-6f), 1);
+ CHECK(eq_epsf(hit.distance, 1.f, 1.e-6f), 1);
+ CHECK(eq_epsf(hit.u, 0.5f, 1.e-6f), 1);
+
+ f3_normalize(dir, f3(dir, 1.f, 0.f, 1.f));
+ CHECK(TRACE_3D(scn, org, dir, range, NULL, &hit), RES_OK);
+ CHECK(S2D_HIT_NONE(&hit), 0);
+ f2_normalize(hit.normal, hit.normal);
+ CHECK(f2_eq_eps(hit.normal, f2(tmp, -1.f, 0.f), 1.e-6f), 1);
+ CHECK(eq_epsf(hit.u, 0.5f, 1.e-6f), 1);
+
+ dot = dir[0];
+ CHECK(eq_epsf(hit.distance, 1.f / dot, 1.e-6f), 1);
+
+ range[1] = 1.2f;
+ CHECK(TRACE_3D(scn, org, dir, range, NULL, &hit), RES_OK);
+ CHECK(S2D_HIT_NONE(&hit), 1);
+
+ CHECK(s2d_scene_end_session(scn), RES_OK);
+
+ CHECK(TRACE_3D(scn, org, dir, range, NULL, &hit), RES_BAD_OP);
+ #undef TRACE_3D
+
+ CHECK(s2d_scene_ref_put(scn), RES_OK);
+ CHECK(s2d_shape_ref_put(shape), RES_OK);
+ CHECK(s2d_device_ref_put(dev), RES_OK);
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHECK(mem_allocated_size(), 0);
+
+ return 0;
+}