From 3529913629c83c27627d93a186bd5e7638dd839a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 13 Aug 2014 14:34:58 +1000 Subject: Math Lib: name signed versions of dist_to_plane_v3 explicitly also add unsigned versions --- source/blender/blenlib/BLI_math_geom.h | 7 +++++-- source/blender/blenlib/intern/math_geom.c | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 57cde5637d3..9962529e095 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -86,8 +86,11 @@ float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float dist_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2]); void closest_to_line_segment_v2(float r_close[2], const float p[2], const float l1[2], const float l2[2]); -float dist_squared_to_plane_v3(const float p[3], const float plane[4]); -float dist_to_plane_v3(const float p[3], const float plane[4]); +float dist_signed_squared_to_plane_v3(const float p[3], const float plane[4]); +float dist_squared_to_plane_v3(const float p[3], const float plane[4]); +float dist_signed_to_plane_v3(const float p[3], const float plane[4]); +float dist_to_plane_v3(const float p[3], const float plane[4]); + float dist_squared_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]); float dist_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]); float dist_squared_to_line_v3(const float p[3], const float l1[3], const float l2[3]); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 54e3545a3f1..3d4cea70551 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -376,24 +376,36 @@ void closest_to_plane_v3(float r_close[3], const float plane[4], const float pt[ madd_v3_v3v3fl(r_close, pt, plane, -side / len_sq); } -float dist_squared_to_plane_v3(const float pt[3], const float plane[4]) +float dist_signed_squared_to_plane_v3(const float pt[3], const float plane[4]) { const float len_sq = len_squared_v3(plane); const float side = plane_point_side_v3(plane, pt); const float fac = side / len_sq; return copysignf(len_sq * (fac * fac), side); } +float dist_squared_to_plane_v3(const float pt[3], const float plane[4]) +{ + const float len_sq = len_squared_v3(plane); + const float side = plane_point_side_v3(plane, pt); + const float fac = side / len_sq; + /* only difference to code above - no 'copysignf' */ + return len_sq * (fac * fac); +} /** * Return the signed distance from the point to the plane. */ -float dist_to_plane_v3(const float pt[3], const float plane[4]) +float dist_signed_to_plane_v3(const float pt[3], const float plane[4]) { const float len_sq = len_squared_v3(plane); const float side = plane_point_side_v3(plane, pt); const float fac = side / len_sq; return sqrtf(len_sq) * fac; } +float dist_to_plane_v3(const float pt[3], const float plane[4]) +{ + return fabsf(dist_signed_to_plane_v3(pt, plane)); +} /* distance v1 to line-piece l1-l2 in 3D */ float dist_squared_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]) -- cgit v1.2.3