Code cleanup: correct abs use

also minor cleanup to rotation code
This commit is contained in:
Campbell Barton
2014-04-21 01:54:52 +10:00
parent 1a1bc281e6
commit 55d75f5020
10 changed files with 43 additions and 40 deletions

View File

@@ -111,7 +111,7 @@ float nearest_point_in_tri_surface_squared(
B0 = dot_v3v3(diff, e0);
B1 = dot_v3v3(diff, e1);
C = dot_v3v3(diff, diff);
Det = fabs(A00 * A11 - A01 * A01);
Det = fabsf(A00 * A11 - A01 * A01);
S = A01 * B1 - A11 * B0;
T = A01 * B0 - A00 * B1;

View File

@@ -520,6 +520,7 @@ float angle_qtqt(const float q1[4], const float q2[4])
void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag)
{
const float eps = 0.0001f;
float nor[3], tvec[3];
float angle, si, co, len;
@@ -553,7 +554,7 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag)
nor[1] = -tvec[2];
nor[2] = tvec[1];
if (fabsf(tvec[1]) + fabsf(tvec[2]) < 0.0001f)
if (fabsf(tvec[1]) + fabsf(tvec[2]) < eps)
nor[1] = 1.0f;
co = tvec[0];
@@ -563,7 +564,7 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag)
nor[1] = 0.0;
nor[2] = -tvec[0];
if (fabsf(tvec[0]) + fabsf(tvec[2]) < 0.0001f)
if (fabsf(tvec[0]) + fabsf(tvec[2]) < eps)
nor[2] = 1.0f;
co = tvec[1];
@@ -573,7 +574,7 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag)
nor[1] = tvec[0];
nor[2] = 0.0;
if (fabsf(tvec[0]) + fabsf(tvec[1]) < 0.0001f)
if (fabsf(tvec[0]) + fabsf(tvec[1]) < eps)
nor[0] = 1.0f;
co = tvec[2];
@@ -582,12 +583,7 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag)
normalize_v3(nor);
angle = 0.5f * saacos(co);
si = sinf(angle);
q[0] = cosf(angle);
q[1] = nor[0] * si;
q[2] = nor[1] * si;
q[3] = nor[2] * si;
axis_angle_normalized_to_quat(q, nor, saacos(co));
if (axis != upflag) {
float mat[3][3];
@@ -1440,11 +1436,15 @@ void eulO_to_mat4(float M[4][4], const float e[3], const short order)
void mat3_to_eulO(float eul[3], const short order, float M[3][3])
{
float eul1[3], eul2[3];
float d1, d2;
mat3_to_eulo2(M, eul1, eul2, order);
d1 = fabsf(eul1[0]) + fabsf(eul1[1]) + fabsf(eul1[2]);
d2 = fabsf(eul2[0]) + fabsf(eul2[1]) + fabsf(eul2[2]);
/* return best, which is just the one with lowest values it in */
if (fabsf(eul1[0]) + fabsf(eul1[1]) + fabsf(eul1[2]) > fabsf(eul2[0]) + fabsf(eul2[1]) + fabsf(eul2[2])) {
if (d1 > d2) {
copy_v3_v3(eul, eul2);
}
else {
@@ -1478,10 +1478,12 @@ void mat3_to_compatible_eulO(float eul[3], float oldrot[3], const short order, f
d2 = fabsf(eul2[0] - oldrot[0]) + fabsf(eul2[1] - oldrot[1]) + fabsf(eul2[2] - oldrot[2]);
/* return best, which is just the one with lowest difference */
if (d1 > d2)
if (d1 > d2) {
copy_v3_v3(eul, eul2);
else
}
else {
copy_v3_v3(eul, eul1);
}
}
void mat4_to_compatible_eulO(float eul[3], float oldrot[3], const short order, float M[4][4])
@@ -1502,7 +1504,8 @@ void rotate_eulO(float beul[3], const short order, char axis, float ang)
assert(axis >= 'X' && axis <= 'Z');
eul[0] = eul[1] = eul[2] = 0.0f;
zero_v3(eul);
if (axis == 'X')
eul[0] = ang;
else if (axis == 'Y')
@@ -1538,9 +1541,7 @@ void eulO_to_gimbal_axis(float gmat[3][3], const float eul[3], const short order
/* Last axis is global */
gmat[R->axis[2]][0] = 0;
gmat[R->axis[2]][1] = 0;
gmat[R->axis[2]][2] = 0;
zero_v3(gmat[R->axis[2]]);
gmat[R->axis[2]][R->axis[2]] = 1;
}
@@ -1660,7 +1661,7 @@ void dquat_to_mat4(float mat[4][4], const DualQuat *dq)
void add_weighted_dq_dq(DualQuat *dqsum, const DualQuat *dq, float weight)
{
int flipped = 0;
bool flipped = false;
/* make sure we interpolate quats in the right direction */
if (dot_qtqt(dq->quat, dqsum->quat) < 0) {

View File

@@ -1684,7 +1684,7 @@ static RetargetMode detectArcRetargetMode(RigArc *iarc)
if (nb_edges > 2) {
for (edge = iarc->edges.first; edge; edge = edge->next) {
if (fabs(edge->angle - avg_angle) > M_PI / 6) {
if (fabsf(edge->angle - avg_angle) > (float)(M_PI / 6)) {
large_angle = 1;
}
}
@@ -1795,7 +1795,7 @@ static float costLength(float original_length, float current_length, float lengt
return MAX_COST;
}
else {
float length_ratio = fabs((current_length - original_length) / original_length);
float length_ratio = fabsf((current_length - original_length) / original_length);
return length_weight * length_ratio * length_ratio;
}
}

View File

@@ -4193,7 +4193,9 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob,
/* change of sign, we passed the 180 degree threshold. This means we need to add a turn.
* to distinguish between transition from 0 to -1 and -PI to +PI, use comparison with PI/2 */
if (mouse_angle * cache->previous_vertex_rotation < 0 && fabs(cache->previous_vertex_rotation) > M_PI_2) {
if ((mouse_angle * cache->previous_vertex_rotation < 0.0f) &&
(fabsf(cache->previous_vertex_rotation) > (float)M_PI_2))
{
if (cache->previous_vertex_rotation < 0)
cache->num_vertex_turns--;
else

View File

@@ -1302,7 +1302,7 @@ static void drawlamp(View3D *v3d, RegionView3D *rv3d, Base *base,
/* draw the circle/square representing spotbl */
if (la->type == LA_SPOT) {
float spotblcirc = fabs(z) * (1 - pow(la->spotblend, 2));
float spotblcirc = fabsf(z) * (1.0f - powf(la->spotblend, 2));
/* hide line if it is zero size or overlaps with outer border,
* previously it adjusted to always to show it but that seems
* confusing because it doesn't show the actual blend size */

View File

@@ -1886,7 +1886,7 @@ static PBool p_collapse_allowed_geometric(PEdge *edge, PEdge *pair)
if (p_vert_interior(oldv)) {
/* hlscm criterion: angular defect smaller than threshold */
if (fabs(angulardefect) > (M_PI * 30.0 / 180.0))
if (fabsf(angulardefect) > (float)(M_PI * 30.0 / 180.0))
return P_FALSE;
}
else {
@@ -1952,7 +1952,7 @@ static float p_collapse_cost(PEdge *edge, PEdge *pair)
sub_v3_v3v3(tetrav3, co2, oldv->co);
cross_v3_v3v3(c, tetrav2, tetrav3);
volumecost += fabs(dot_v3v3(edgevec, c) / 6.0f);
volumecost += fabsf(dot_v3v3(edgevec, c) / 6.0f);
#if 0
shapecost += dot_v3v3(co1, keepv->co);

View File

@@ -643,10 +643,10 @@ static float voronoiTex(Tex *tex, const float texvec[3], TexResult *texres)
{
int rv = TEX_INT;
float da[4], pa[12]; /* distance and point coordinate arrays of 4 nearest neighbors */
float aw1 = fabs(tex->vn_w1);
float aw2 = fabs(tex->vn_w2);
float aw3 = fabs(tex->vn_w3);
float aw4 = fabs(tex->vn_w4);
float aw1 = fabsf(tex->vn_w1);
float aw2 = fabsf(tex->vn_w2);
float aw3 = fabsf(tex->vn_w3);
float aw4 = fabsf(tex->vn_w4);
float sc = (aw1 + aw2 + aw3 + aw4);
if (sc!=0.f) sc = tex->ns_outscale/sc;
@@ -751,9 +751,9 @@ static int cubemap_glob(const float n[3], float x, float y, float z, float *adr1
}
mul_mat3_m4_v3(R.viewinv, nor);
x1= fabs(nor[0]);
y1= fabs(nor[1]);
z1= fabs(nor[2]);
x1 = fabsf(nor[0]);
y1 = fabsf(nor[1]);
z1 = fabsf(nor[2]);
if (z1>=x1 && z1>=y1) {
*adr1 = (x + 1.0f) / 2.0f;
@@ -844,9 +844,9 @@ static int cubemap_ob(Object *ob, const float n[3], float x, float y, float z, f
copy_v3_v3(nor, n);
if (ob) mul_mat3_m4_v3(ob->imat, nor);
x1= fabs(nor[0]);
y1= fabs(nor[1]);
z1= fabs(nor[2]);
x1 = fabsf(nor[0]);
y1 = fabsf(nor[1]);
z1 = fabsf(nor[2]);
if (z1>=x1 && z1>=y1) {
*adr1 = (x + 1.0f) / 2.0f;

View File

@@ -1910,9 +1910,9 @@ static void renderflare(RenderResult *rr, float *rectf, HaloRen *har)
for (b=1; b<har->flarec; b++) {
fla.r= fabs(rc[0]);
fla.g= fabs(rc[1]);
fla.b= fabs(rc[2]);
fla.r = fabsf(rc[0]);
fla.g = fabsf(rc[1]);
fla.b = fabsf(rc[2]);
fla.alfa= ma->flareboost*fabsf(alfa*visifac*rc[3]);
fla.hard= 20.0f + fabsf(70.0f*rc[7]);
fla.tex= 0;

View File

@@ -2120,7 +2120,7 @@ static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *v
/* clip We can test for -1.0/1.0 because of the properties of the
* coordinate transformations. */
fac= fabs(hoco[3]);
fac = fabsf(hoco[3]);
if (hoco[0]<-fac || hoco[0]>fac)
return 0;
if (hoco[1]<-fac || hoco[1]>fac)

View File

@@ -109,8 +109,8 @@ static float AngleBetween(float thetav, float phiv, float theta, float phi)
* */
static void DirectionToThetaPhi(float *toSun, float *theta, float *phi)
{
*theta = acos(toSun[2]);
if (fabs(*theta) < 1e-5)
*theta = acosf(toSun[2]);
if (fabsf(*theta) < 1e-5f)
*phi = 0;
else
*phi = atan2(toSun[1], toSun[0]);