[Bf-blender-cvs] [8cd9d78] master: Replace sqrt with hypot for wipe-effect & transform code

Campbell Barton noreply at git.blender.org
Sat Jun 14 10:44:56 CEST 2014


Commit: 8cd9d784c7e4785d38b336bc852ffb8be3fde867
Author: Campbell Barton
Date:   Sat Jun 14 17:27:50 2014 +1000
https://developer.blender.org/rB8cd9d784c7e4785d38b336bc852ffb8be3fde867

Replace sqrt with hypot for wipe-effect & transform code

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

M	source/blender/blenkernel/intern/seqeffects.c
M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform_input.c

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

diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c
index 7ed9af8..2b14b92 100644
--- a/source/blender/blenkernel/intern/seqeffects.c
+++ b/source/blender/blenkernel/intern/seqeffects.c
@@ -1398,7 +1398,7 @@ static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float f
 			x = x - halfx;
 			y = y - halfy;
 
-			temp2 = asin(abs(y) / sqrt(x * x + y * y));
+			temp2 = asin(abs(y) / hypot(x, y));
 			if (x <= 0 && y >= 0) temp2 = (float)M_PI - temp2;
 			else if (x <= 0 && y <= 0) temp2 += (float)M_PI;
 			else if (x >= 0 && y <= 0) temp2 = 2.0f * (float)M_PI - temp2;
@@ -1441,7 +1441,7 @@ static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float f
 
 			temp1 = xo * (1 - facf0 / 2) - xo * facf0 / 2;
 			temp2 = yo * (1 - facf0 / 2) - yo * facf0 / 2;
-			pointdist = sqrtf(temp1 * temp1 + temp2 * temp2);
+			pointdist = hypot(temp1, temp2);
 
 			if (b2 < b1 && b2 < b3) {
 				if (hwidth < pointdist)
@@ -1498,9 +1498,9 @@ static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float f
 			hwidth = width * 0.5f;
 
 			temp1 = (halfx - (halfx) * facf0);
-			pointdist = sqrtf(temp1 * temp1 + temp1 * temp1);
+			pointdist = hypotf(temp1, temp1);
 
-			temp2 = sqrtf((halfx - x) * (halfx - x) + (halfy - y) * (halfy - y));
+			temp2 = hypotf(halfx - x, halfy - y);
 			if (temp2 > pointdist) output = in_band(hwidth, fabsf(temp2 - pointdist), 0, 1);
 			else output = in_band(hwidth, fabsf(temp2 - pointdist), 1, 1);
 
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 899f119..ab0bc06 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -1718,7 +1718,7 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
 			{
 				float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
 				float angle = atan2f(dy, dx);
-				float dist = sqrtf(dx * dx + dy * dy);
+				float dist = hypotf(dx, dy);
 				float delta_angle = min_ff(15.0f / dist, (float)M_PI / 4.0f);
 				float spacing_angle = min_ff(5.0f / dist, (float)M_PI / 12.0f);
 				UI_ThemeColor(TH_VIEW_OVERLAY);
diff --git a/source/blender/editors/transform/transform_input.c b/source/blender/editors/transform/transform_input.c
index 6546a05..61b2dea 100644
--- a/source/blender/editors/transform/transform_input.c
+++ b/source/blender/editors/transform/transform_input.c
@@ -64,18 +64,18 @@ static void InputSpring(TransInfo *UNUSED(t), MouseInput *mi, const int mval[2],
 		/* calculate ratio for shiftkey pos, and for total, and blend these for precision */
 		dx = (float)(mi->center[0] - mi->precision_mval[0]);
 		dy = (float)(mi->center[1] - mi->precision_mval[1]);
-		ratio = sqrtf(dx * dx + dy * dy);
+		ratio = hypotf(dx, dy);
 
 		dx = (float)(mi->center[0] - mval[0]);
 		dy = (float)(mi->center[1] - mval[1]);
-		precise_ratio = sqrtf(dx * dx + dy * dy);
+		precise_ratio = hypotf(dx, dy);
 
 		ratio = (ratio + (precise_ratio - ratio) / 10.0f) / mi->factor;
 	}
 	else {
 		dx = (float)(mi->center[0] - mval[0]);
 		dy = (float)(mi->center[1] - mval[1]);
-		ratio = sqrtf(dx * dx + dy * dy) / mi->factor;
+		ratio = hypotf(dx, dy) / mi->factor;
 	}
 
 	output[0] = ratio;
@@ -195,7 +195,7 @@ static void InputCustomRatioFlip(TransInfo *UNUSED(t), MouseInput *mi, const int
 		dx = data[2] - data[0];
 		dy = data[3] - data[1];
 		
-		length = sqrt(dx * dx + dy * dy);
+		length = hypot(dx, dy);
 		
 		if (mi->precision) {
 			/* deal with Shift key by adding motion / 10 to motion before shift press */




More information about the Bf-blender-cvs mailing list