From 59cdbfd8849315984e280b92968d6cf1d9d44c4b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 27 Mar 2011 15:54:20 +0000 Subject: math lib and UV project: floats were being implicitly promoted to doubles, adjust to use floats. --- source/blender/blenlib/intern/math_rotation.c | 56 +++++++++++++-------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'source/blender/blenlib/intern/math_rotation.c') diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index d9afd9f3cd4..4e37de93ded 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -167,10 +167,10 @@ static void quat_to_mat3_no_error(float m[][3], const float q[4]) { double q0, q1, q2, q3, qda,qdb,qdc,qaa,qab,qac,qbb,qbc,qcc; - q0= M_SQRT2 * q[0]; - q1= M_SQRT2 * q[1]; - q2= M_SQRT2 * q[2]; - q3= M_SQRT2 * q[3]; + q0= M_SQRT2 * (double)q[0]; + q1= M_SQRT2 * (double)q[1]; + q2= M_SQRT2 * (double)q[2]; + q3= M_SQRT2 * (double)q[3]; qda= q0*q1; qdb= q0*q2; @@ -200,7 +200,7 @@ void quat_to_mat3(float m[][3], const float q[4]) { #ifdef DEBUG float f; - if(!((f=dot_qtqt(q, q))==0.0 || (fabs(f-1.0) < QUAT_EPSILON))) { + if(!((f=dot_qtqt(q, q))==0.0f || (fabsf(f-1.0f) < (float)QUAT_EPSILON))) { fprintf(stderr, "Warning! quat_to_mat3() called with non-normalized: size %.8f *** report a bug ***\n", f); } #endif @@ -213,15 +213,15 @@ void quat_to_mat4(float m[][4], const float q[4]) double q0, q1, q2, q3, qda,qdb,qdc,qaa,qab,qac,qbb,qbc,qcc; #ifdef DEBUG - if(!((q0=dot_qtqt(q, q))==0.0 || (fabs(q0-1.0) < QUAT_EPSILON))) { + if(!((q0=dot_qtqt(q, q))==0.0f || (fabsf(q0-1.0f) < (float)QUAT_EPSILON))) { fprintf(stderr, "Warning! quat_to_mat4() called with non-normalized: size %.8f *** report a bug ***\n", (float)q0); } #endif - q0= M_SQRT2 * q[0]; - q1= M_SQRT2 * q[1]; - q2= M_SQRT2 * q[2]; - q3= M_SQRT2 * q[3]; + q0= M_SQRT2 * (double)q[0]; + q1= M_SQRT2 * (double)q[1]; + q2= M_SQRT2 * (double)q[2]; + q3= M_SQRT2 * (double)q[3]; qda= q0*q1; qdb= q0*q2; @@ -261,9 +261,9 @@ void mat3_to_quat(float *q, float wmat[][3]) copy_m3_m3(mat, wmat); normalize_m3(mat); /* this is needed AND a NormalQuat in the end */ - tr= 0.25*(1.0+mat[0][0]+mat[1][1]+mat[2][2]); + tr= 0.25* (double)(1.0f+mat[0][0]+mat[1][1]+mat[2][2]); - if(tr>FLT_EPSILON) { + if(tr>(double)FLT_EPSILON) { s= sqrt(tr); q[0]= (float)s; s= 1.0/(4.0*s); @@ -273,7 +273,7 @@ void mat3_to_quat(float *q, float wmat[][3]) } else { if(mat[0][0] > mat[1][1] && mat[0][0] > mat[2][2]) { - s= 2.0*sqrtf(1.0 + mat[0][0] - mat[1][1] - mat[2][2]); + s= 2.0*sqrtf(1.0f + mat[0][0] - mat[1][1] - mat[2][2]); q[1]= (float)(0.25*s); s= 1.0/s; @@ -282,7 +282,7 @@ void mat3_to_quat(float *q, float wmat[][3]) q[3]= (float)((mat[2][0] + mat[0][2])*s); } else if(mat[1][1] > mat[2][2]) { - s= 2.0*sqrtf(1.0 + mat[1][1] - mat[0][0] - mat[2][2]); + s= 2.0*sqrtf(1.0f + mat[1][1] - mat[0][0] - mat[2][2]); q[2]= (float)(0.25*s); s= 1.0/s; @@ -361,7 +361,7 @@ float normalize_qt(float *q) float len; len= (float)sqrt(dot_qtqt(q, q)); - if(len!=0.0) { + if(len!=0.0f) { mul_qt_fl(q, 1.0f/len); } else { @@ -428,7 +428,7 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) q[1]=q[2]=q[3]= 0.0; len1= (float)sqrt(x2*x2+y2*y2+z2*z2); - if(len1 == 0.0) return; + if(len1 == 0.0f) return; /* nasty! I need a good routine for this... * problem is a rotation of an Y axis to the negative Y-axis for example. @@ -631,7 +631,7 @@ void tri_to_quat(float quat[4], const float v1[3], const float v2[3], const floa q2[1]= 0.0f; q2[2]= 0.0f; q2[3]= si; - + mul_qt_qtqt(quat, q1, q2); } @@ -667,7 +667,7 @@ void quat_to_axis_angle(float axis[3], float *angle, const float q[4]) float ha, si; #ifdef DEBUG - if(!((ha=dot_qtqt(q, q))==0.0 || (fabs(ha-1.0) < QUAT_EPSILON))) { + if(!((ha=dot_qtqt(q, q))==0.0f || (fabsf(ha-1.0f) < (float)QUAT_EPSILON))) { fprintf(stderr, "Warning! quat_to_axis_angle() called with non-normalized: size %.8f *** report a bug ***\n", ha); } #endif @@ -846,8 +846,8 @@ void vec_rot_to_quat(float *quat, const float vec[3], const float phi) unit_qt(quat); } else { - quat[0]= (float)cos(phi/2.0); - si= (float)sin(phi/2.0); + quat[0]= (float)cos((double)phi/2.0); + si= (float)sin((double)phi/2.0); quat[1] *= si; quat[2] *= si; quat[3] *= si; @@ -928,7 +928,7 @@ static void mat3_to_eul2(float tmat[][3], float eul1[3], float eul2[3]) cy = (float)sqrt(mat[0][0]*mat[0][0] + mat[0][1]*mat[0][1]); - if (cy > 16.0*FLT_EPSILON) { + if (cy > 16.0f*FLT_EPSILON) { eul1[0] = (float)atan2(mat[1][2], mat[2][2]); eul1[1] = (float)atan2(-mat[0][2], cy); @@ -1045,13 +1045,13 @@ void compatible_eul(float eul[3], const float oldrot[3]) /* is 1 of the axis rotations larger than 180 degrees and the other small? NO ELSE IF!! */ if(fabs(dx) > 3.2 && fabs(dy)<1.6 && fabs(dz)<1.6) { - if(dx > 0.0) eul[0] -= 2.0f*(float)M_PI; else eul[0]+= 2.0f*(float)M_PI; + if(dx > 0.0f) eul[0] -= 2.0f*(float)M_PI; else eul[0]+= 2.0f*(float)M_PI; } if(fabs(dy) > 3.2 && fabs(dz)<1.6 && fabs(dx)<1.6) { - if(dy > 0.0) eul[1] -= 2.0f*(float)M_PI; else eul[1]+= 2.0f*(float)M_PI; + if(dy > 0.0f) eul[1] -= 2.0f*(float)M_PI; else eul[1]+= 2.0f*(float)M_PI; } if(fabs(dz) > 3.2 && fabs(dx)<1.6 && fabs(dy)<1.6) { - if(dz > 0.0) eul[2] -= 2.0f*(float)M_PI; else eul[2]+= 2.0f*(float)M_PI; + if(dz > 0.0f) eul[2] -= 2.0f*(float)M_PI; else eul[2]+= 2.0f*(float)M_PI; } /* the method below was there from ancient days... but why! probably because the code sucks :) @@ -1222,7 +1222,7 @@ static void mat3_to_eulo2(float M[3][3], float *e1, float *e2, short order) cy= sqrt(m[i][i]*m[i][i] + m[i][j]*m[i][j]); - if (cy > 16*FLT_EPSILON) { + if (cy > 16.0*(double)FLT_EPSILON) { e1[i] = atan2(m[j][k], m[k][k]); e1[j] = atan2(-m[i][k], cy); e1[k] = atan2(m[i][j], m[i][i]); @@ -1417,7 +1417,7 @@ void mat4_to_dquat(DualQuat *dq,float basemat[][4], float mat[][4]) copy_v3_v3(dscale, scale); dscale[0] -= 1.0f; dscale[1] -= 1.0f; dscale[2] -= 1.0f; - if((determinant_m4(mat) < 0.0f) || len_v3(dscale) > 1e-4) { + if((determinant_m4(mat) < 0.0f) || len_v3(dscale) > 1e-4f) { /* extract R and S */ float tmp[4][4]; @@ -1668,10 +1668,10 @@ void vec_apply_track(float vec[3], short axis) /* lens/angle conversion (radians) */ float lens_to_angle(float lens) { - return 2.0f * atan(16.0f/lens); + return 2.0f * atanf(16.0f/lens); } float angle_to_lens(float angle) { - return 16.0f / tan(angle * 0.5f); + return 16.0f / tanf(angle * 0.5f); } -- cgit v1.2.3