star-geometry-3d

Clean and decorate 3D geometries
git clone git://git.meso-star.fr/star-geometry-3d.git
Log | Files | Refs | README | LICENSE

commit 855c8d9c3ff4bddb8a7c59bc118ecc0146af1224
parent cd3ddddd237f3b25eae063e77b87e88518709891
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri,  6 Dec 2019 16:38:30 +0100

More tests and fixes

Diffstat:
Msrc/sg3_geometry.c | 18++++--------------
Msrc/star-geometry.h | 13++++++++++++-
Msrc/test_sg3_report_2.c | 144++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Msrc/test_sg3_utils.h | 1+
4 files changed, 142 insertions(+), 34 deletions(-)

diff --git a/src/sg3_geometry.c b/src/sg3_geometry.c @@ -107,18 +107,6 @@ trg_make_key(struct unsigned3* k, const unsigned t[3]) } } -static INLINE int -compatible_property - (const enum sg3_property_type t, - const unsigned p1, - const unsigned p2) -{ - (void)t; /* Type is useless */ - if(p1 == SG3_UNDEFINED_PROPERTY || p2 == SG3_UNDEFINED_PROPERTY) return 1; - return (p1 == p2); -} - - /******************************************************************************* * Exported functions ******************************************************************************/ @@ -288,6 +276,7 @@ sg3_geometry_add struct unsigned3 utrg_key; int ureversed = trg_make_key(&utrg_key, trg[*p_trg].vertex_ids); int same = (reversed == ureversed); + int already_conflict; unsigned* uprop; ASSERT(trg_key_eq(&trg_key, &utrg_key)); unique_id = *p_trg; @@ -303,6 +292,7 @@ sg3_geometry_add if(!same) SWAP(unsigned, tmp.properties[SG3_FRONT], tmp.properties[SG3_BACK]); uprop = trg[*p_trg].properties; + already_conflict = p_trgd->merge_conflict; if(merge_trg) { /* Let the client app rule. */ ERR(merge_trg(trg[*p_trg].global_id, i, same, uprop, tmp.properties, @@ -311,7 +301,7 @@ sg3_geometry_add * of conflicts */ } else { FOR_EACH(j, 0, SG3_PROP_TYPES_COUNT__) { - if(!compatible_property(j, uprop[j], tmp.properties[j])) { + if(!sg3_compatible_property(uprop[j], tmp.properties[j])) { res = RES_BAD_ARG; p_trgd->merge_conflict = 1; break; @@ -319,7 +309,7 @@ sg3_geometry_add } } if(geom->report && p_trgd->merge_conflict) { - geom->report->merge_conflict_count++; + if(!already_conflict) geom->report->merge_conflict_count++; /* If merge_trg and we reached this line, merge_trg ruled no error */ if(!merge_trg) goto error; } diff --git a/src/star-geometry.h b/src/star-geometry.h @@ -83,10 +83,21 @@ enum sg3_report_dump_content { ******************************************************************************/ #define SG3_UNDEFINED_PROPERTY UINT_MAX - BEGIN_DECLS /******************************************************************************* + * A helper function on properties compatibility. + ******************************************************************************/ +static INLINE int +sg3_compatible_property + (const unsigned p1, + const unsigned p2) +{ + if(p1 == SG3_UNDEFINED_PROPERTY || p2 == SG3_UNDEFINED_PROPERTY) return 1; + return (p1 == p2); +} + +/******************************************************************************* * star-geometry device. It is an handle toward the star-geometry library. * It manages the star-geometry resources. ******************************************************************************/ diff --git a/src/test_sg3_report_2.c b/src/test_sg3_report_2.c @@ -52,11 +52,15 @@ merge_trg { struct context* ctx = context; struct add_geom_ctx* add_geom_ctx; + int i; ASSERT(ctx && triangle_properties && merged_properties && merge_conflict); (void)global_id; (void)itri; (void)reversed_triangle; - (void)triangle_properties; (void)merged_properties; (void)merge_conflict; + (void)triangle_properties; (void)merged_properties; add_geom_ctx = ctx->custom; if(add_geom_ctx->merge_res == RES_OK) ++add_geom_ctx->merge_cpt; + FOR_EACH(i, 0, 3) + if(!sg3_compatible_property(triangle_properties[i], merged_properties[i])) + *merge_conflict = 1; return add_geom_ctx->merge_res; } @@ -126,6 +130,14 @@ main(int argc, char** argv) CHK(count == 0); OK(sg3_report_get_unique_triangles_count(report, &count)); CHK(count == 0); + OK(sg3_report_get_triangle_with_undefined_side_count(report, &count)); + CHK(count == 0); + OK(sg3_report_get_triangle_with_undefined_interface_count(report, &count)); + CHK(count == 0); + OK(sg3_report_get_merge_conflict_count(report, &count)); + CHK(count == 0); + OK(sg3_report_get_properties_conflict_count(report, &count)); + CHK(count == 0); /* Successful add geometry with add callback */ add_geom_ctx.add_res = RES_OK; @@ -137,11 +149,14 @@ main(int argc, char** argv) CHK(count == nvertices); OK(sg3_report_get_unique_triangles_count(report, &count)); CHK(count == ntriangles); - OK(sg3_report_get_triangle_with_undefined_side_count(report, &count)); CHK(count == ntriangles); OK(sg3_report_get_triangle_with_undefined_interface_count(report, &count)); CHK(count == ntriangles); + OK(sg3_report_get_merge_conflict_count(report, &count)); + CHK(count == 0); + OK(sg3_report_get_properties_conflict_count(report, &count)); + CHK(count == 0); /* Clear geometry */ SG3(geometry_ref_put(geometry)); @@ -161,6 +176,14 @@ main(int argc, char** argv) CHK(count == nvertices); OK(sg3_report_get_unique_triangles_count(report, &count)); CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_side_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_interface_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_merge_conflict_count(report, &count)); + CHK(count == 0); + OK(sg3_report_get_properties_conflict_count(report, &count)); + CHK(count == 0); /* If merge fails, add geometry fails the same way */ add_geom_ctx.merge_res = RES_BAD_ARG; @@ -175,6 +198,14 @@ main(int argc, char** argv) CHK(count == nvertices); OK(sg3_report_get_unique_triangles_count(report, &count)); CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_side_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_interface_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_merge_conflict_count(report, &count)); + CHK(count == 0); /* merge failed but with a no-conflict status */ + OK(sg3_report_get_properties_conflict_count(report, &count)); + CHK(count == 0); /* Successful add geometry without merge callback */ OK(sg3_geometry_add(geometry, ntriangles, get_indices, get_properties, @@ -184,6 +215,14 @@ main(int argc, char** argv) CHK(count == nvertices); OK(sg3_report_get_unique_triangles_count(report, &count)); CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_side_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_interface_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_merge_conflict_count(report, &count)); + CHK(count == 0); + OK(sg3_report_get_properties_conflict_count(report, &count)); + CHK(count == 0); /* Successful add geometry with merge callback */ add_geom_ctx.merge_res = RES_OK; @@ -195,6 +234,14 @@ main(int argc, char** argv) CHK(count == nvertices); OK(sg3_report_get_unique_triangles_count(report, &count)); CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_side_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_interface_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_merge_conflict_count(report, &count)); + CHK(count == 0); /* merge failed but with a no-conflict status */ + OK(sg3_report_get_properties_conflict_count(report, &count)); + CHK(count == 0); /* Geometry with media information on both sides */ ctx.front_media = medium0; @@ -208,11 +255,23 @@ main(int argc, char** argv) /* Successful add geometry with add callback */ add_geom_ctx.add_res = RES_OK; - OK(sg3_geometry_add(geometry, ntriangles, get_indices, NULL, nvertices, - get_position, add_trg, merge_trg, &ctx)); + OK(sg3_geometry_add(geometry, ntriangles, get_indices, get_properties, + nvertices, get_position, add_trg, merge_trg, &ctx)); CHK(add_geom_ctx.add_cpt == ntriangles); CHK(add_geom_ctx.merge_cpt == 0); add_geom_ctx.add_cpt = 0; + OK(sg3_report_get_unique_vertices_count(report, &count)); + CHK(count == nvertices); + OK(sg3_report_get_unique_triangles_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_side_count(report, &count)); + CHK(count == 0); /* media where defined */ + OK(sg3_report_get_triangle_with_undefined_interface_count(report, &count)); + CHK(count == ntriangles); /* interfaces where undefined */ + OK(sg3_report_get_merge_conflict_count(report, &count)); + CHK(count == 0); + OK(sg3_report_get_properties_conflict_count(report, &count)); + CHK(count == 0); /* Clear geometry */ SG3(geometry_ref_put(geometry)); @@ -220,45 +279,92 @@ main(int argc, char** argv) OK(sg3_report_create(dev, &report)); OK(sg3_geometry_create(dev, report, &geometry)); - /* Successful add geometry with add callback */ + /* Successful add geometry with add callback and no defined properties */ add_geom_ctx.add_res = RES_OK; OK(sg3_geometry_add(geometry, ntriangles, get_indices, NULL, nvertices, get_position, add_trg, merge_trg, &ctx)); CHK(add_geom_ctx.add_cpt == ntriangles); CHK(add_geom_ctx.merge_cpt == 0); add_geom_ctx.add_cpt = 0; + OK(sg3_report_get_unique_vertices_count(report, &count)); + CHK(count == nvertices); + OK(sg3_report_get_unique_triangles_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_side_count(report, &count)); + CHK(count == ntriangles); /* media where undefined */ + OK(sg3_report_get_triangle_with_undefined_interface_count(report, &count)); + CHK(count == ntriangles); /* interfaces where undefined */ + OK(sg3_report_get_merge_conflict_count(report, &count)); + CHK(count == 0); + OK(sg3_report_get_properties_conflict_count(report, &count)); + CHK(count == 0); - /* Successful add geometry with merge callback */ + /* Define interface */ + ctx.intface = intface0; + + /* Successful add geometry with merge callback and properties */ add_geom_ctx.merge_res = RES_OK; - OK(sg3_geometry_add(geometry, ntriangles, get_indices, NULL, nvertices, - get_position, add_trg, merge_trg, &ctx)); + OK(sg3_geometry_add(geometry, ntriangles, get_indices, get_properties, + nvertices, get_position, add_trg, merge_trg, &ctx)); CHK(add_geom_ctx.merge_cpt == ntriangles); add_geom_ctx.merge_cpt = 0; + OK(sg3_report_get_unique_vertices_count(report, &count)); + CHK(count == nvertices); + OK(sg3_report_get_unique_triangles_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_side_count(report, &count)); + CHK(count == 0); /* media where defined */ + OK(sg3_report_get_triangle_with_undefined_interface_count(report, &count)); + CHK(count == 0); /* interfaces where defined */ + OK(sg3_report_get_merge_conflict_count(report, &count)); + CHK(count == 0); + OK(sg3_report_get_properties_conflict_count(report, &count)); + CHK(count == 0); /* Geometry with incompatible media information on both sides */ ctx.front_media = medium1; ctx.back_media = medium0; /* Unsuccessful add geometry without merge callback */ - OK(sg3_geometry_add(geometry, ntriangles, get_indices, NULL, nvertices, - get_position, add_trg, NULL, &ctx)); + BA(sg3_geometry_add(geometry, ntriangles, get_indices, get_properties, + nvertices, get_position, add_trg, NULL, &ctx)); CHK(add_geom_ctx.merge_cpt == 0); + OK(sg3_report_get_unique_vertices_count(report, &count)); + CHK(count == nvertices); + OK(sg3_report_get_unique_triangles_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_side_count(report, &count)); + CHK(count == 0); /* media where defined */ + OK(sg3_report_get_triangle_with_undefined_interface_count(report, &count)); + CHK(count == 0); /* interfaces where defined */ + OK(sg3_report_get_merge_conflict_count(report, &count)); + CHK(count == 1); /* Without merge_trg add stops at the first conflict */ + OK(sg3_report_get_properties_conflict_count(report, &count)); + CHK(count == 0); + + /* Incompatible interface */ + ctx.intface = intface1; /* Successful add geometry with merge callback */ add_geom_ctx.merge_res = RES_OK; - OK(sg3_geometry_add(geometry, ntriangles, get_indices, NULL, nvertices, - get_position, add_trg, merge_trg, &ctx)); + OK(sg3_geometry_add(geometry, ntriangles, get_indices, get_properties, + nvertices, get_position, add_trg, merge_trg, &ctx)); CHK(add_geom_ctx.merge_cpt == ntriangles); add_geom_ctx.merge_cpt = 0; - - - - - OK(sg3_report_validate_properties(report, validate, NULL)); - count = 1; + OK(sg3_report_get_unique_vertices_count(report, &count)); + CHK(count == nvertices); + OK(sg3_report_get_unique_triangles_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_triangle_with_undefined_side_count(report, &count)); + CHK(count == 0); /* media where defined */ + OK(sg3_report_get_triangle_with_undefined_interface_count(report, &count)); + CHK(count == 0); /* interfaces where defined */ OK(sg3_report_get_merge_conflict_count(report, &count)); + CHK(count == ntriangles); + OK(sg3_report_get_properties_conflict_count(report, &count)); CHK(count == 0); - count = 1; + + OK(sg3_report_validate_properties(report, validate, NULL)); OK(sg3_report_get_properties_conflict_count(report, &count)); CHK(count == 0); OK(sg3_report_dump_as_obj(report, stdout, SG3_ALL_TRIANGLES)); diff --git a/src/test_sg3_utils.h b/src/test_sg3_utils.h @@ -95,6 +95,7 @@ static const unsigned medium1_back0[12] = { 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1 } static const unsigned medium1_front0[12] = { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; static const unsigned intface0[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +static const unsigned intface1[12] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; static INLINE void get_indices(const unsigned itri, unsigned ids[3], void* context)