commit 09ec4ad14fbf5b839fc926861f1031d36f9c73fd
parent b65503263992200c9cee46cf2767b5c8dd4a7431
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Wed, 15 Jan 2025 16:30:57 +0100
Add the scad_geometry_get_bounding_box API call
Diffstat:
2 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/src/scad.h b/src/scad.h
@@ -260,6 +260,13 @@ scad_geometry_get_closest_point
double* closest,
double* closest_distance);
+/* Get the Boundig Box of geometry `geom' */
+SCAD_API res_T
+scad_geometry_get_bounding_box
+ (struct scad_geometry* geom,
+ double min[3],
+ double max[3]);
+
/* Add a rectangle to the scene, defined by a point `xyz' and
* `dxdy' the extents along the x-, y-axes. */
SCAD_API res_T
diff --git a/src/scad_geometry.c b/src/scad_geometry.c
@@ -816,6 +816,44 @@ error:
}
res_T
+scad_geometry_get_bounding_box
+ (struct scad_geometry* geom,
+ double min[3],
+ double max[3])
+{
+ res_T res = RES_OK;
+ size_t n = 0;
+ double mi[3], ma[3];
+
+ if(!geom || !min || !max) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ ERR(check_device(FUNC_NAME));
+
+ d3_splat(mi, DBL_MAX);
+ d3_splat(ma, -DBL_MAX);
+ for(n = 0; n < geom->gmsh_dimTags_n; n += 2) {
+ double i[3], a[3];
+ int ierr = 0;
+ int dim = geom->gmsh_dimTags[n];
+ int tag = geom->gmsh_dimTags[n + 1];
+ gmshModelOccGetBoundingBox(dim, tag, i, i+1, i+2, a, a+1, a+2, &ierr);
+ ERR(gmsh_err_to_res_T(ierr));
+ d3_min(mi, mi, i);
+ d3_max(ma, ma, a);
+ }
+ d3_set(min, mi);
+ d3_set(max, ma);
+
+exit:
+ return res;
+error:
+ goto exit;
+}
+
+res_T
scad_add_rectangle
(const char* name,
const double xyz[3],