[Bf-blender-cvs] [3529913] master: Math Lib: name signed versions of dist_to_plane_v3 explicitly

Campbell Barton noreply at git.blender.org
Wed Aug 13 06:36:46 CEST 2014


Commit: 3529913629c83c27627d93a186bd5e7638dd839a
Author: Campbell Barton
Date:   Wed Aug 13 14:34:58 2014 +1000
Branches: master
https://developer.blender.org/rB3529913629c83c27627d93a186bd5e7638dd839a

Math Lib: name signed versions of dist_to_plane_v3 explicitly

also add unsigned versions

===================================================================

M	source/blender/blenkernel/intern/camera.c
M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/editors/mesh/editmesh_knife.c
M	source/blender/modifiers/intern/MOD_screw.c
M	source/blender/python/mathutils/mathutils_geometry.c

===================================================================

diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 9d4908b..6ce3abe 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -473,7 +473,7 @@ static void camera_to_frame_view_cb(const float co[3], void *user_data)
 	unsigned int i;
 
 	for (i = 0; i < 4; i++) {
-		float nd = dist_squared_to_plane_v3(co, data->plane_tx[i]);
+		float nd = dist_signed_squared_to_plane_v3(co, data->plane_tx[i]);
 		if (nd < data->dist_vals_sq[i]) {
 			data->dist_vals_sq[i] = nd;
 		}
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 57cde56..9962529 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 54e3545..3d4cea7 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])
diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c
index b14c59f..962bbaf 100644
--- a/source/blender/editors/mesh/editmesh_knife.c
+++ b/source/blender/editors/mesh/editmesh_knife.c
@@ -1120,8 +1120,8 @@ static bool knife_ray_intersect_face(KnifeTool_OpData *kcd,
 			/* check if line coplanar with tri */
 			normal_tri_v3(tri_norm, lv1, lv2, lv3);
 			plane_from_point_normal_v3(tri_plane, lv1, tri_norm);
-			if ((fabsf(dist_squared_to_plane_v3(v1, tri_plane)) < KNIFE_FLT_EPS) &&
-			    (fabsf(dist_squared_to_plane_v3(v2, tri_plane)) < KNIFE_FLT_EPS))
+			if ((dist_squared_to_plane_v3(v1, tri_plane) < KNIFE_FLT_EPS) &&
+			    (dist_squared_to_plane_v3(v2, tri_plane) < KNIFE_FLT_EPS))
 			{
 				return false;
 			}
diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c
index ff7cc01..5900baa 100644
--- a/source/blender/modifiers/intern/MOD_screw.c
+++ b/source/blender/modifiers/intern/MOD_screw.c
@@ -362,7 +362,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 
 		if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) {
 			for (i = 0, mv_orig = mvert_orig; i < totvert; i++, mv_orig++) {
-				const float v = dist_squared_to_plane_v3(mv_orig->co, uv_axis_plane);
+				const float v = dist_signed_squared_to_plane_v3(mv_orig->co, uv_axis_plane);
 				uv_v_minmax[0] = min_ff(v, uv_v_minmax[0]);
 				uv_v_minmax[1] = max_ff(v, uv_v_minmax[1]);
 			}
@@ -897,8 +897,8 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 		}
 
 		if (has_mloop_orig == false && mloopuv_layers_tot) {
-			uv_v_offset_a = dist_to_plane_v3(mvert_new[medge_new[i].v1].co, uv_axis_plane);
-			uv_v_offset_b = dist_to_plane_v3(mvert_new[medge_new[i].v2].co, uv_axis_plane);
+			uv_v_offset_a = dist_signed_to_plane_v3(mvert_new[medge_new[i].v1].co, uv_axis_plane);
+			uv_v_offset_b = dist_signed_to_plane_v3(mvert_new[medge_new[i].v2].co, uv_axis_plane);
 
 			if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) {
 				uv_v_offset_a = (uv_v_offset_a - uv_v_minmax[0]) * uv_v_range_inv;
diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c
index 20d69ca..2e2e033 100644
--- a/source/blender/python/mathutils/mathutils_geometry.c
+++ b/source/blender/python/mathutils/mathutils_geometry.c
@@ -1082,7 +1082,7 @@ static PyObject *M_Geometry_distance_point_to_plane(PyObject *UNUSED(self), PyOb
 	}
 
 	plane_from_point_normal_v3(plane, plane_co->vec, plane_no->vec);
-	return PyFloat_FromDouble(dist_to_plane_v3(pt->vec, plane));
+	return PyFloat_FromDouble(dist_signed_to_plane_v3(pt->vec, plane));
 }
 
 PyDoc_STRVAR(M_Geometry_barycentric_transform_doc,




More information about the Bf-blender-cvs mailing list