commit 0c1a7f6f42f7d8c86d15aad78e672e1d0ca21a7e
parent ca3479e3071c3e519bf13dcc3fb5e9300e14ab01
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 5 Mar 2026 10:45:51 +0100
Add the member variable depth to the tree descriptor
Diffstat:
3 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/src/sln.h b/src/sln.h
@@ -157,11 +157,12 @@ struct sln_tree_desc {
enum sln_mesh_type mesh_type;
enum sln_line_profile line_profile;
+ unsigned depth;
size_t nvertices;
size_t nnodes;
};
#define SLN_TREE_DESC_NULL__ { \
- 0, 0, SLN_MESH_TYPES_COUNT__, SLN_LINE_PROFILES_COUNT__, 0, 0 \
+ 0, 0, SLN_MESH_TYPES_COUNT__, SLN_LINE_PROFILES_COUNT__, 0, 0, 0 \
}
static const struct sln_tree_desc SLN_TREE_DESC_NULL = SLN_TREE_DESC_NULL__;
diff --git a/src/sln_tree.c b/src/sln_tree.c
@@ -507,13 +507,37 @@ sln_tree_ref_put(struct sln_tree* tree)
res_T
sln_tree_get_desc(const struct sln_tree* tree, struct sln_tree_desc* desc)
{
+ size_t nlines = 0;
+ size_t nlines_adjusted = 0;
+ unsigned depth = 0;
+
if(!tree || !desc) return RES_BAD_ARG;
+
desc->max_nlines_per_leaf = 1;
desc->mesh_decimation_err = tree->args.mesh_decimation_err;
desc->mesh_type = tree->args.mesh_type;
desc->line_profile = tree->args.line_profile;
desc->nnodes = darray_node_size_get(&tree->nodes);
desc->nvertices = darray_vertex_size_get(&tree->vertices);
+
+ SHTR(line_list_get_size(tree->args.lines, &nlines));
+ nlines_adjusted = round_up_pow2(nlines);
+
+ for(depth=0; depth<64 && !(BIT_U64(depth) & nlines_adjusted); ++depth);
+ desc->depth = depth;
+
+#ifndef NDEBUG
+ {
+ unsigned max_depth = 0;
+ const struct sln_node* node = sln_tree_get_root(tree);
+ while(!sln_node_is_leaf(node)) {
+ node = sln_node_get_child(node, 0);
+ ++max_depth;
+ }
+ CHK(max_depth == depth);
+ }
+#endif
+
return RES_OK;
}
diff --git a/src/test_sln_tree.c b/src/test_sln_tree.c
@@ -157,6 +157,7 @@ test_tree
const struct sln_node* node = NULL;
struct shtr_line line = SHTR_LINE_NULL;
size_t nlines = 0;
+ unsigned depth = 0;
CHK(sln && tree_args_in && line_list);
tree_args = *tree_args_in;
@@ -179,10 +180,14 @@ test_tree
CHK(desc.nvertices >= 1);
CHK(desc.nnodes >= 1);
+ depth = 0;
CHK(node = sln_tree_get_root(tree));
while(!sln_node_is_leaf(node)) {
node = sln_node_get_child(node, 0);
+ ++depth;
}
+ CHK(desc.depth == depth);
+
CHK(sln_node_get_lines_count(node) <= desc.max_nlines_per_leaf);
CHK(sln_node_get_line(NULL, node, 0, &line) == RES_BAD_ARG);
CHK(sln_node_get_line(tree, NULL, 0, &line) == RES_BAD_ARG);