commit c0e36df38179eae9dedecfa1272e5b7225c528eb
parent a3a20d5ec56d8fd6bb490ba4d06bdce9eb6bc2e9
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 3 Jul 2020 16:06:59 +0200
Fix misleading comments and small changes to the code
The modified code, that is supposed to give the same results, is more readable.
Diffstat:
1 file changed, 23 insertions(+), 17 deletions(-)
diff --git a/src/senc2d_scene_analyze.c b/src/senc2d_scene_analyze.c
@@ -209,9 +209,9 @@ extract_connex_components
/* Any not-already-used side is used as a starting point */
side_id_t first_side_not_in_component = media_use->first;
double max_ny;
- side_id_t max_ny_side_id = SIDE_NULL__;
+ side_id_t max_ny_side_id;
const side_id_t last_side = media_use->last;
- int component_canceled = 0;
+ int component_canceled = 0, max_y_is_2sided = 0;
res_T tmp_res = RES_OK;
ATOMIC id;
@@ -405,8 +405,12 @@ extract_connex_components
cmp[sid] = cc->cc_id;
}
- /* Compute the normal at the max_y vertex. */
+ /* Determine if this component can be an inner part inside another
+ * component (substracting a volume) as only these components will need
+ * to search for their possible outer component when grouping
+ * components to create enclosures */
max_ny = 0;
+ max_ny_side_id = SIDE_NULL__;
sz = darray_side_id_size_get(&ids_of_sides_around_max_y_vertex);
ASSERT(sz > 0);
FOR_EACH(ii, 0, sz) {
@@ -421,13 +425,7 @@ extract_connex_components
darray_position_cdata_get(&scn->vertices);
double edge[2], normal[2], norm;
- /* To ensure that segments with 2 sides in the component total to 0
- * regardless of numeric accuracy, we need to prevent them to
- * contribute (remember than x + y - y == x can be false). */
ASSERT(seg_comp->component[s] == cc->cc_id); (void)s;
- if(seg_comp->component[SENC2D_FRONT] == seg_comp->component[SENC2D_BACK])
- continue;
-
d2_sub(edge, vertices[seg_in->vertice_id[1]].vec,
vertices[seg_in->vertice_id[0]].vec);
d2(normal, -edge[1], +edge[0]);
@@ -437,10 +435,17 @@ extract_connex_components
if(fabs(max_ny) < fabs(normal[1])) {
max_ny_side_id = side_id;
max_ny = normal[1];
+ max_y_is_2sided = (seg_comp->component[SENC2D_FRONT]
+ == seg_comp->component[SENC2D_BACK]);
}
}
- if(max_ny == 0) cc->is_outer_border = 0;
+ /* The inner/outer property comes from the normal orientation of the
+ * segment on top of the component, this segment being the one whose
+ * |Ny| is maximal. If this segment has its 2 sides in the component,
+ * the component is inner */
+ if(max_ny == 0 || max_y_is_2sided) cc->is_outer_border = 0;
else {
+ ASSERT(max_ny_side_id != SIDE_NULL__);
if(SEGSIDE_IS_FRONT(max_ny_side_id)
== ((scn->convention & SENC2D_CONVENTION_NORMAL_FRONT) != 0)) {
/* Geom normal points towards the component */
@@ -591,7 +596,7 @@ group_connex_components
max_vrtx = positions[cc->max_y_vrtx_id].vec;
if(cc->is_outer_border) {
ATOMIC id;
- /* Don't need to cast a ray */
+ /* No need to cast a ray */
cc->cc_group_root = cc->cc_id; /* New group with self as root */
id = ATOMIC_INCR(next_enclosure_id) - 1;
ASSERT(id <= ENCLOSURE_MAX__);
@@ -945,6 +950,7 @@ build_result
const struct segment_comp* segments_comp;
struct htable_vrtx_id vtable;
int output_normal_in, normals_front, normals_back;
+ size_t cc_count;
int64_t sg;
int64_t ee;
@@ -957,8 +963,8 @@ build_result
ASSERT(normals_back != normals_front);
ASSERT(output_normal_in
!= ((scn->convention & SENC2D_CONVENTION_NORMAL_OUTSIDE) != 0));
- ASSERT(darray_ptr_component_descriptor_size_get(connex_components)
- <= COMPONENT_MAX__);
+ cc_count = darray_ptr_component_descriptor_size_get(connex_components);
+ ASSERT(cc_count <= COMPONENT_MAX__);
cc_descriptors = darray_ptr_component_descriptor_cdata_get(connex_components);
enclosures = darray_enclosure_data_get(&scn->analyze.enclosures);
segments_in = darray_segment_in_cdata_get(&scn->segments_in);
@@ -987,9 +993,10 @@ build_result
ordered_ids[rank] = e;
}
/* Rewrite cc_descriptors */
- FOR_EACH(d, 0, darray_ptr_component_descriptor_size_get(connex_components))
+ FOR_EACH(d, 0, cc_count) {
cc_descriptors[d]->enclosure_id =
- ordered_ids[cc_descriptors[d]->enclosure_id];
+ ordered_ids[cc_descriptors[d]->enclosure_id];
+ }
single_err: (void)0;
}/* Implicit barrier here. */
if(*res != RES_OK) goto exit;
@@ -1026,8 +1033,7 @@ build_result
seg_id_t s;
medium_id_t m;
res_T tmp_res = RES_OK;
- ASSERT(enc->first_component
- < darray_ptr_component_descriptor_size_get(connex_components));
+ ASSERT(enc->first_component < cc_count);
ASSERT(cc_descriptors[enc->first_component]->cc_id
== enc->first_component);