commit c5b3eb65d9d62b4f2b4da0ca75e7c06958b466b9
parent 9e449d549dc533e3b3c98750aa63be174fbc39c7
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 22 Apr 2021 11:53:11 +0200
Add the htrdr_geometry_get_epsilon function
Return a pre-computed empirical value relative to the extent of the
geometry that represents the threshold below which a numerical problem
could occur.
Diffstat:
2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/src/core/htrdr_geometry.c b/src/core/htrdr_geometry.c
@@ -75,6 +75,10 @@ struct htrdr_geometry {
float upper[3]; /* Ground upper bound */
int repeat; /* Make the geom infinite in X and Y */
+ /* A empirical value relative to the extent of the geometry that represents
+ * the threshold below which a numerical problem could occur. */
+ float epsilon;
+
struct htable_interface interfaces; /* Map a Star3D shape to its interface */
struct htrdr* htrdr;
@@ -581,6 +585,10 @@ htrdr_geometry_create
{
char buf[128];
struct htrdr_geometry* geom = NULL;
+ double low[3];
+ double upp[3];
+ double tmp[3];
+ double extent;
struct time t0, t1;
res_T res = RES_OK;
ASSERT(htrdr && obj_filename && mats && out_ground);
@@ -608,6 +616,10 @@ htrdr_geometry_create
time_dump(&t0, TIME_ALL, NULL, buf, sizeof(buf));
htrdr_log(geom->htrdr, "Setup geom in %s\n", buf);
+ htrdr_geometry_get_aabb(geom, low, upp);
+ extent = d3_len(d3_sub(tmp, upp, low));
+ geom->epsilon = MMAX((float)(extent * 1e-6), FLT_EPSILON);
+
exit:
*out_ground = geom;
return res;
@@ -738,3 +750,10 @@ htrdr_geometry_get_aabb
d3_set_f3(lower, geom->lower);
d3_set_f3(upper, geom->upper);
}
+
+double
+htrdr_geometry_get_epsilon(const struct htrdr_geometry* geom)
+{
+ ASSERT(geom);
+ return geom->epsilon;
+}
diff --git a/src/core/htrdr_geometry.h b/src/core/htrdr_geometry.h
@@ -98,6 +98,12 @@ htrdr_geometry_get_aabb
double lower[3],
double upper[3]);
+/* Empirical value relative to the extent of the geometry that represents the
+ * threshold below which a numerical problem could occur. */
+HTRDR_CORE_API double
+htrdr_geometry_get_epsilon
+ (const struct htrdr_geometry* geom);
+
END_DECLS
#endif /* HTRDR_GEOMETRY_H */