[Bf-blender-cvs] [1389606] master: Math library: minor additions sqrtf_signed and copy_v2_fl2

Campbell Barton noreply at git.blender.org
Tue Nov 26 10:54:20 CET 2013


Commit: 13896063bccdf97f790db5a4048514a3bf0bf0b4
Author: Campbell Barton
Date:   Tue Nov 26 20:53:26 2013 +1100
http://developer.blender.org/rB13896063bccdf97f790db5a4048514a3bf0bf0b4

Math library: minor additions sqrtf_signed and copy_v2_fl2

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

M	source/blender/blenkernel/intern/camera.c
M	source/blender/blenlib/BLI_math_base.h
M	source/blender/blenlib/BLI_math_vector.h
M	source/blender/blenlib/intern/math_base_inline.c
M	source/blender/blenlib/intern/math_vector_inline.c

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

diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 536ec95..ab952fb 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -535,16 +535,11 @@ int BKE_camera_view_frame_fit_to_scene(Scene *scene, struct View3D *v3d, Object
 
 		float plane_isect_pt_1[3], plane_isect_pt_2[3];
 
-		/* could make a generic macro */
-#define SQRT_SIGNED(f) copysign(sqrtf(fabsf(f)), f)
-
 		/* apply the dist-from-plane's to the transformed plane points */
 		for (i = 0; i < 4; i++) {
-			mul_v3_v3fl(plane_tx[i], data_cb.normal_tx[i], SQRT_SIGNED(data_cb.dist_vals_sq[i]));
+			mul_v3_v3fl(plane_tx[i], data_cb.normal_tx[i], sqrtf_signed(data_cb.dist_vals_sq[i]));
 		}
 
-#undef SQRT_SIGNED
-
 		isect_plane_plane_v3(plane_isect_1, plane_isect_1_no,
 		                     plane_tx[0], data_cb.normal_tx[0],
 		                     plane_tx[2], data_cb.normal_tx[2]);
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index 1cb28d2..f7e6dc1 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -197,6 +197,8 @@ static const int NAN_INT = 0x7FC00000;
 MINLINE float sqrt3f(float f);
 MINLINE double sqrt3d(double d);
 
+MINLINE float sqrtf_signed(float f);
+
 MINLINE float saacosf(float f);
 MINLINE float saasinf(float f);
 MINLINE float sasqrtf(float f);
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 3ff81e4..1444517 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -83,6 +83,7 @@ MINLINE void copy_v2db_v2fl(double r[2], const float a[2]);
 MINLINE void copy_v3db_v3fl(double r[3], const float a[3]);
 MINLINE void copy_v4db_v4fl(double r[4], const float a[4]);
 /* float args -> vec */
+MINLINE void copy_v2_fl2(float v[2], float x, float y);
 MINLINE void copy_v3_fl3(float v[3], float x, float y, float z);
 MINLINE void copy_v4_fl4(float v[4], float x, float y, float z, float w);
 
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index e6509db..c68ca3e 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -61,6 +61,11 @@ MINLINE double sqrt3d(double d)
 	else                         return  exp(log( d) / 3.0);
 }
 
+MINLINE float sqrtf_signed(float f)
+{
+	return (f >= 0.0f) ? sqrtf(f) : -sqrtf(-f);
+}
+
 MINLINE float saacos(float fac)
 {
 	if      (UNLIKELY(fac <= -1.0f)) return (float)M_PI;
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index ace8e6b..cdbbcc5 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -236,6 +236,12 @@ MINLINE void swap_v4_v4(float a[4], float b[4])
 }
 
 /* float args -> vec */
+MINLINE void copy_v2_fl2(float v[2], float x, float y)
+{
+	v[0] = x;
+	v[1] = y;
+}
+
 MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
 {
 	v[0] = x;




More information about the Bf-blender-cvs mailing list