Code cleanup: suffix vars to make obvious they are squared

This commit is contained in:
Campbell Barton 2014-02-03 02:46:45 +11:00
parent dda63375b2
commit fed1b8b16d
37 changed files with 218 additions and 213 deletions

@ -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

@ -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 {

@ -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);
}
}

@ -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);

@ -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);

@ -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;

@ -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) {

@ -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);

@ -359,7 +359,7 @@ 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_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;

@ -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;
}

@ -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;
}
}

@ -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);

@ -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);
}

@ -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);

@ -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);

@ -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 */

@ -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;
}
}

@ -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))) +
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;
}
}

@ -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);

@ -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;
}
}

@ -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;
}

@ -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++;

@ -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;
}
}
}

@ -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;

@ -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);

@ -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);

@ -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) {

@ -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);

@ -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])

@ -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);

@ -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;
}
}

@ -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 {

@ -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;
}
}

@ -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);

@ -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) {

@ -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);
}
}

@ -1238,7 +1238,7 @@ static float my_boundbox_mesh(Mesh *me, float *loc, float *size)
BoundBox *bb;
float min[3], max[3];
float mloc[3], msize[3];
float radius=0.0f, vert_radius, *co;
float radius_sq=0.0f, vert_radius_sq, *co;
int a;
if (me->bb==0) {
@ -1260,9 +1260,9 @@ static float my_boundbox_mesh(Mesh *me, float *loc, float *size)
/* radius */
vert_radius = len_squared_v3(co);
if (vert_radius > radius)
radius = vert_radius;
vert_radius_sq = len_squared_v3(co);
if (vert_radius_sq > radius_sq)
radius_sq = vert_radius_sq;
}
if (me->totvert) {
@ -1288,7 +1288,7 @@ static float my_boundbox_mesh(Mesh *me, float *loc, float *size)
bb->vec[0][2] = bb->vec[3][2] = bb->vec[4][2] = bb->vec[7][2] = loc[2]-size[2];
bb->vec[1][2] = bb->vec[2][2] = bb->vec[5][2] = bb->vec[6][2] = loc[2]+size[2];
return sqrt(radius);
return sqrtf_signed(radius_sq);
}