commit 5b505c5c959b5c035fcc68ab91d13f473a9fc718
parent b0747383f216360d9c1045ac9e0b9a579aa3192f
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 16 Jul 2024 15:44:30 +0200
Improve test_partition
Add an ascii art picture of the 3 different models and additional
comments.
Also the geometry is simplified as the purpose of this test only needs
2 cubes.
Finally, run the 3 models both with and without allowing overlapping.
Diffstat:
1 file changed, 33 insertions(+), 21 deletions(-)
diff --git a/src/test_partition.c b/src/test_partition.c
@@ -27,20 +27,27 @@
#include <stdlib.h>
#include <stdio.h>
+/*
+ * +-------+ +-------+ +------+
+ * | | +----+ | +----+ | +----+
+ * | | | | | | | | || |
+ * | | +----+ | +----+ | +----+
+ * +-------+ +-------+ +------+
+ * x = 1.1 x = 1 x = 0.9
+ */
+
static res_T
two_geoms
(double x,
const int allow_overlapping,
struct mem_allocator* allocator)
{
- double p0[3] = {0, 0, 2};
- double d0[3] = {1, 1, 1};
double p1[3] = {0, 0, 0};
double d1[3] = {1, 1, 1};
double p2[3];
double d2[3] = {0.5, 0.5, 0.5};
- struct scad_geometry* geoms[3];
- struct scad_geometry* out_geoms[3];
+ struct scad_geometry* geoms[2];
+ struct scad_geometry* out_geoms[2];
char name[64];
res_T res;
@@ -49,39 +56,42 @@ two_geoms
/* set position for cube #2 */
d3(p2, x, 0.25, 0.25);
- OK(scad_add_box("cube0", p0, d0, geoms));
- OK(scad_add_box("cube1", p1, d1, geoms+1));
- OK(scad_add_box("cube2", p2, d2, geoms+2));
+ OK(scad_add_box("cube1", p1, d1, geoms+0));
+ OK(scad_add_box("cube2", p2, d2, geoms+1));
- res = scad_geometries_partition(geoms, 3, allow_overlapping, out_geoms);
+ /* Try to partition.
+ * Fails if the 2 cubes overlap and overlapping is not allowed. */
+ res = scad_geometries_partition(geoms, 2, allow_overlapping, out_geoms);
if(res != RES_OK) goto end;
+ /* Try to export the partitioned geometry in STL files.
+ * If normal are forced, it fails when the geometry does not properly define
+ * an inside / outside. */
OK(scad_scene_mesh());
if(allow_overlapping) {
snprintf(name, sizeof(name), "part_%g_1o", x);
- OK(scad_stl_export(out_geoms[0], name, Scad_force_normals_outward, 0));
+ /* If x==0.9, cubes 1 & 2 intersect. As a consequence, the partitioned
+ * geometry of both cubes does not define and inside/outside and the
+ * partitioned geometry cannot have its normals forced */
+ if(x == 0.9) {
+ BAD(scad_stl_export(out_geoms[0], name, Scad_force_normals_outward, 0));
+ OK(scad_stl_export(out_geoms[0], name, Scad_keep_normals_unchanged, 0));
+ } else {
+ OK(scad_stl_export(out_geoms[0], name, Scad_force_normals_outward, 1));
+ }
snprintf(name, sizeof(name), "part_%g_2o", x);
- /* If 0.9, cubes 1 & 2 intersect and the partitioned geometry cannot have
- * its normals forced */
if(x == 0.9) {
BAD(scad_stl_export(out_geoms[1], name, Scad_force_normals_outward, 1));
OK(scad_stl_export(out_geoms[1], name, Scad_keep_normals_unchanged, 1));
- snprintf(name, sizeof(name), "part_%g_3o", x);
- BAD(scad_stl_export(out_geoms[2], name, Scad_force_normals_outward, 1));
- OK(scad_stl_export(out_geoms[2], name, Scad_keep_normals_unchanged, 1));
} else {
OK(scad_stl_export(out_geoms[1], name, Scad_force_normals_outward, 1));
- snprintf(name, sizeof(name), "part_%g_3o", x);
- OK(scad_stl_export(out_geoms[2], name, Scad_force_normals_outward, 1));
}
} else {
snprintf(name, sizeof(name), "part_%g_1", x);
OK(scad_stl_export(geoms[0], name, Scad_force_normals_outward, 0));
snprintf(name, sizeof(name), "part_%g_2", x);
OK(scad_stl_export(geoms[1], name, Scad_force_normals_outward, 1));
- snprintf(name, sizeof(name), "part_%g_3", x);
- OK(scad_stl_export(out_geoms[2], name, Scad_force_normals_outward, 1));
}
end:
@@ -99,13 +109,15 @@ main(int argc, char* argv[])
OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
- /* First with distant geometries */
+ /* With distant geometries */
OK(two_geoms(1.1, 0, &allocator));
+ OK(two_geoms(1.1, 1, &allocator));
- /* First with contacting geometries */
+ /* With contacting geometries */
OK(two_geoms(1, 0, &allocator));
+ OK(two_geoms(1, 1, &allocator));
- /* First with overlapping geometries */
+ /* With overlapping geometries */
BAD(two_geoms(0.9, 0, &allocator));
OK(two_geoms(0.9, 1, &allocator));