From fed1b8b16d2d6a56aeea496677f24b286672bb74 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 3 Feb 2014 02:46:45 +1100 Subject: Code cleanup: suffix vars to make obvious they are squared --- source/blender/blenkernel/intern/armature.c | 14 ++++++------- source/blender/blenkernel/intern/bvhutils.c | 28 +++++++++++++------------ source/blender/blenkernel/intern/constraint.c | 2 +- source/blender/blenkernel/intern/dynamicpaint.c | 12 +++++------ source/blender/blenkernel/intern/editmesh_bvh.c | 19 ++++++++--------- source/blender/blenkernel/intern/effect.c | 2 +- source/blender/blenkernel/intern/mask.c | 8 +++---- source/blender/blenkernel/intern/mball.c | 10 ++++----- source/blender/blenkernel/intern/object.c | 10 ++++----- source/blender/blenkernel/intern/shrinkwrap.c | 18 ++++++++-------- source/blender/blenkernel/intern/smoke.c | 6 +++--- 11 files changed, 65 insertions(+), 64 deletions(-) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index c44479a4b08..699e71393c8 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -663,7 +663,7 @@ static void b_bone_deform(bPoseChanDeform *pdef_info, Bone *bone, float co[3], D /* using vec with dist to bone b1 - b2 */ float distfactor_to_bone(const float vec[3], const float b1[3], const float b2[3], float rad1, float rad2, float rdist) { - float dist = 0.0f; + float dist_sq; float bdelta[3]; float pdelta[3]; float hsqr, a, l, rad; @@ -678,16 +678,16 @@ float distfactor_to_bone(const float vec[3], const float b1[3], const float b2[3 if (a < 0.0f) { /* If we're past the end of the bone, do a spherical field attenuation thing */ - dist = len_squared_v3v3(b1, vec); + dist_sq = len_squared_v3v3(b1, vec); rad = rad1; } else if (a > l) { /* If we're past the end of the bone, do a spherical field attenuation thing */ - dist = len_squared_v3v3(b2, vec); + dist_sq = len_squared_v3v3(b2, vec); rad = rad2; } else { - dist = (hsqr - (a * a)); + dist_sq = (hsqr - (a * a)); if (l != 0.0f) { rad = a / l; @@ -698,15 +698,15 @@ float distfactor_to_bone(const float vec[3], const float b1[3], const float b2[3 } a = rad * rad; - if (dist < a) + if (dist_sq < a) return 1.0f; else { l = rad + rdist; l *= l; - if (rdist == 0.0f || dist >= l) + if (rdist == 0.0f || dist_sq >= l) return 0.0f; else { - a = sqrtf(dist) - rad; + a = sqrtf(dist_sq) - rad; return 1.0f - (a * a) / (rdist * rdist); } } diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index 82125455584..7838fac09b5 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -82,7 +82,9 @@ static float sphereray_tri_intersection(const BVHTreeRay *ray, float radius, con * Function adapted from David Eberly's distance tools (LGPL) * http://www.geometrictools.com/LibFoundation/Distance/Distance.html */ -float nearest_point_in_tri_surface(const float v0[3], const float v1[3], const float v2[3], const float p[3], int *v, int *e, float nearest[3]) +float nearest_point_in_tri_surface_squared( + const float v0[3], const float v1[3], const float v2[3], + const float p[3], int *v, int *e, float nearest[3]) { float diff[3]; float e0[3]; @@ -377,13 +379,13 @@ static void mesh_faces_nearest_point(void *userdata, int index, const float co[3 do { - float nearest_tmp[3], dist; + float nearest_tmp[3], dist_sq; int vertex, edge; - dist = nearest_point_in_tri_surface(t0, t1, t2, co, &vertex, &edge, nearest_tmp); - if (dist < nearest->dist) { + dist_sq = nearest_point_in_tri_surface_squared(t0, t1, t2, co, &vertex, &edge, nearest_tmp); + if (dist_sq < nearest->dist_sq) { nearest->index = index; - nearest->dist = dist; + nearest->dist_sq = dist_sq; copy_v3_v3(nearest->co, nearest_tmp); normal_tri_v3(nearest->no, t0, t1, t2); @@ -410,13 +412,13 @@ static void editmesh_faces_nearest_point(void *userdata, int index, const float t2 = ltri[2]->v->co; { - float nearest_tmp[3], dist; + float nearest_tmp[3], dist_sq; int vertex, edge; - dist = nearest_point_in_tri_surface(t0, t1, t2, co, &vertex, &edge, nearest_tmp); - if (dist < nearest->dist) { + dist_sq = nearest_point_in_tri_surface_squared(t0, t1, t2, co, &vertex, &edge, nearest_tmp); + if (dist_sq < nearest->dist_sq) { nearest->index = index; - nearest->dist = dist; + nearest->dist_sq = dist_sq; copy_v3_v3(nearest->co, nearest_tmp); normal_tri_v3(nearest->no, t0, t1, t2); } @@ -499,18 +501,18 @@ static void mesh_edges_nearest_point(void *userdata, int index, const float co[3 const BVHTreeFromMesh *data = (BVHTreeFromMesh *) userdata; MVert *vert = data->vert; MEdge *edge = data->edge + index; - float nearest_tmp[3], dist; + float nearest_tmp[3], dist_sq; float *t0, *t1; t0 = vert[edge->v1].co; t1 = vert[edge->v2].co; closest_to_line_segment_v3(nearest_tmp, co, t0, t1); - dist = len_squared_v3v3(nearest_tmp, co); + dist_sq = len_squared_v3v3(nearest_tmp, co); - if (dist < nearest->dist) { + if (dist_sq < nearest->dist_sq) { nearest->index = index; - nearest->dist = dist; + nearest->dist_sq = dist_sq; copy_v3_v3(nearest->co, nearest_tmp); sub_v3_v3v3(nearest->no, t0, t1); normalize_v3(nearest->no); diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index b7850c0030e..2eca9f30bfb 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -3348,7 +3348,7 @@ static void shrinkwrap_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstra float dist; nearest.index = -1; - nearest.dist = FLT_MAX; + nearest.dist_sq = FLT_MAX; if (scon->shrinkType == MOD_SHRINKWRAP_NEAREST_VERTEX) bvhtree_from_mesh_verts(&treeData, target, 0.0, 2, 6); diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index b0968377ece..ef4d199dbb2 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -2944,13 +2944,13 @@ static void mesh_faces_nearest_point_dp(void *userdata, int index, const float c t3 = face->v4 ? vert[face->v4].co : NULL; do { - float nearest_tmp[3], dist; + float nearest_tmp[3], dist_sq; int vertex, edge; - dist = nearest_point_in_tri_surface(t0, t1, t2, co, &vertex, &edge, nearest_tmp); - if (dist < nearest->dist) { + dist_sq = nearest_point_in_tri_surface_squared(t0, t1, t2, co, &vertex, &edge, nearest_tmp); + if (dist_sq < nearest->dist_sq) { nearest->index = index; - nearest->dist = dist; + nearest->dist_sq = dist_sq; copy_v3_v3(nearest->co, nearest_tmp); nearest->no[0] = (quad) ? 1.0f : 0.0f; } @@ -3405,7 +3405,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, hit.index = -1; hit.dist = 9999; nearest.index = -1; - nearest.dist = brush_radius * brush_radius; /* find_nearest uses squared distance */ + nearest.dist_sq = brush_radius * brush_radius; /* find_nearest uses squared distance */ /* Check volume collision */ if (brush->collision == MOD_DPAINT_COL_VOLUME || brush->collision == MOD_DPAINT_COL_VOLDIST) @@ -3463,7 +3463,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* If pure distance proximity, find the nearest point on the mesh */ if (!(brush->flags & MOD_DPAINT_PROX_PROJECT)) { if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, mesh_faces_nearest_point_dp, &treeData) != -1) { - proxDist = sqrtf(nearest.dist); + proxDist = sqrtf(nearest.dist_sq); copy_v3_v3(hitCo, nearest.co); hQuad = (nearest.no[0] == 1.0f); face = nearest.index; diff --git a/source/blender/blenkernel/intern/editmesh_bvh.c b/source/blender/blenkernel/intern/editmesh_bvh.c index 1c0e508e9e6..018a9198f34 100644 --- a/source/blender/blenkernel/intern/editmesh_bvh.c +++ b/source/blender/blenkernel/intern/editmesh_bvh.c @@ -378,7 +378,7 @@ struct VertSearchUserData { const float (*cos_cage)[3]; /* from the hit */ - float maxdist; + float dist_max_sq; int index_tri; }; @@ -386,8 +386,7 @@ static void bmbvh_find_vert_closest_cb(void *userdata, int index, const float co { struct VertSearchUserData *bmcb_data = userdata; const BMLoop **ltri = bmcb_data->looptris[index]; - const float maxdist = bmcb_data->maxdist; - float dist; + const float dist_max_sq = bmcb_data->dist_max_sq; int i; const float *tri_cos[3]; @@ -395,32 +394,32 @@ static void bmbvh_find_vert_closest_cb(void *userdata, int index, const float co bmbvh_tri_from_face(tri_cos, ltri, bmcb_data->cos_cage); for (i = 0; i < 3; i++) { - dist = len_squared_v3v3(co, tri_cos[i]); - if (dist < hit->dist && dist < maxdist) { + const float dist_sq = len_squared_v3v3(co, tri_cos[i]); + if (dist_sq < hit->dist_sq && dist_sq < dist_max_sq) { copy_v3_v3(hit->co, tri_cos[i]); /* XXX, normal ignores cage */ copy_v3_v3(hit->no, ltri[i]->v->no); - hit->dist = dist; + hit->dist_sq = dist_sq; hit->index = index; bmcb_data->index_tri = i; } } } -BMVert *BKE_bmbvh_find_vert_closest(BMBVHTree *bmtree, const float co[3], const float maxdist) +BMVert *BKE_bmbvh_find_vert_closest(BMBVHTree *bmtree, const float co[3], const float dist_max) { BVHTreeNearest hit; struct VertSearchUserData bmcb_data; - const float maxdist_sq = maxdist * maxdist; + const float dist_max_sq = dist_max * dist_max; if (bmtree->cos_cage) BLI_assert(!(bmtree->bm->elem_index_dirty & BM_VERT)); - hit.dist = maxdist_sq; + hit.dist_sq = dist_max_sq; hit.index = -1; bmcb_data.looptris = (const BMLoop *(*)[3])bmtree->looptris; bmcb_data.cos_cage = (const float (*)[3])bmtree->cos_cage; - bmcb_data.maxdist = maxdist_sq; + bmcb_data.dist_max_sq = dist_max_sq; BLI_bvhtree_find_nearest(bmtree->tree, co, &hit, bmbvh_find_vert_closest_cb, &bmcb_data); if (hit.index != -1) { diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 81b0de9fd32..a8124c0f9c0 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -537,7 +537,7 @@ int closest_point_on_surface(SurfaceModifierData *surmd, const float co[3], floa BVHTreeNearest nearest; nearest.index = -1; - nearest.dist = FLT_MAX; + nearest.dist_sq = FLT_MAX; BLI_bvhtree_find_nearest(surmd->bvhtree->tree, co, &nearest, surmd->bvhtree->nearest_callback, surmd->bvhtree); diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index 997c444982c..131e383a8a2 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -358,8 +358,8 @@ void BKE_mask_spline_direction_switch(MaskLayer *masklay, MaskSpline *spline) float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point, float start_u, const float co[2], const eMaskSign sign) { - const float proj_eps = 1e-3; - const float proj_eps_squared = proj_eps * proj_eps; + const float proj_eps = 1e-3; + const float proj_eps_sq = proj_eps * proj_eps; const int N = 1000; float u = -1.0f, du = 1.0f / N, u1 = start_u, u2 = start_u; float ang = -1.0f; @@ -381,7 +381,7 @@ float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point, ((sign == MASK_PROJ_POS) && (dot_v2v2(v1, n1) >= 0.0f))) { - if (len_squared_v2(v1) > proj_eps_squared) { + if (len_squared_v2(v1) > proj_eps_sq) { ang1 = angle_v2v2(v1, n1); if (ang1 > (float)M_PI / 2.0f) ang1 = (float)M_PI - ang1; @@ -408,7 +408,7 @@ float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point, ((sign == MASK_PROJ_POS) && (dot_v2v2(v2, n2) >= 0.0f))) { - if (len_squared_v2(v2) > proj_eps_squared) { + if (len_squared_v2(v2) > proj_eps_sq) { ang2 = angle_v2v2(v2, n2); if (ang2 > (float)M_PI / 2.0f) ang2 = (float)M_PI - ang2; diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 6ba69335c6b..e5fdc449dbd 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -1500,7 +1500,7 @@ static void find_first_points(PROCESS *process, MetaBall *mb, int a) float in_v /*, out_v*/; float workp[3]; float dvec[3]; - float tmp_v, workp_v, max_len, nx, ny, nz, max_dim; + float tmp_v, workp_v, max_len_sq, nx, ny, nz, max_dim; calc_mballco(ml, in); in_v = process->function(process, in[0], in[1], in[2]); @@ -1553,7 +1553,7 @@ static void find_first_points(PROCESS *process, MetaBall *mb, int a) /* find "first points" on Implicit Surface of MetaElemnt ml */ copy_v3_v3(workp, in); workp_v = in_v; - max_len = len_squared_v3v3(out, in); + max_len_sq = len_squared_v3v3(out, in); nx = fabsf((out[0] - in[0]) / process->size); ny = fabsf((out[1] - in[1]) / process->size); @@ -1561,13 +1561,13 @@ static void find_first_points(PROCESS *process, MetaBall *mb, int a) max_dim = max_fff(nx, ny, nz); if (max_dim != 0.0f) { - float len = 0.0f; + float len_sq = 0.0f; dvec[0] = (out[0] - in[0]) / max_dim; dvec[1] = (out[1] - in[1]) / max_dim; dvec[2] = (out[2] - in[2]) / max_dim; - while (len <= max_len) { + while (len_sq <= max_len_sq) { add_v3_v3(workp, dvec); /* compute value of implicite function */ @@ -1589,7 +1589,7 @@ static void find_first_points(PROCESS *process, MetaBall *mb, int a) add_cube(process, c_i, c_j, c_k, 2); } } - len = len_squared_v3v3(workp, in); + len_sq = len_squared_v3v3(workp, in); workp_v = tmp_v; } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index bd614392a63..94ff1026d12 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1110,23 +1110,23 @@ static LodLevel *lod_level_select(Object *ob, const float cam_loc[3]) { LodLevel *current = ob->currentlod; float ob_loc[3], delta[3]; - float distance2; + float dist_sq; if (!current) return NULL; copy_v3_v3(ob_loc, ob->obmat[3]); sub_v3_v3v3(delta, ob_loc, cam_loc); - distance2 = len_squared_v3(delta); + dist_sq = len_squared_v3(delta); - if (distance2 < current->distance * current->distance) { + if (dist_sq < current->distance * current->distance) { /* check for higher LoD */ - while (current->prev && distance2 < (current->distance * current->distance)) { + while (current->prev && dist_sq < (current->distance * current->distance)) { current = current->prev; } } else { /* check for lower LoD */ - while (current->next && distance2 > (current->next->distance * current->next->distance)) { + while (current->next && dist_sq > (current->next->distance * current->next->distance)) { current = current->next; } } diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 49c36566b36..74771378e9c 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -139,7 +139,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) /* Setup nearest */ nearest.index = -1; - nearest.dist = FLT_MAX; + nearest.dist_sq = FLT_MAX; #ifndef __APPLE__ #pragma omp parallel for default(none) private(i) firstprivate(nearest) shared(treeData, calc) schedule(static) #endif @@ -167,9 +167,9 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) * so we can initiate the "nearest.dist" with the expected value to that last hit. * This will lead in pruning of the search tree. */ if (nearest.index != -1) - nearest.dist = len_squared_v3v3(tmp_co, nearest.co); + nearest.dist_sq = len_squared_v3v3(tmp_co, nearest.co); else - nearest.dist = FLT_MAX; + nearest.dist_sq = FLT_MAX; BLI_bvhtree_find_nearest(treeData.tree, tmp_co, &nearest, treeData.nearest_callback, &treeData); @@ -178,8 +178,8 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) if (nearest.index != -1) { /* Adjusting the vertex weight, * so that after interpolating it keeps a certain distance from the nearest position */ - if (nearest.dist > FLT_EPSILON) { - const float dist = sqrtf(nearest.dist); + if (nearest.dist_sq > FLT_EPSILON) { + const float dist = sqrtf(nearest.dist_sq); weight *= (dist - calc->keepDist) / dist; } @@ -441,7 +441,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) /* Setup nearest */ nearest.index = -1; - nearest.dist = FLT_MAX; + nearest.dist_sq = FLT_MAX; /* Find the nearest vertex */ @@ -469,9 +469,9 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) * so we can initiate the "nearest.dist" with the expected value to that last hit. * This will lead in pruning of the search tree. */ if (nearest.index != -1) - nearest.dist = len_squared_v3v3(tmp_co, nearest.co); + nearest.dist_sq = len_squared_v3v3(tmp_co, nearest.co); else - nearest.dist = FLT_MAX; + nearest.dist_sq = FLT_MAX; BLI_bvhtree_find_nearest(treeData.tree, tmp_co, &nearest, treeData.nearest_callback, &treeData); @@ -484,7 +484,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) else { /* Adjusting the vertex weight, * so that after interpolating it keeps a certain distance from the nearest position */ - float dist = sasqrt(nearest.dist); + const float dist = sasqrt(nearest.dist_sq); if (dist > FLT_EPSILON) { /* linear interpolation */ interp_v3_v3v3(tmp_co, tmp_co, nearest.co, (dist - calc->keepDist) / dist); diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index e83323ea7a3..8636614f7ed 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -797,7 +797,7 @@ static void obstacles_from_derivedmesh(Object *coll_ob, SmokeDomainSettings *sds float ray_start[3] = {(float)x + 0.5f, (float)y + 0.5f, (float)z + 0.5f}; BVHTreeNearest nearest = {0}; nearest.index = -1; - nearest.dist = surface_distance * surface_distance; /* find_nearest uses squared distance */ + nearest.dist_sq = surface_distance * surface_distance; /* find_nearest uses squared distance */ /* find the nearest point on the mesh */ if (BLI_bvhtree_find_nearest(treeData.tree, ray_start, &nearest, treeData.nearest_callback, &treeData) != -1) { @@ -1434,7 +1434,7 @@ static void sample_derivedmesh(SmokeFlowSettings *sfs, MVert *mvert, MTFace *tfa hit.index = -1; hit.dist = 9999; nearest.index = -1; - nearest.dist = sfs->surface_distance * sfs->surface_distance; /* find_nearest uses squared distance */ + nearest.dist_sq = sfs->surface_distance * sfs->surface_distance; /* find_nearest uses squared distance */ /* Check volume collision */ if (sfs->volume_density) { @@ -1465,7 +1465,7 @@ static void sample_derivedmesh(SmokeFlowSettings *sfs, MVert *mvert, MTFace *tfa /* emit from surface based on distance */ if (sfs->surface_distance) { - sample_str = sqrtf(nearest.dist) / sfs->surface_distance; + sample_str = sqrtf(nearest.dist_sq) / sfs->surface_distance; CLAMP(sample_str, 0.0f, 1.0f); sample_str = pow(1.0f - sample_str, 0.5f); } -- cgit v1.2.3