Skip to content

Commit

Permalink
scales bbox
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 7a0eb8d commit 8c2230e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ref_oct.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,17 @@ REF_FCN REF_STATUS ref_oct_bbox_overlap(REF_DBL *bbox0, REF_DBL *bbox1,
return REF_SUCCESS;
}

REF_FCN REF_STATUS ref_oct_bbox_scale(REF_DBL *bbox0, REF_DBL factor,
REF_DBL *bbox1) {
bbox1[0] = bbox0[0] - 0.5 * (factor - 1.0) * (bbox0[1] - bbox0[0]);
bbox1[1] = bbox0[1] + 0.5 * (factor - 1.0) * (bbox0[1] - bbox0[0]);
bbox1[2] = bbox0[2] - 0.5 * (factor - 1.0) * (bbox0[3] - bbox0[2]);
bbox1[3] = bbox0[3] + 0.5 * (factor - 1.0) * (bbox0[3] - bbox0[2]);
bbox1[4] = bbox0[4] - 0.5 * (factor - 1.0) * (bbox0[5] - bbox0[4]);
bbox1[5] = bbox0[5] + 0.5 * (factor - 1.0) * (bbox0[5] - bbox0[4]);
return REF_SUCCESS;
}

REF_FCN REF_STATUS ref_oct_tec(REF_OCT ref_oct, const char *filename) {
FILE *f;
REF_INT i;
Expand Down
2 changes: 2 additions & 0 deletions src/ref_oct.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ REF_FCN REF_STATUS ref_oct_contains(REF_OCT ref_oct, REF_DBL *xyz,

REF_FCN REF_STATUS ref_oct_bbox_overlap(REF_DBL *bbox0, REF_DBL *bbox1,
REF_BOOL *overlap);
REF_FCN REF_STATUS ref_oct_bbox_scale(REF_DBL *bbox0, REF_DBL factor,
REF_DBL *bbox1);

REF_FCN REF_STATUS ref_oct_tec(REF_OCT ref_oct, const char *filename);

Expand Down
20 changes: 20 additions & 0 deletions src/ref_oct_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,26 @@ int main(int argc, char *argv[]) {
REIS(REF_FALSE, overlap, "did expect overlap");
}

{
REF_DBL bbox0[6], bbox1[6];
REF_DBL factor;
REF_DBL tol = -1.0;
bbox0[0] = 0.0;
bbox0[1] = 1.0;
bbox0[2] = 0.0;
bbox0[3] = 2.0;
bbox0[4] = 0.0;
bbox0[5] = 4.0;
factor = 1.1;
RSS(ref_oct_bbox_scale(bbox0, factor, bbox1), "scale");
RWDS(-0.05, bbox1[0], tol, "xmin");
RWDS(1.05, bbox1[1], tol, "xmax");
RWDS(-0.1, bbox1[2], tol, "ymin");
RWDS(2.1, bbox1[3], tol, "ymax");
RWDS(-0.2, bbox1[4], tol, "zmin");
RWDS(4.2, bbox1[5], tol, "zmax");
}

RSS(ref_mpi_free(ref_mpi), "mpi free");
RSS(ref_mpi_stop(), "stop");
return 0;
Expand Down

0 comments on commit 8c2230e

Please sign in to comment.