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/BKE_bvhutils.h | 2 +- source/blender/blenkernel/BKE_editmesh_bvh.h | 4 +-- 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 ++-- source/blender/blenlib/BLI_kdopbvh.h | 4 +-- source/blender/blenlib/intern/BLI_kdopbvh.c | 36 ++++++++++++---------- source/blender/blenlib/intern/math_geom.c | 16 +++++----- source/blender/bmesh/intern/bmesh_construct.c | 10 +++--- source/blender/bmesh/intern/bmesh_edgeloop.c | 24 +++++++-------- source/blender/bmesh/intern/bmesh_queries.c | 14 ++++----- source/blender/bmesh/operators/bmo_normals.c | 10 +++--- .../blender/editors/interface/interface_widgets.c | 4 +-- source/blender/editors/mask/mask_ops.c | 28 ++++++++--------- source/blender/editors/mesh/editmesh_knife.c | 16 +++++----- source/blender/editors/object/object_vgroup.c | 6 ++-- source/blender/editors/physics/particle_object.c | 2 +- .../editors/sculpt_paint/paint_image_proj.c | 8 ++--- source/blender/editors/sculpt_paint/paint_vertex.c | 6 ++-- .../editors/sculpt_paint/paint_vertex_proj.c | 16 +++++----- source/blender/editors/space_clip/clip_draw.c | 6 ++-- source/blender/editors/space_clip/tracking_ops.c | 6 ++-- source/blender/editors/transform/transform.c | 20 ++++++------ .../editors/transform/transform_conversions.c | 8 ++--- source/blender/editors/transform/transform_snap.c | 10 +++--- source/blender/makesrna/intern/rna_object_api.c | 2 +- source/blender/modifiers/intern/MOD_solidify.c | 22 ++++++------- .../modifiers/intern/MOD_weightvgproximity.c | 12 ++++---- 36 files changed, 213 insertions(+), 208 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index a90a97f89cf..4bc8fc44bb4 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -108,7 +108,7 @@ void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data); * Math functions used by callbacks */ float bvhtree_ray_tri_intersection(const BVHTreeRay *ray, const float m_dist, const float v0[3], const float v1[3], const float v2[3]); -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]); /* * BVHCache diff --git a/source/blender/blenkernel/BKE_editmesh_bvh.h b/source/blender/blenkernel/BKE_editmesh_bvh.h index aeac00b06c1..355e817f621 100644 --- a/source/blender/blenkernel/BKE_editmesh_bvh.h +++ b/source/blender/blenkernel/BKE_editmesh_bvh.h @@ -53,8 +53,8 @@ struct BMFace *BKE_bmbvh_ray_cast(BMBVHTree *tree, const float co[3], const flo /* find a face intersecting a segment (but not apart of the segment) */ struct BMFace *BKE_bmbvh_find_face_segment(BMBVHTree *tree, const float co_a[3], const float co_b[3], float *r_fac, float r_hitout[3], float r_cagehit[3]); -/* find a vert closest to co in a sphere of radius maxdist */ -struct BMVert *BKE_bmbvh_find_vert_closest(BMBVHTree *tree, const float co[3], const float maxdist); +/* find a vert closest to co in a sphere of radius dist_max */ +struct BMVert *BKE_bmbvh_find_vert_closest(BMBVHTree *tree, const float co[3], const float dist_max); /* BKE_bmbvh_new flag parameter */ enum { 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); } diff --git a/source/blender/blenlib/BLI_kdopbvh.h b/source/blender/blenlib/BLI_kdopbvh.h index b55ab432a12..bf7bd3d99b2 100644 --- a/source/blender/blenlib/BLI_kdopbvh.h +++ b/source/blender/blenlib/BLI_kdopbvh.h @@ -56,7 +56,7 @@ typedef struct BVHTreeNearest { int index; /* the index of the nearest found (untouched if none is found within a dist radius from the given coordinates) */ float co[3]; /* nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */ float no[3]; /* normal at nearest coordinates (untouched it none is found within a dist radius from the given coordinates) */ - float dist; /* squared distance to search arround */ + float dist_sq; /* squared distance to search arround */ int flags; } BVHTreeNearest; @@ -81,7 +81,7 @@ typedef void (*BVHTree_NearestPointCallback)(void *userdata, int index, const fl typedef void (*BVHTree_RayCastCallback)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit); /* callback to range search query */ -typedef void (*BVHTree_RangeQuery)(void *userdata, int index, float squared_dist); +typedef void (*BVHTree_RangeQuery)(void *userdata, int index, float dist_sq); BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis); void BLI_bvhtree_free(BVHTree *tree); diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 7c1cdd593c3..5d97c1c22d2 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -1135,7 +1135,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int } /* Determines the nearest point of the given node BV. Returns the squared distance to that point. */ -static float calc_nearest_point(const float proj[3], BVHNode *node, float *nearest) +static float calc_nearest_point_squared(const float proj[3], BVHNode *node, float *nearest) { int i; const float *bv = node->bv; @@ -1185,7 +1185,7 @@ static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node) data->callback(data->userdata, node->index, data->co, &data->nearest); else { data->nearest.index = node->index; - data->nearest.dist = calc_nearest_point(data->proj, node, data->nearest.co); + data->nearest.dist_sq = calc_nearest_point_squared(data->proj, node, data->nearest.co); } } else { @@ -1196,13 +1196,15 @@ static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node) if (data->proj[node->main_axis] <= node->children[0]->bv[node->main_axis * 2 + 1]) { for (i = 0; i != node->totnode; i++) { - if (calc_nearest_point(data->proj, node->children[i], nearest) >= data->nearest.dist) continue; + if (calc_nearest_point_squared(data->proj, node->children[i], nearest) >= data->nearest.dist_sq) + continue; dfs_find_nearest_dfs(data, node->children[i]); } } else { for (i = node->totnode - 1; i >= 0; i--) { - if (calc_nearest_point(data->proj, node->children[i], nearest) >= data->nearest.dist) continue; + if (calc_nearest_point_squared(data->proj, node->children[i], nearest) >= data->nearest.dist_sq) + continue; dfs_find_nearest_dfs(data, node->children[i]); } } @@ -1211,9 +1213,11 @@ static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node) static void dfs_find_nearest_begin(BVHNearestData *data, BVHNode *node) { - float nearest[3], sdist; - sdist = calc_nearest_point(data->proj, node, nearest); - if (sdist >= data->nearest.dist) return; + float nearest[3], dist_sq; + dist_sq = calc_nearest_point_squared(data->proj, node, nearest); + if (dist_sq >= data->nearest.dist_sq) { + return; + } dfs_find_nearest_dfs(data, node); } @@ -1329,7 +1333,7 @@ int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *n } else { data.nearest.index = -1; - data.nearest.dist = FLT_MAX; + data.nearest.dist_sq = FLT_MAX; } /* dfs search */ @@ -1568,7 +1572,7 @@ float BLI_bvhtree_bb_raycast(const float bv[6], const float light_start[3], cons typedef struct RangeQueryData { BVHTree *tree; const float *center; - float radius; /* squared radius */ + float radius_sq; /* squared radius */ int hits; @@ -1594,12 +1598,12 @@ static void dfs_range_query(RangeQueryData *data, BVHNode *node) int i; for (i = 0; i != node->totnode; i++) { float nearest[3]; - float dist = calc_nearest_point(data->center, node->children[i], nearest); - if (dist < data->radius) { + float dist_sq = calc_nearest_point_squared(data->center, node->children[i], nearest); + if (dist_sq < data->radius_sq) { /* Its a leaf.. call the callback */ if (node->children[i]->totnode == 0) { data->hits++; - data->callback(data->userdata, node->children[i]->index, dist); + data->callback(data->userdata, node->children[i]->index, dist_sq); } else dfs_range_query(data, node->children[i]); @@ -1615,7 +1619,7 @@ int BLI_bvhtree_range_query(BVHTree *tree, const float co[3], float radius, BVHT RangeQueryData data; data.tree = tree; data.center = co; - data.radius = radius * radius; + data.radius_sq = radius * radius; data.hits = 0; data.callback = callback; @@ -1623,12 +1627,12 @@ int BLI_bvhtree_range_query(BVHTree *tree, const float co[3], float radius, BVHT if (root != NULL) { float nearest[3]; - float dist = calc_nearest_point(data.center, root, nearest); - if (dist < data.radius) { + float dist_sq = calc_nearest_point_squared(data.center, root, nearest); + if (dist_sq < data.radius_sq) { /* Its a leaf.. call the callback */ if (root->totnode == 0) { data.hits++; - data.callback(data.userdata, root->index, dist); + data.callback(data.userdata, root->index, dist_sq); } else dfs_range_query(&data, root); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index cfbf814a5f2..3b49ad5db8d 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -335,17 +335,17 @@ void closest_to_line_segment_v3(float close_r[3], const float v1[3], const float */ void closest_to_plane_v3(float close_r[3], const float plane[4], const float pt[3]) { - const float length = len_squared_v3(plane); + const float len_sq = len_squared_v3(plane); const float side = plane_point_side_v3(plane, pt); - madd_v3_v3v3fl(close_r, pt, plane, -side / length); + madd_v3_v3v3fl(close_r, pt, plane, -side / len_sq); } float dist_squared_to_plane_v3(const float pt[3], const float plane[4]) { - const float length = len_squared_v3(plane); + const float len_sq = len_squared_v3(plane); const float side = plane_point_side_v3(plane, pt); - const float fac = side / length; - return copysignf(length * (fac * fac), side); + const float fac = side / len_sq; + return copysignf(len_sq * (fac * fac), side); } /** @@ -353,10 +353,10 @@ float dist_squared_to_plane_v3(const float pt[3], const float plane[4]) */ float dist_to_plane_v3(const float pt[3], const float plane[4]) { - const float length = len_squared_v3(plane); + const float len_sq = len_squared_v3(plane); const float side = plane_point_side_v3(plane, pt); - const float fac = side / length; - return sqrtf(length) * fac; + const float fac = side / len_sq; + return sqrtf(len_sq) * fac; } /* distance v1 to line-piece l1-l2 in 3D */ diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index a8f8f92518a..109f964a5f9 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -394,7 +394,7 @@ BMFace *BM_face_create_ngon_vcloud(BMesh *bm, BMVert **vert_arr, int len, float far_cross_vec[3]; float sign_vec[3]; /* work out if we are pos/neg angle */ - float far_dist, far_best; + float far_dist_sq, far_dist_max_sq; float far_cross_dist, far_cross_best = 0.0f; /* get the center point and collect vector array since we loop over these a lot */ @@ -405,12 +405,12 @@ BMFace *BM_face_create_ngon_vcloud(BMesh *bm, BMVert **vert_arr, int len, /* find the far point from cent */ - far_best = 0.0f; + far_dist_max_sq = 0.0f; for (i = 0; i < len; i++) { - far_dist = len_squared_v3v3(vert_arr[i]->co, cent); - if (far_dist > far_best || far == NULL) { + far_dist_sq = len_squared_v3v3(vert_arr[i]->co, cent); + if (far_dist_sq > far_dist_max_sq || far == NULL) { far = vert_arr[i]->co; - far_best = far_dist; + far_dist_max_sq = far_dist_sq; } } diff --git a/source/blender/bmesh/intern/bmesh_edgeloop.c b/source/blender/bmesh/intern/bmesh_edgeloop.c index fe3f6551b70..4724552e4c9 100644 --- a/source/blender/bmesh/intern/bmesh_edgeloop.c +++ b/source/blender/bmesh/intern/bmesh_edgeloop.c @@ -406,11 +406,11 @@ void BM_mesh_edgeloops_calc_order(BMesh *UNUSED(bm), ListBase *eloops, const boo /* find far outest loop */ { BMEdgeLoopStore *el_store_best = NULL; - float len_best = -1.0f; + float len_best_sq = -1.0f; for (el_store = eloops->first; el_store; el_store = el_store->next) { - const float len = len_squared_v3v3(cent, el_store->co); - if (len > len_best) { - len_best = len; + const float len_sq = len_squared_v3v3(cent, el_store->co); + if (len_sq > len_best_sq) { + len_best_sq = len_sq; el_store_best = el_store; } } @@ -424,27 +424,27 @@ void BM_mesh_edgeloops_calc_order(BMesh *UNUSED(bm), ListBase *eloops, const boo BMEdgeLoopStore *el_store_best = NULL; const float *co = ((BMEdgeLoopStore *)eloops_ordered.last)->co; const float *no = ((BMEdgeLoopStore *)eloops_ordered.last)->no; - float len_best = FLT_MAX; + float len_best_sq = FLT_MAX; if (use_normals) BLI_ASSERT_UNIT_V3(no); for (el_store = eloops->first; el_store; el_store = el_store->next) { - float len; + float len_sq; if (use_normals) { /* scale the length by how close the loops are to pointing at eachother */ float dir[3]; sub_v3_v3v3(dir, co, el_store->co); - len = normalize_v3(dir); - len = len * ((1.0f - fabsf(dot_v3v3(dir, no))) + - (1.0f - fabsf(dot_v3v3(dir, el_store->no)))); + len_sq = normalize_v3(dir); + len_sq = len_sq * ((1.0f - fabsf(dot_v3v3(dir, no))) + + (1.0f - fabsf(dot_v3v3(dir, el_store->no)))); } else { - len = len_squared_v3v3(co, el_store->co); + len_sq = len_squared_v3v3(co, el_store->co); } - if (len < len_best) { - len_best = len; + if (len_sq < len_best_sq) { + len_best_sq = len_sq; el_store_best = el_store; } } diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index 968ca5f3102..e66af07eeac 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -1323,10 +1323,10 @@ BMLoop *BM_face_find_shortest_loop(BMFace *f) l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - const float len = len_squared_v3v3(l_iter->v->co, l_iter->next->v->co); - if (len <= shortest_len) { + const float len_sq = len_squared_v3v3(l_iter->v->co, l_iter->next->v->co); + if (len_sq <= shortest_len) { shortest_loop = l_iter; - shortest_len = len; + shortest_len = len_sq; } } while ((l_iter = l_iter->next) != l_first); @@ -1339,7 +1339,7 @@ BMLoop *BM_face_find_shortest_loop(BMFace *f) BMLoop *BM_face_find_longest_loop(BMFace *f) { BMLoop *longest_loop = NULL; - float longest_len = 0.0f; + float len_max_sq = 0.0f; BMLoop *l_iter; BMLoop *l_first; @@ -1347,10 +1347,10 @@ BMLoop *BM_face_find_longest_loop(BMFace *f) l_iter = l_first = BM_FACE_FIRST_LOOP(f); do { - const float len = len_squared_v3v3(l_iter->v->co, l_iter->next->v->co); - if (len >= longest_len) { + const float len_sq = len_squared_v3v3(l_iter->v->co, l_iter->next->v->co); + if (len_sq >= len_max_sq) { longest_loop = l_iter; - longest_len = len; + len_max_sq = len_sq; } } while ((l_iter = l_iter->next) != l_first); diff --git a/source/blender/bmesh/operators/bmo_normals.c b/source/blender/bmesh/operators/bmo_normals.c index 7ad592411fc..0856beeeb12 100644 --- a/source/blender/bmesh/operators/bmo_normals.c +++ b/source/blender/bmesh/operators/bmo_normals.c @@ -63,7 +63,7 @@ static void bmo_recalc_face_normals_array(BMesh *bm, BMFace **faces, const int f int i, f_start_index; const short oflag_flip = oflag | FACE_FLIP; - float f_len_best; + float f_len_best_sq; BMFace *f; BLI_LINKSTACK_DECLARE(fstack, BMFace *); @@ -80,13 +80,13 @@ static void bmo_recalc_face_normals_array(BMesh *bm, BMFace **faces, const int f BLI_assert(BM_face_is_normal_valid(faces[i])); } - f_len_best = -FLT_MAX; + f_len_best_sq = -FLT_MAX; for (i = 0; i < faces_len; i++) { - float f_len_test; + float f_len_test_sq; - if ((f_len_test = len_squared_v3v3(faces_center[i], cent)) > f_len_best) { - f_len_best = f_len_test; + if ((f_len_test_sq = len_squared_v3v3(faces_center[i], cent)) > f_len_best_sq) { + f_len_best_sq = f_len_test_sq; f_start_index = i; } } diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 1724380aaf8..0006163c48e 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -1981,9 +1981,9 @@ void ui_hsvcircle_vals_from_pos(float *val_rad, float *val_dist, const rcti *rec const float centy = BLI_rcti_cent_y_fl(rect); const float radius = (float)min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)) / 2.0f; const float m_delta[2] = {mx - centx, my - centy}; - const float dist_squared = len_squared_v2(m_delta); + const float dist_sq = len_squared_v2(m_delta); - *val_dist = (dist_squared < (radius * radius)) ? sqrtf(dist_squared) / radius : 1.0f; + *val_dist = (dist_sq < (radius * radius)) ? sqrtf(dist_sq) / radius : 1.0f; *val_rad = atan2f(m_delta[0], m_delta[1]) / (2.0f * (float)M_PI) + 0.5f; } diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index bf2939c1a62..13ae17c6efd 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -72,7 +72,7 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, Mask *mask, const MaskSplinePoint *point = NULL; float co[2]; const float threshold_sq = threshold * threshold; - float len = FLT_MAX, scalex, scaley; + float len_sq = FLT_MAX, scalex, scaley; int is_handle = FALSE, width, height; ED_mask_get_size(sa, &width, &height); @@ -96,7 +96,7 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, Mask *mask, const for (i = 0; i < spline->tot_point; i++) { MaskSplinePoint *cur_point = &spline->points[i]; MaskSplinePoint *cur_point_deform = &points_array[i]; - float cur_len, vec[2], handle[2]; + float cur_len_sq, vec[2], handle[2]; vec[0] = cur_point_deform->bezt.vec[1][0] * scalex; vec[1] = cur_point_deform->bezt.vec[1][1] * scaley; @@ -106,31 +106,31 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, Mask *mask, const handle[0] *= scalex; handle[1] *= scaley; - cur_len = len_squared_v2v2(co, handle); + cur_len_sq = len_squared_v2v2(co, handle); - if (cur_len < len) { + if (cur_len_sq < len_sq) { point_masklay = masklay; point_spline = spline; point = cur_point; - len = cur_len; + len_sq = cur_len_sq; is_handle = TRUE; } } - cur_len = len_squared_v2v2(co, vec); + cur_len_sq = len_squared_v2v2(co, vec); - if (cur_len < len) { + if (cur_len_sq < len_sq) { point_spline = spline; point_masklay = masklay; point = cur_point; - len = cur_len; + len_sq = cur_len_sq; is_handle = FALSE; } } } } - if (len < threshold_sq) { + if (len_sq < threshold_sq) { if (masklay_r) *masklay_r = point_masklay; @@ -141,7 +141,7 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, Mask *mask, const *is_handle_r = is_handle; if (score) - *score = sqrtf(len); + *score = sqrtf(len_sq); return point; } @@ -200,14 +200,14 @@ bool ED_mask_feather_find_nearest(const bContext *C, Mask *mask, const float nor MaskSplinePoint *cur_point = &spline->points[i]; for (j = 0; j <= cur_point->tot_uw; j++) { - float cur_len, vec[2]; + float cur_len_sq, vec[2]; vec[0] = (*fp)[0] * scalex; vec[1] = (*fp)[1] * scaley; - cur_len = len_squared_v2v2(vec, co); + cur_len_sq = len_squared_v2v2(vec, co); - if (point == NULL || cur_len < len) { + if (point == NULL || cur_len_sq < len) { if (j == 0) uw = NULL; else @@ -216,7 +216,7 @@ bool ED_mask_feather_find_nearest(const bContext *C, Mask *mask, const float nor point_masklay = masklay; point_spline = spline; point = cur_point; - len = cur_len; + len = cur_len_sq; } fp++; diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 1fb3741380a..d24fbb3900e 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -1842,7 +1842,7 @@ static void sort_by_frac_along(ListBase *lst, BMEdge *e) for (cur = ((Ref *)lst->first)->next; cur; cur = next) { KnifeVert *vcur = cur->ref; - const float vcur_fac = len_squared_v3v3(v1co, vcur->co); + const float vcur_fac_sq = len_squared_v3v3(v1co, vcur->co); next = cur->next; prev = cur->prev; @@ -1851,7 +1851,7 @@ static void sort_by_frac_along(ListBase *lst, BMEdge *e) while (prev) { KnifeVert *vprev = prev->ref; - if (len_squared_v3v3(v1co, vprev->co) <= vcur_fac) + if (len_squared_v3v3(v1co, vprev->co) <= vcur_fac_sq) break; prev = prev->prev; } @@ -2057,7 +2057,7 @@ static bool find_hole_chains(KnifeTool_OpData *kcd, ListBase *hole, BMFace *f, L BMIter iter; int nh, nf, i, j, k, m, ax, ay, sep = 0 /* Quite warnings */, bestsep; int besti[2], bestj[2]; - float d, bestd; + float dist_sq, dist_best_sq; nh = BLI_countlist(hole); nf = f->len; @@ -2110,7 +2110,7 @@ static bool find_hole_chains(KnifeTool_OpData *kcd, ListBase *hole, BMFace *f, L for (m = 0; m < 2; m++) { besti[m] = -1; bestj[m] = -1; - bestd = FLT_MAX; + dist_best_sq = FLT_MAX; bestsep = 0; for (i = 0; i < nh; i++) { if (m == 1) { @@ -2120,15 +2120,15 @@ static bool find_hole_chains(KnifeTool_OpData *kcd, ListBase *hole, BMFace *f, L sep = MIN2(sep, nh - sep); if (sep < bestsep) continue; - bestd = FLT_MAX; + dist_best_sq = FLT_MAX; } for (j = 0; j < nf; j++) { bool ok; if (m == 1 && j == bestj[0]) continue; - d = len_squared_v2v2(hco[i], fco[j]); - if (d > bestd) + dist_sq = len_squared_v2v2(hco[i], fco[j]); + if (dist_sq > dist_best_sq) continue; ok = true; @@ -2151,7 +2151,7 @@ static bool find_hole_chains(KnifeTool_OpData *kcd, ListBase *hole, BMFace *f, L bestj[m] = j; if (m == 1) bestsep = sep; - bestd = d; + dist_best_sq = dist_sq; } } } diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 66884d75f36..fa47f8f8bd9 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -997,7 +997,7 @@ static bool ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGro } /* Reset nearest.*/ - nearest.dist = FLT_MAX; + nearest.dist_sq = FLT_MAX; /* It is faster to start searching at the top of the tree instead of previous search result.*/ nearest.index = -1; @@ -1037,7 +1037,7 @@ static bool ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGro } /* Reset nearest.*/ - nearest.dist = FLT_MAX; + nearest.dist_sq = FLT_MAX; /* It is faster to start searching at the top of the tree instead of previous search result.*/ nearest.index = -1; @@ -1098,7 +1098,7 @@ static bool ed_vgroup_transfer_weight(Object *ob_dst, Object *ob_src, bDeformGro } /* Reset nearest.*/ - nearest.dist = FLT_MAX; + nearest.dist_sq = FLT_MAX; /* It is faster to start searching at the top of the tree instead of previous search result.*/ nearest.index = -1; diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index 61392341ce3..bebc46d1242 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -675,7 +675,7 @@ static int connect_hair(Scene *scene, Object *ob, ParticleSystem *psys) key = pa->hair; nearest.index = -1; - nearest.dist = FLT_MAX; + nearest.dist_sq = FLT_MAX; BLI_bvhtree_find_nearest(bvhtree.tree, key->co, &nearest, bvhtree.nearest_callback, &bvhtree); diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 9f3743cf28f..2e8a8a32ce9 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -3814,7 +3814,7 @@ static void *do_projectpaint_thread(void *ph_v) ProjPaintImage *last_projIma = NULL; ImagePaintPartialRedraw *last_partial_redraw_cell; - float dist_nosqrt, dist; + float dist_sq, dist; float falloff; int bucket_index; @@ -3914,11 +3914,11 @@ static void *do_projectpaint_thread(void *ph_v) projPixel = (ProjPixel *)node->link; - dist_nosqrt = len_squared_v2v2(projPixel->projCoSS, pos); + dist_sq = len_squared_v2v2(projPixel->projCoSS, pos); /*if (dist < radius) {*/ /* correct but uses a sqrtf */ - if (dist_nosqrt <= brush_radius_sq) { - dist = sqrtf(dist_nosqrt); + if (dist_sq <= brush_radius_sq) { + dist = sqrtf(dist_sq); falloff = BKE_brush_curve_strength_clamp(ps->brush, dist, brush_radius); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index f04e94719c0..d6d13decf4d 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -917,11 +917,11 @@ static float calc_vp_strength_col_dl(VPaint *vp, ViewContext *vc, const float co co, co_ss, V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) { - const float dist_squared = len_squared_v2v2(mval, co_ss); + const float dist_sq = len_squared_v2v2(mval, co_ss); - if (dist_squared <= brush_size_pressure * brush_size_pressure) { + if (dist_sq <= brush_size_pressure * brush_size_pressure) { Brush *brush = BKE_paint_brush(&vp->paint); - const float dist = sqrtf(dist_squared); + const float dist = sqrtf(dist_sq); float factor; if (brush->mtex.tex && rgba) { diff --git a/source/blender/editors/sculpt_paint/paint_vertex_proj.c b/source/blender/editors/sculpt_paint/paint_vertex_proj.c index 4c06cb8ea0d..cf15fc3b2db 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_proj.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_proj.c @@ -56,7 +56,7 @@ struct VertProjHandle { bool use_update; /* use for update */ - float *dists; + float *dists_sq; Object *ob; Scene *scene; @@ -144,13 +144,13 @@ static void vpaint_proj_dm_map_cosnos_update__map_cb(void *userData, int index, co, co_ss, V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) { - const float dist = len_squared_v2v2(vp_update->mval_fl, co_ss); - if (dist > vp_handle->dists[index]) { + const float dist_sq = len_squared_v2v2(vp_update->mval_fl, co_ss); + if (dist_sq > vp_handle->dists_sq[index]) { /* bail out! */ return; } - vp_handle->dists[index] = dist; + vp_handle->dists_sq[index] = dist_sq; } } /* continue with regular functionality */ @@ -181,7 +181,7 @@ static void vpaint_proj_dm_map_cosnos_update(struct VertProjHandle *vp_handle, /* highly unlikely this will become unavailable once painting starts (perhaps with animated modifiers) */ if (LIKELY(dm->foreachMappedVert)) { - fill_vn_fl(vp_handle->dists, me->totvert, FLT_MAX); + fill_vn_fl(vp_handle->dists_sq, me->totvert, FLT_MAX); dm->foreachMappedVert(dm, vpaint_proj_dm_map_cosnos_update__map_cb, &vp_update, DM_FOREACH_USE_NORMAL); } @@ -207,13 +207,13 @@ struct VertProjHandle *ED_vpaint_proj_handle_create(Scene *scene, Object *ob, vpaint_proj_dm_map_cosnos_init(scene, ob, vp_handle); if (vp_handle->use_update) { - vp_handle->dists = MEM_mallocN(sizeof(float) * me->totvert, __func__); + vp_handle->dists_sq = MEM_mallocN(sizeof(float) * me->totvert, __func__); vp_handle->ob = ob; vp_handle->scene = scene; } else { - vp_handle->dists = NULL; + vp_handle->dists_sq = NULL; vp_handle->ob = NULL; vp_handle->scene = NULL; @@ -234,7 +234,7 @@ void ED_vpaint_proj_handle_update(struct VertProjHandle *vp_handle, void ED_vpaint_proj_handle_free(struct VertProjHandle *vp_handle) { if (vp_handle->use_update) { - MEM_freeN(vp_handle->dists); + MEM_freeN(vp_handle->dists_sq); } MEM_freeN(vp_handle->vcosnos); diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index aee6e2cda93..92f94185712 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -762,7 +762,7 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra static float get_shortest_pattern_side(MovieTrackingMarker *marker) { int i, next; - float len = FLT_MAX; + float len_sq = FLT_MAX; for (i = 0; i < 4; i++) { float cur_len; @@ -771,10 +771,10 @@ static float get_shortest_pattern_side(MovieTrackingMarker *marker) cur_len = len_squared_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]); - len = min_ff(cur_len, len); + len_sq = min_ff(cur_len, len_sq); } - return sqrtf(len); + return sqrtf(len_sq); } static void draw_marker_slide_square(float x, float y, float dx, float dy, int outline, float px[2]) diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index 2e63e00dc28..45f00462147 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -542,13 +542,13 @@ static int get_mouse_pattern_corner(SpaceClip *sc, MovieTrackingMarker *marker, float len = FLT_MAX, dx, dy; for (i = 0; i < 4; i++) { - float cur_len; + float cur_len_sq; next = (i + 1) % 4; - cur_len = len_squared_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]); + cur_len_sq = len_squared_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]); - len = min_ff(cur_len, len); + len = min_ff(cur_len_sq, len); } len = sqrtf(len); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 59cb050a335..a7d2ee35be3 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -5273,8 +5273,8 @@ static void calcNonProportionalEdgeSlide(TransInfo *t, EdgeSlideData *sld, const int i = 0; float v_proj[2]; - float dist = 0; - float min_dist = FLT_MAX; + float dist_sq = 0; + float dist_min_sq = FLT_MAX; if (t->spacetype == SPACE_VIEW3D) { /* background mode support */ @@ -5294,9 +5294,9 @@ static void calcNonProportionalEdgeSlide(TransInfo *t, EdgeSlideData *sld, const sv->edge_len = len_v3v3(sv->dir_a, sv->dir_b); ED_view3d_project_float_v2_m4(ar, sv->v->co, v_proj, projectMat); - dist = len_squared_v2v2(mval, v_proj); - if (dist < min_dist) { - min_dist = dist; + dist_sq = len_squared_v2v2(mval, v_proj); + if (dist_sq < dist_min_sq) { + dist_min_sq = dist_sq; sld->curr_sv_index = i; } } @@ -6249,14 +6249,14 @@ static void calcVertSlideMouseActiveVert(struct TransInfo *t, const int mval[2]) TransDataVertSlideVert *sv; /* set the vertex to use as a reference for the mouse direction 'curr_sv_index' */ - float dist = 0.0f; - float min_dist = FLT_MAX; + float dist_sq = 0.0f; + float dist_min_sq = FLT_MAX; int i; for (i = 0, sv = sld->sv; i < sld->totsv; i++, sv++) { - dist = len_squared_v2v2(mval_fl, sv->co_orig_2d); - if (dist < min_dist) { - min_dist = dist; + dist_sq = len_squared_v2v2(mval_fl, sv->co_orig_2d); + if (dist_sq < dist_min_sq) { + dist_min_sq = dist_sq; sld->curr_sv_index = i; } } diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 3163e8ffce4..2103073d5e9 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -238,7 +238,7 @@ static void set_prop_dist(TransInfo *t, const bool with_dist) if ((tob->flag & TD_SELECTED) == 0) { TransData *td; int i; - float dist, vec[3]; + float dist_sq, vec[3]; tob->rdist = -1.0f; // signal for next loop @@ -253,9 +253,9 @@ static void set_prop_dist(TransInfo *t, const bool with_dist) sub_v3_v3(vec, vec_p); } - dist = len_squared_v3(vec); - if ((tob->rdist == -1.0f) || (dist < (tob->rdist * tob->rdist))) { - tob->rdist = sqrtf(dist); + dist_sq = len_squared_v3(vec); + if ((tob->rdist == -1.0f) || (dist_sq < (tob->rdist * tob->rdist))) { + tob->rdist = sqrtf(dist_sq); } } else { diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 4a6f4c31a90..9f48dc8995c 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -680,22 +680,22 @@ eRedrawFlag updateSelectedSnapPoint(TransInfo *t) if (t->tsnap.status & MULTI_POINTS) { TransSnapPoint *p, *closest_p = NULL; - float closest_dist = TRANSFORM_SNAP_MAX_PX; + float dist_min_sq = TRANSFORM_SNAP_MAX_PX; const float mval_fl[2] = {t->mval[0], t->mval[1]}; float screen_loc[2]; for (p = t->tsnap.points.first; p; p = p->next) { - float dist; + float dist_sq; if (ED_view3d_project_float_global(t->ar, p->co, screen_loc, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_OK) { continue; } - dist = len_squared_v2v2(mval_fl, screen_loc); + dist_sq = len_squared_v2v2(mval_fl, screen_loc); - if (dist < closest_dist) { + if (dist_sq < dist_min_sq) { closest_p = p; - closest_dist = dist; + dist_min_sq = dist_sq; } } diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index b4692f9aec3..e672a7ef2a7 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -344,7 +344,7 @@ static void rna_Object_closest_point_on_mesh(Object *ob, ReportList *reports, fl BVHTreeNearest nearest; nearest.index = -1; - nearest.dist = max_dist * max_dist; + nearest.dist_sq = max_dist * max_dist; if (BLI_bvhtree_find_nearest(treeData.tree, point_co, &nearest, treeData.nearest_callback, &treeData) != -1) { copy_v3_v3(n_location, nearest.co); diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c index 32abf8dcb19..83b53e208c0 100644 --- a/source/blender/modifiers/intern/MOD_solidify.c +++ b/source/blender/modifiers/intern/MOD_solidify.c @@ -425,12 +425,12 @@ static DerivedMesh *applyModifier( const float offset_sq = offset * offset; if (do_clamp) { - vert_lens = MEM_callocN(sizeof(float) * numVerts, "vert_lens"); + vert_lens = MEM_mallocN(sizeof(float) * numVerts, "vert_lens"); fill_vn_fl(vert_lens, (int)numVerts, FLT_MAX); for (i = 0; i < numEdges; i++) { - const float ed_len = len_squared_v3v3(mvert[medge[i].v1].co, mvert[medge[i].v2].co); - vert_lens[medge[i].v1] = min_ff(vert_lens[medge[i].v1], ed_len); - vert_lens[medge[i].v2] = min_ff(vert_lens[medge[i].v2], ed_len); + const float ed_len_sq = len_squared_v3v3(mvert[medge[i].v1].co, mvert[medge[i].v2].co); + vert_lens[medge[i].v1] = min_ff(vert_lens[medge[i].v1], ed_len_sq); + vert_lens[medge[i].v2] = min_ff(vert_lens[medge[i].v2], ed_len_sq); } } @@ -578,22 +578,22 @@ static DerivedMesh *applyModifier( } if (do_clamp) { - float *vert_lens = MEM_callocN(sizeof(float) * numVerts, "vert_lens"); + float *vert_lens_sq = MEM_callocN(sizeof(float) * numVerts, "vert_lens"); const float offset = fabsf(smd->offset) * smd->offset_clamp; const float offset_sq = offset * offset; - fill_vn_fl(vert_lens, (int)numVerts, FLT_MAX); + fill_vn_fl(vert_lens_sq, (int)numVerts, FLT_MAX); for (i = 0; i < numEdges; i++) { const float ed_len = len_squared_v3v3(mvert[medge[i].v1].co, mvert[medge[i].v2].co); - vert_lens[medge[i].v1] = min_ff(vert_lens[medge[i].v1], ed_len); - vert_lens[medge[i].v2] = min_ff(vert_lens[medge[i].v2], ed_len); + vert_lens_sq[medge[i].v1] = min_ff(vert_lens_sq[medge[i].v1], ed_len); + vert_lens_sq[medge[i].v2] = min_ff(vert_lens_sq[medge[i].v2], ed_len); } for (i = 0; i < numVerts; i++) { - if (vert_lens[i] < offset_sq) { - float scalar = sqrtf(vert_lens[i]) / offset; + if (vert_lens_sq[i] < offset_sq) { + float scalar = sqrtf(vert_lens_sq[i]) / offset; vert_angles[i] *= scalar; } } - MEM_freeN(vert_lens); + MEM_freeN(vert_lens_sq); } if (ofs_new) { diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index 4ee8494496d..63019770942 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -131,22 +131,22 @@ static void get_vert2geom_distance(int numVerts, float (*v_cos)[3], * This will lead in prunning of the search tree. */ if (dist_v) { - nearest_v.dist = nearest_v.index != -1 ? len_squared_v3v3(tmp_co, nearest_v.co) : FLT_MAX; + nearest_v.dist_sq = nearest_v.index != -1 ? len_squared_v3v3(tmp_co, nearest_v.co) : FLT_MAX; /* Compute and store result. If invalid (-1 idx), keep FLT_MAX dist. */ BLI_bvhtree_find_nearest(treeData_v.tree, tmp_co, &nearest_v, treeData_v.nearest_callback, &treeData_v); - dist_v[i] = sqrtf(nearest_v.dist); + dist_v[i] = sqrtf(nearest_v.dist_sq); } if (dist_e) { - nearest_e.dist = nearest_e.index != -1 ? len_squared_v3v3(tmp_co, nearest_e.co) : FLT_MAX; + nearest_e.dist_sq = nearest_e.index != -1 ? len_squared_v3v3(tmp_co, nearest_e.co) : FLT_MAX; /* Compute and store result. If invalid (-1 idx), keep FLT_MAX dist. */ BLI_bvhtree_find_nearest(treeData_e.tree, tmp_co, &nearest_e, treeData_e.nearest_callback, &treeData_e); - dist_e[i] = sqrtf(nearest_e.dist); + dist_e[i] = sqrtf(nearest_e.dist_sq); } if (dist_f) { - nearest_f.dist = nearest_f.index != -1 ? len_squared_v3v3(tmp_co, nearest_f.co) : FLT_MAX; + nearest_f.dist_sq = nearest_f.index != -1 ? len_squared_v3v3(tmp_co, nearest_f.co) : FLT_MAX; /* Compute and store result. If invalid (-1 idx), keep FLT_MAX dist. */ BLI_bvhtree_find_nearest(treeData_f.tree, tmp_co, &nearest_f, treeData_f.nearest_callback, &treeData_f); - dist_f[i] = sqrtf(nearest_f.dist); + dist_f[i] = sqrtf(nearest_f.dist_sq); } } -- cgit v1.2.3