Skip to content

Commit

Permalink
extracts child's bbox by index
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Park authored and Mike Park committed Sep 9, 2022
1 parent f176661 commit 30a656c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/ref_oct.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,80 @@ REF_FCN REF_STATUS ref_oct_free(REF_OCT ref_oct) {
return REF_SUCCESS;
}

REF_FCN REF_STATUS ref_oct_child_bbox(REF_DBL *bbox, REF_INT child_index,
REF_DBL *box) {
switch (child_index) {
case 0:
box[0] = bbox[0];
box[1] = 0.5 * (bbox[0] + bbox[1]);
box[2] = bbox[2];
box[3] = 0.5 * (bbox[2] + bbox[3]);
box[4] = bbox[4];
box[5] = 0.5 * (bbox[4] + bbox[5]);
break;
case 1:
box[0] = 0.5 * (bbox[0] + bbox[1]);
box[1] = bbox[1];
box[2] = bbox[2];
box[3] = 0.5 * (bbox[2] + bbox[3]);
box[4] = bbox[4];
box[5] = 0.5 * (bbox[4] + bbox[5]);
break;
case 2:
box[0] = 0.5 * (bbox[0] + bbox[1]);
box[1] = bbox[1];
box[2] = 0.5 * (bbox[2] + bbox[3]);
box[3] = bbox[3];
box[4] = bbox[4];
box[5] = 0.5 * (bbox[4] + bbox[5]);
break;
case 3:
box[0] = bbox[0];
box[1] = 0.5 * (bbox[0] + bbox[1]);
box[2] = 0.5 * (bbox[2] + bbox[3]);
box[3] = bbox[3];
box[4] = bbox[4];
box[5] = 0.5 * (bbox[4] + bbox[5]);
break;
case 4:
box[0] = bbox[0];
box[1] = 0.5 * (bbox[0] + bbox[1]);
box[2] = bbox[2];
box[3] = 0.5 * (bbox[2] + bbox[3]);
box[4] = 0.5 * (bbox[4] + bbox[5]);
box[5] = bbox[5];
break;
case 5:
box[0] = 0.5 * (bbox[0] + bbox[1]);
box[1] = bbox[1];
box[2] = bbox[2];
box[3] = 0.5 * (bbox[2] + bbox[3]);
box[4] = 0.5 * (bbox[4] + bbox[5]);
box[5] = bbox[5];
break;
case 6:
box[0] = 0.5 * (bbox[0] + bbox[1]);
box[1] = bbox[1];
box[2] = 0.5 * (bbox[2] + bbox[3]);
box[3] = bbox[3];
box[4] = 0.5 * (bbox[4] + bbox[5]);
box[5] = bbox[5];
break;
case 7:
box[0] = bbox[0];
box[1] = 0.5 * (bbox[0] + bbox[1]);
box[2] = 0.5 * (bbox[2] + bbox[3]);
box[3] = bbox[3];
box[4] = 0.5 * (bbox[4] + bbox[5]);
box[5] = bbox[5];
break;
default:
THROW("not 2^3");
}

return REF_SUCCESS;
}

REF_FCN REF_STATUS ref_oct_split(REF_OCT ref_oct, REF_INT node) {
REF_INT i;
for (i = 0; i < 8; i++) {
Expand Down
3 changes: 3 additions & 0 deletions src/ref_oct.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ REF_FCN REF_STATUS ref_oct_create(REF_OCT *ref_oct);

REF_FCN REF_STATUS ref_oct_free(REF_OCT ref_oct);

REF_FCN REF_STATUS ref_oct_child_bbox(REF_DBL *parent_bbox, REF_INT child_index,
REF_DBL *child_bbox);

REF_FCN REF_STATUS ref_oct_split(REF_OCT ref_oct, REF_INT node);

REF_FCN REF_STATUS ref_oct_contains(REF_OCT ref_oct, REF_DBL *xyz,
Expand Down
14 changes: 14 additions & 0 deletions src/ref_oct_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ int main(int argc, char *argv[]) {
RSS(ref_oct_free(ref_oct), "free oct");
}

{ /* child's bbox */
REF_DBL parent_bbox[6], child_bbox[6];
REF_INT child_index = 0;
REF_DBL tol = -1.0;
parent_bbox[0] = 0.0;
parent_bbox[1] = 1.0;
parent_bbox[2] = 0.0;
parent_bbox[3] = 1.0;
parent_bbox[4] = 0.0;
parent_bbox[5] = 1.0;
RSS(ref_oct_child_bbox(parent_bbox, child_index, child_bbox), "bbox");
RWDS(0.0, child_bbox[0], tol, "not zero");
}

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

0 comments on commit 30a656c

Please sign in to comment.