From a51a0ca772b21814e29bdb3b2b5fd854e29c5334 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 19 Apr 2014 22:12:50 +1000 Subject: Math Lib: add shell_v3v3_normalized_to_dist and v2 version bypass angle calculation to avoids (asin, sqrt, cos). --- source/blender/blenlib/BLI_math_base.h | 2 -- source/blender/blenlib/BLI_math_geom.h | 4 +++ source/blender/blenlib/intern/math_base_inline.c | 12 --------- source/blender/blenlib/intern/math_geom_inline.c | 34 ++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 14 deletions(-) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index 68ffb4b4893..5bd8490db6e 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -241,8 +241,6 @@ MINLINE int mod_i(int i, int n); MINLINE unsigned int highest_order_bit_i(unsigned int n); MINLINE unsigned short highest_order_bit_s(unsigned short n); -MINLINE float shell_angle_to_dist(const float angle); - #if defined(_MSC_VER) && (_MSC_VER < 1800) extern double copysign(double x, double y); extern double round(double x); diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 6ba8910db14..5067cee7352 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -314,6 +314,10 @@ MINLINE int min_axis_v3(const float vec[3]); MINLINE int poly_to_tri_count(const int poly_count, const int corner_count); +MINLINE float shell_angle_to_dist(const float angle); +MINLINE float shell_v3v3_normalized_to_dist(const float a[3], const float b[3]); +MINLINE float shell_v2v2_normalized_to_dist(const float a[2], const float b[2]); + /**************************** Inline Definitions ******************************/ #if BLI_MATH_DO_INLINE diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 82c6e68ccc2..e6217329145 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -44,9 +44,6 @@ # define UNLIKELY(x) (x) #endif -/* A few small defines. Keep'em local! */ -#define SMALL_NUMBER 1.e-8f - MINLINE float sqrt3f(float f) { if (UNLIKELY(f == 0.0f)) return 0.0f; @@ -111,15 +108,6 @@ MINLINE float interpf(float target, float origin, float fac) return (fac * target) + (1.0f - fac) * origin; } -/* useful to calculate an even width shell, by taking the angle between 2 planes. - * The return value is a scale on the offset. - * no angle between planes is 1.0, as the angle between the 2 planes approaches 180d - * the distance gets very high, 180d would be inf, but this case isn't valid */ -MINLINE float shell_angle_to_dist(const float angle) -{ - return (UNLIKELY(angle < SMALL_NUMBER)) ? 1.0f : fabsf(1.0f / cosf(angle)); -} - /* used for zoom values*/ MINLINE float power_of_2(float val) { diff --git a/source/blender/blenlib/intern/math_geom_inline.c b/source/blender/blenlib/intern/math_geom_inline.c index 0e243c5e198..1e54dd11a76 100644 --- a/source/blender/blenlib/intern/math_geom_inline.c +++ b/source/blender/blenlib/intern/math_geom_inline.c @@ -34,6 +34,9 @@ #include +/* A few small defines. Keep'em local! */ +#define SMALL_NUMBER 1.e-8f + /********************************** Polygons *********************************/ MINLINE float cross_tri_v2(const float v1[2], const float v2[2], const float v3[2]) @@ -227,4 +230,35 @@ MINLINE float plane_point_side_v3(const float plane[4], const float co[3]) return dot_v3v3(co, plane) + plane[3]; } +/* useful to calculate an even width shell, by taking the angle between 2 planes. + * The return value is a scale on the offset. + * no angle between planes is 1.0, as the angle between the 2 planes approaches 180d + * the distance gets very high, 180d would be inf, but this case isn't valid */ +MINLINE float shell_angle_to_dist(const float angle) +{ + return (UNLIKELY(angle < SMALL_NUMBER)) ? 1.0f : fabsf(1.0f / cosf(angle)); +} +/** + * equivalent to ``shell_angle_to_dist(angle_normalized_v3v3(a, b))`` + */ +MINLINE float shell_v3v3_normalized_to_dist(const float a[3], const float b[3]) +{ + const float angle_cos = fabsf(dot_v3v3(a, b)); + BLI_ASSERT_UNIT_V3(a); + BLI_ASSERT_UNIT_V3(b); + return (UNLIKELY(angle_cos < SMALL_NUMBER)) ? 1.0f : (1.0f / angle_cos); +} +/** + * equivalent to ``shell_angle_to_dist(angle_normalized_v2v2(a, b))`` + */ +MINLINE float shell_v2v2_normalized_to_dist(const float a[2], const float b[2]) +{ + const float angle_cos = fabsf(dot_v2v2(a, b)); + BLI_ASSERT_UNIT_V2(a); + BLI_ASSERT_UNIT_V2(b); + return (UNLIKELY(angle_cos < SMALL_NUMBER)) ? 1.0f : (1.0f / angle_cos); +} + +#undef SMALL_NUMBER + #endif /* __MATH_GEOM_INLINE_C__ */ -- cgit v1.2.3