commit 9b93c2dfcf42682c62a9412bb5f8fbd276448c5c
parent 6d7e6d2c55adabe41a923b181940492e103ee259
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 17 Dec 2019 10:57:32 +0100
Fix geometry properties validation
Diffstat:
3 files changed, 49 insertions(+), 32 deletions(-)
diff --git a/src/sg3.h b/src/sg3.h
@@ -166,6 +166,8 @@ sg3_geometry_add
/* User function that provides properties for added triangles */
void(*properties) /* Can be NULL <=> SG3_UNDEFINED_PROPERTY used */
(const unsigned itri,
+ /* It is OK to have side and interface properties sharing the same IDs,
+ * i.e. side and interface IDs both starting from 0 */
unsigned properties[SG3_PROP_TYPES_COUNT__],
void* context),
/* Number of added vertices */
diff --git a/src/sg3_geometry.c b/src/sg3_geometry.c
@@ -219,6 +219,26 @@ error:
goto exit;
}
+res_T
+geometry_enlarge_trg_descriptions
+ (struct sg3_geometry* geom,
+ const size_t sz)
+{
+ res_T res = RES_OK;
+ size_t old_sz =
+ darray_trg_descriptions_size_get(&geom->trg_descriptions);
+ if(sz <= old_sz) return RES_OK;
+ ASSERT(sz - old_sz < UINT_MAX);
+ ERR(darray_trg_descriptions_resize(&geom->trg_descriptions, sz));
+ geom->trg_with_undef_sides_count += (unsigned)(sz - old_sz);
+ geom->trg_with_undef_intface_count += (unsigned)(sz - old_sz);
+
+exit:
+ return res;
+error:
+ goto exit;
+}
+
static void
dump_partition
(const struct sg3_geometry* geom,
@@ -514,15 +534,25 @@ sg3_geometry_validate_properties
= darray_trg_descriptions_data_get(&geom->trg_descriptions);
geom->properties_conflict_count = 0; /* Reset count */
FOR_EACH(i, 0, sz) {
- unsigned props[3] = {
- SG3_UNDEFINED_PROPERTY, SG3_UNDEFINED_PROPERTY, SG3_UNDEFINED_PROPERTY };
+ unsigned p, j;
+ unsigned props[SG3_PROP_TYPES_COUNT__];
struct trg_descriptions* trgd = trg_descriptions + i;
/* Validate only triangle not flagged with merge_conflict */
if(trgd->merge_conflict) {
trgd->properties_conflict = 0;
continue;
}
- /* Get non-conflicting properties */
+ /* Get properties for non-conflict triangles */
+ FOR_EACH(p, 0, SG3_PROP_TYPES_COUNT__) {
+ const struct definition* defs = darray_definition_cdata_get(trgd->defs + p);
+ props[p] = SG3_UNDEFINED_PROPERTY;
+ FOR_EACH(j, 0, darray_definition_size_get(trgd->defs + p)) {
+ if(defs[j].property_value != SG3_UNDEFINED_PROPERTY) {
+ props[p] = defs[j].property_value;
+ break;
+ }
+ }
+ }
/* Call vaildation */
ERR(validate(i, props, ctx, &trgd->properties_conflict));
if(trgd->properties_conflict)
diff --git a/src/sg3_geometry.h b/src/sg3_geometry.h
@@ -109,8 +109,8 @@ struct definition {
static FINLINE void
init_definition
-(struct mem_allocator* alloc,
- struct definition* data)
+ (struct mem_allocator* alloc,
+ struct definition* data)
{
ASSERT(alloc && data);
data->property_value = SG3_UNDEFINED_PROPERTY;
@@ -119,8 +119,8 @@ init_definition
static INLINE res_T
copy_definition
-(struct definition* dst,
- const struct definition* src)
+ (struct definition* dst,
+ const struct definition* src)
{
res_T res = RES_OK;
ASSERT(dst && src);
@@ -134,7 +134,7 @@ error:
static FINLINE void
release_definition
-(struct definition* data)
+ (struct definition* data)
{
ASSERT(data);
darray_uint_release(&data->set_ids);
@@ -159,8 +159,8 @@ struct trg_descriptions {
static FINLINE void
init_trg_descriptions
-(struct mem_allocator* alloc,
- struct trg_descriptions* data)
+ (struct mem_allocator* alloc,
+ struct trg_descriptions* data)
{
int i;
ASSERT(alloc && data);
@@ -173,8 +173,8 @@ init_trg_descriptions
static INLINE res_T
copy_trg_descriptions
-(struct trg_descriptions* dst,
- const struct trg_descriptions* src)
+ (struct trg_descriptions* dst,
+ const struct trg_descriptions* src)
{
res_T res = RES_OK;
int i;
@@ -193,7 +193,7 @@ error:
static FINLINE void
release_trg_descriptions
-(struct trg_descriptions* data)
+ (struct trg_descriptions* data)
{
int i;
ASSERT(data);
@@ -213,8 +213,8 @@ release_trg_descriptions
******************************************************************************/
static FINLINE void
init_trg_intfaceid
-(struct mem_allocator* alloc,
- unsigned* data)
+ (struct mem_allocator* alloc,
+ unsigned* data)
{
ASSERT(data); (void)alloc;
*data = SG3_UNDEFINED_PROPERTY;
@@ -268,24 +268,9 @@ geometry_register_triangle
const int merge_conflict);
/* Add new undefined triangle descriptions to a geometry */
-static res_T
+extern res_T
geometry_enlarge_trg_descriptions
(struct sg3_geometry* geom,
- const size_t sz)
-{
- res_T res = RES_OK;
- size_t old_sz =
- darray_trg_descriptions_size_get(&geom->trg_descriptions);
- if(sz <= old_sz) return RES_OK;
- ASSERT(sz - old_sz < UINT_MAX);
- ERR(darray_trg_descriptions_resize(&geom->trg_descriptions, sz));
- geom->trg_with_undef_sides_count += (unsigned)(sz - old_sz);
- geom->trg_with_undef_intface_count += (unsigned)(sz - old_sz);
-
-exit:
- return res;
-error:
- goto exit;
-}
+ const size_t sz);
#endif /* SG3_GEOMETRY_H__ */