Skip to content

Commit

Permalink
adds fixture and ref_oct_gradation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Park authored and Mike Park committed Sep 27, 2022
1 parent 8c2230e commit 427008a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/ref_oct.c
Expand Up @@ -193,6 +193,40 @@ REF_FCN REF_STATUS ref_oct_split_touching(REF_OCT ref_oct, REF_DBL *bbox,
return REF_SUCCESS;
}

REF_FCN static REF_STATUS ref_oct_gradation_node(REF_OCT ref_oct, REF_INT node,
REF_DBL *bbox) {
if (ref_oct->children[8 * node] == REF_EMPTY) {
REF_DBL tool[6], factor = 1.1, diag, h;
RSS(ref_oct_bbox_scale(bbox, factor, tool), "scale");
RSS(ref_oct_bbox_diag(bbox, &diag), "scale");
h = factor * diag;
RSS(ref_oct_split_touching(ref_oct, tool, h), "split region");
} else {
REF_INT child_index;
for (child_index = 0; child_index < 8; child_index++) {
REF_DBL box[6];
RSS(ref_oct_child_bbox(bbox, child_index, box), "bbox");
RSS(ref_oct_gradation_node(
ref_oct, ref_oct->children[child_index + 8 * node], box),
"recurse");
}
}
return REF_SUCCESS;
}

REF_FCN REF_STATUS ref_oct_gradation(REF_OCT ref_oct) {
REF_INT n, last_n;
last_n = REF_EMPTY;
n = ref_oct_n(ref_oct);
while (n != last_n) {
printf("ncell %d\n", n);
RSS(ref_oct_gradation_node(ref_oct, 0, ref_oct->bbox), "descend");
last_n = n;
n = ref_oct_n(ref_oct);
}
return REF_SUCCESS;
}

REF_FCN static REF_STATUS ref_oct_contains_node(REF_OCT ref_oct, REF_DBL *xyz,
REF_DBL *bbox, REF_INT current,
REF_INT *node,
Expand Down
1 change: 1 addition & 0 deletions src/ref_oct.h
Expand Up @@ -48,6 +48,7 @@ REF_FCN REF_STATUS ref_oct_split(REF_OCT ref_oct, REF_INT node);
REF_FCN REF_STATUS ref_oct_split_at(REF_OCT ref_oct, REF_DBL *xyz, REF_DBL h);
REF_FCN REF_STATUS ref_oct_split_touching(REF_OCT ref_oct, REF_DBL *bbox,
REF_DBL h);
REF_FCN REF_STATUS ref_oct_gradation(REF_OCT ref_oct);

REF_FCN REF_STATUS ref_oct_contains(REF_OCT ref_oct, REF_DBL *xyz,
REF_INT *node, REF_DBL *bbox);
Expand Down
10 changes: 10 additions & 0 deletions src/ref_oct_test.c
Expand Up @@ -177,6 +177,16 @@ int main(int argc, char *argv[]) {
RSS(ref_oct_free(ref_oct), "free oct");
}

{
REF_OCT ref_oct;
RSS(ref_oct_create(&ref_oct), "make oct");
RSS(ref_oct_split(ref_oct, 0), "split root");
RSS(ref_oct_split(ref_oct, 1), "split first child");
RSS(ref_oct_split(ref_oct, 14), "split second gen");
RSS(ref_oct_gradation(ref_oct), "gradation");
RSS(ref_oct_free(ref_oct), "free oct");
}

{ /* contains root */
REF_OCT ref_oct;
REF_DBL xyz[] = {0.1, 0.1, 0.1};
Expand Down

0 comments on commit 427008a

Please sign in to comment.