commit 4f82a8098ed4f2a99d0eeb4369b28a491f276b2f
parent f67cf71a7c737b94255788e81d37e5a9bb794685
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Wed, 19 Aug 2020 20:01:59 +0200
Add a new test (enclosures in contact at a single vertex)
Diffstat:
3 files changed, 236 insertions(+), 2 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -161,10 +161,11 @@ if(NOT NO_TEST)
new_test(test_senc3d_some_enclosures)
new_test(test_senc3d_some_triangles)
new_test(test_senc3d_unspecified_medium)
+ new_test(test_senc3d_zero_distance)
build_test(test_senc3d_many_enclosures test_senc3d_utils2.h)
build_test(test_senc3d_many_triangles test_senc3d_utils2.h)
-
+
target_link_libraries(test_senc3d_enclosure Star3D)
target_link_libraries(test_senc3d_sample_enclosure StarSP Star3D)
target_link_libraries(test_senc3d_many_enclosures Star3DUT)
diff --git a/src/test_senc3d_utils.h b/src/test_senc3d_utils.h
@@ -113,7 +113,7 @@ static INLINE void
get_position(const unsigned ivert, double pos[3], void* context)
{
const struct context* ctx = context;
- ASSERT(pos && ctx);
+ ASSERT(pos && ctx && ctx->scale);
pos[0] = ctx->positions[ivert * 3 + 0] * ctx->scale + ctx->offset[0];
pos[1] = ctx->positions[ivert * 3 + 1] * ctx->scale + ctx->offset[1];
pos[2] = ctx->positions[ivert * 3 + 2] * ctx->scale + ctx->offset[2];
diff --git a/src/test_senc3d_zero_distance.c b/src/test_senc3d_zero_distance.c
@@ -0,0 +1,232 @@
+/* Copyright (C) |Meso|Star> 2016-2020 (contact@meso-star.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* This test has been created using the sg3_geometry_dump_as_C_code feature
+ * of star-geometry. It uses output from test_sg3_cube_on_cube. */
+
+#define _POSIX_C_SOURCE 200112L /* snprintf */
+
+#include "senc3d.h"
+#include "test_senc3d_utils.h"
+
+#include <rsys/double3.h>
+
+#include <stdio.h>
+
+/* Test created using -c option of stardis */
+#define zero_1_UNSPECIFIED_PROPERTY 4294967295
+
+static const unsigned
+zero_1_vertices_count = 22;
+
+static const unsigned
+zero_1_triangles_count = 36;
+
+static const double
+zero_1_vertices[22][3] = {
+ { 10, 10, 0 },
+ { 10, 0, 0 },
+ { 0, 10, 0 },
+ { 0, 0, 0 },
+ { 0, 10, 10 },
+ { 0, 0, 10 },
+ { 10, 0, 10 },
+ { 9, 9, 11 },
+ { 8, 9, 1 },
+ { 4, 7, 1 },
+ { 1, 9, 1 },
+ { 1, 2, 1 },
+ { 1, 9, 9 },
+ { 1, 2, 9 },
+ { 4, 7, 9 },
+ { 7, 5, 1 },
+ { 9, 8, 1 },
+ { 9, 1, 1 },
+ { 2, 1, 1 },
+ { 2, 1, 9 },
+ { 9, 1, 9 },
+ { 7, 4, 9 }
+};
+
+static const unsigned
+zero_1_triangles[36][3] = {
+ { 0, 1, 2 },
+ { 1, 3, 2 },
+ { 4, 5, 6 },
+ { 7, 4, 6 },
+ { 2, 3, 4 },
+ { 3, 5, 4 },
+ { 6, 1, 7 },
+ { 1, 0, 7 },
+ { 0, 2, 4 },
+ { 7, 0, 4 },
+ { 5, 3, 1 },
+ { 6, 5, 1 },
+ { 8, 9, 10 },
+ { 9, 11, 10 },
+ { 12, 13, 14 },
+ { 7, 12, 14 },
+ { 10, 11, 12 },
+ { 11, 13, 12 },
+ { 14, 9, 7 },
+ { 9, 8, 7 },
+ { 8, 10, 12 },
+ { 7, 8, 12 },
+ { 13, 11, 9 },
+ { 14, 13, 9 },
+ { 15, 16, 17 },
+ { 18, 15, 17 },
+ { 19, 20, 21 },
+ { 20, 7, 21 },
+ { 18, 17, 20 },
+ { 19, 18, 20 },
+ { 15, 21, 7 },
+ { 16, 15, 7 },
+ { 17, 16, 20 },
+ { 16, 7, 20 },
+ { 18, 19, 15 },
+ { 19, 21, 15 }
+};
+
+static const unsigned
+zero_1_properties[36][3] = {
+ { 0, zero_1_UNSPECIFIED_PROPERTY, 2 },
+ { 0, zero_1_UNSPECIFIED_PROPERTY, 2 },
+ { 0, zero_1_UNSPECIFIED_PROPERTY, 2 },
+ { 0, zero_1_UNSPECIFIED_PROPERTY, 2 },
+ { 0, zero_1_UNSPECIFIED_PROPERTY, 2 },
+ { 0, zero_1_UNSPECIFIED_PROPERTY, 2 },
+ { 0, zero_1_UNSPECIFIED_PROPERTY, 2 },
+ { 0, zero_1_UNSPECIFIED_PROPERTY, 2 },
+ { 0, zero_1_UNSPECIFIED_PROPERTY, 2 },
+ { 0, zero_1_UNSPECIFIED_PROPERTY, 2 },
+ { 0, zero_1_UNSPECIFIED_PROPERTY, 2 },
+ { 0, zero_1_UNSPECIFIED_PROPERTY, 2 },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY },
+ { 1, 0, zero_1_UNSPECIFIED_PROPERTY }
+};
+
+int
+test
+ (const double* positions,
+ const unsigned* indices,
+ const unsigned* properties)
+{
+ struct mem_allocator allocator;
+ struct senc3d_device* dev = NULL;
+ struct senc3d_scene* scn = NULL;
+ struct context ctx = CONTEXT_NULL__;
+ unsigned count, e, n;
+
+ OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
+ OK(senc3d_device_create(NULL, &allocator, 1, 1, &dev));
+
+ FOR_EACH(n, 0, 2) {
+ /* Create a scene with 4 enclosures joining at a single vertex. */
+ ctx.positions = positions;
+ ctx.indices = indices;
+ ctx.properties = properties;
+
+ if(n == 1) {
+ /* Same model with symmetry / origin
+ * (need to reverse vertices' order to keep same inside/outside) */
+ ctx.scale = -1;
+ ctx.reverse_vrtx = 1;
+ }
+
+ OK(senc3d_scene_create(dev,
+ SENC3D_CONVENTION_NORMAL_BACK | SENC3D_CONVENTION_NORMAL_OUTSIDE,
+ zero_1_triangles_count, get_indices, get_media_from_properties,
+ zero_1_vertices_count, get_position, &ctx, &scn));
+
+ OK(senc3d_scene_get_enclosure_count(scn, &count));
+ CHK(count == 4);
+
+ OK(senc3d_scene_get_vertices_count(scn, &count));
+ CHK(count == zero_1_vertices_count);
+
+ OK(senc3d_scene_get_triangles_count(scn, &count));
+ CHK(count == zero_1_triangles_count);
+
+ OK(senc3d_scene_get_enclosure_count(scn, &count));
+ CHK(count == 4);
+ FOR_EACH(e, 0, count) {
+ struct senc3d_enclosure* enclosure;
+ struct senc3d_enclosure_header header;
+ unsigned m;
+ char name[128]; (void)name;
+ OK(senc3d_scene_get_enclosure(scn, e, &enclosure));
+ OK(senc3d_enclosure_get_header(enclosure, &header));
+ CHK(header.enclosed_media_count == 1);
+ OK(senc3d_enclosure_get_medium(enclosure, 0, &m));
+ if (header.is_infinite) {
+ CHK(m == zero_1_UNSPECIFIED_PROPERTY); /* External */
+ }
+ else if (header.primitives_count == 12) {
+ CHK(m == 1); /* Internal */
+ }
+ else {
+ CHK(m == 0); /* In between */
+ }
+ OK(senc3d_enclosure_ref_put(enclosure));
+#ifdef DUMP_ENCLOSURES
+ snprintf(name, sizeof(name), "test_cube_on_cube_%u.obj", e);
+ dump_enclosure(scn, e, name);
+#endif
+ }
+
+ OK(senc3d_scene_ref_put(scn));
+ }
+
+ OK(senc3d_device_ref_put(dev));
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHK(mem_allocated_size() == 0);
+ return 0;
+}
+
+int
+main(int argc, char** argv)
+{
+ (void)argc, (void)argv;
+
+ test((double *)zero_1_vertices, (unsigned*)zero_1_triangles,
+ (unsigned *)zero_1_properties);
+
+ return 0;
+}
+\ No newline at end of file