Commit: a1a0ebbf490fd36d893ad5b0a37e099f3d035eac
Author: Campbell Barton
Date:   Sun Feb 2 01:36:40 2014 +1100
https://developer.blender.org/rBa1a0ebbf490fd36d893ad5b0a37e099f3d035eac

Code cleanup: use length squared where possible

===================================================================

M       source/blender/blenkernel/intern/brush.c
M       source/blender/blenkernel/intern/mask.c
M       source/blender/blenkernel/intern/mball.c
M       source/blender/blenkernel/intern/mesh.c
M       source/blender/blenlib/intern/graph.c
M       source/blender/editors/interface/interface_handlers.c
M       source/blender/editors/mask/mask_intern.h
M       source/blender/editors/mask/mask_ops.c
M       source/blender/editors/space_clip/clip_draw.c
M       source/blender/editors/space_clip/tracking_ops.c

===================================================================

diff --git a/source/blender/blenkernel/intern/brush.c 
b/source/blender/blenkernel/intern/brush.c
index d6b48c7..4885798 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -920,7 +920,7 @@ void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, 
const float pos[2],
                do {
                        rand_pos[0] = BLI_rng_get_float(brush_rng) - 0.5f;
                        rand_pos[1] = BLI_rng_get_float(brush_rng) - 0.5f;
-               } while (len_v2(rand_pos) > 0.5f);
+               } while (len_squared_v2(rand_pos) > (0.5f * 0.5f));
 
 
                if (brush->flag & BRUSH_ABSOLUTE_JITTER) {
diff --git a/source/blender/blenkernel/intern/mask.c 
b/source/blender/blenkernel/intern/mask.c
index 280093b..997c444 100644
--- a/source/blender/blenkernel/intern/mask.c
+++ b/source/blender/blenkernel/intern/mask.c
@@ -1178,7 +1178,7 @@ static void mask_calc_point_handle(MaskSplinePoint 
*point, MaskSplinePoint *poin
                sub_v3_v3v3(v2, bezt->vec[2], bezt->vec[1]);
                add_v3_v3v3(vec, v1, v2);
 
-               if (len_v3(vec) > 1e-3) {
+               if (len_squared_v3(vec) > (1e-3f * 1e-3f)) {
                        h[0] = vec[1];
                        h[1] = -vec[0];
                        h[2] = 0.0f;
diff --git a/source/blender/blenkernel/intern/mball.c 
b/source/blender/blenkernel/intern/mball.c
index 0197415..6ba6933 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -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_v3v3(out, in);
+                                       max_len = len_squared_v3v3(out, in);
 
                                        nx = fabsf((out[0] - in[0]) / 
process->size);
                                        ny = fabsf((out[1] - in[1]) / 
process->size);
@@ -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_v3v3(workp, 
in);
+                                                       len = 
len_squared_v3v3(workp, in);
                                                        workp_v = tmp_v;
 
                                                }
diff --git a/source/blender/blenkernel/intern/mesh.c 
b/source/blender/blenkernel/intern/mesh.c
index e8504a3..31a4a49 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -154,7 +154,7 @@ static int customdata_compare(CustomData *c1, CustomData 
*c2, Mesh *m1, Mesh *m2
                        int vtot = m1->totvert;
                        
                        for (j = 0; j < vtot; j++, v1++, v2++) {
-                               if (len_v3v3(v1->co, v2->co) > thresh)
+                               if (len_squared_v3v3(v1->co, v2->co) > 
thresh_sq)
                                        return MESHCMP_VERTCOMISMATCH;
                                /* I don't care about normals, let's just do 
coodinates */
                        }
diff --git a/source/blender/blenlib/intern/graph.c 
b/source/blender/blenlib/intern/graph.c
index 24497f8..9ec183a 100644
--- a/source/blender/blenlib/intern/graph.c
+++ b/source/blender/blenlib/intern/graph.c
@@ -235,11 +235,12 @@ void BLI_replaceNode(BGraph *graph, BNode *node_src, 
BNode *node_replaced)
 
 void BLI_removeDoubleNodes(BGraph *graph, float limit)
 {
+       const float limit_sq = limit * limit;
        BNode *node_src, *node_replaced;
        
        for (node_src = graph->nodes.first; node_src; node_src = 
node_src->next) {
                for (node_replaced = graph->nodes.first; node_replaced; 
node_replaced = node_replaced->next) {
-                       if (node_replaced != node_src && 
len_v3v3(node_replaced->p, node_src->p) <= limit) {
+                       if (node_replaced != node_src && 
len_squared_v3v3(node_replaced->p, node_src->p) <= limit_sq) {
                                BLI_replaceNode(graph, node_src, node_replaced);
                        }
                }
@@ -249,12 +250,13 @@ void BLI_removeDoubleNodes(BGraph *graph, float limit)
 
 BNode *BLI_FindNodeByPosition(BGraph *graph, const float p[3], const float 
limit)
 {
+       const float limit_sq = limit * limit;
        BNode *closest_node = NULL, *node;
        float min_distance = 0.0f;
        
        for (node = graph->nodes.first; node; node = node->next) {
-               float distance = len_v3v3(p, node->p); 
-               if (distance <= limit && (closest_node == NULL || distance < 
min_distance)) {
+               float distance = len_squared_v3v3(p, node->p);
+               if (distance <= limit_sq && (closest_node == NULL || distance < 
min_distance)) {
                        closest_node = node;
                        min_distance = distance;
                }
@@ -476,6 +478,7 @@ void BLI_mirrorAlongAxis(float v[3], float center[3], float 
axis[3])
 
 static void testRadialSymmetry(BGraph *graph, BNode *root_node, RadialArc 
*ring, int total, float axis[3], float limit, int group)
 {
+       const float limit_sq = limit * limit;
        int symmetric = 1;
        int i;
        
@@ -525,7 +528,7 @@ static void testRadialSymmetry(BGraph *graph, BNode 
*root_node, RadialArc *ring,
                BLI_mirrorAlongAxis(p, root_node->p, normal);
                
                /* check if it's within limit before continuing */
-               if (len_v3v3(node1->p, p) > limit) {
+               if (len_squared_v3v3(node1->p, p) > limit_sq) {
                        symmetric = 0;
                }
 
@@ -707,6 +710,7 @@ static void flagAxialSymmetry(BNode *root_node, BNode 
*end_node, BArc *arc, int
 
 static void testAxialSymmetry(BGraph *graph, BNode *root_node, BNode *node1, 
BNode *node2, BArc *arc1, BArc *arc2, float axis[3], float limit, int group)
 {
+       const float limit_sq = limit * limit;
        float nor[3], vec[3], p[3];
 
        sub_v3_v3v3(p, node1->p, root_node->p);
@@ -733,7 +737,7 @@ static void testAxialSymmetry(BGraph *graph, BNode 
*root_node, BNode *node1, BNo
        BLI_mirrorAlongAxis(p, root_node->p, nor);
        
        /* check if it's within limit before continuing */
-       if (len_v3v3(node1->p, p) <= limit) {
+       if (len_squared_v3v3(node1->p, p) <= limit_sq) {
                /* mark node as symmetric physically */
                copy_v3_v3(root_node->symmetry_axis, nor);
                root_node->symmetry_flag |= SYM_PHYSICAL;
diff --git a/source/blender/editors/interface/interface_handlers.c 
b/source/blender/editors/interface/interface_handlers.c
index b9bdbe5..45e6993 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -4586,7 +4586,7 @@ static bool ui_numedit_but_CURVE(uiBlock *block, uiBut 
*but, uiHandleButtonData
                d[0] = mx - data->dragstartx;
                d[1] = my - data->dragstarty;
 
-               if (len_v2(d) < 3.0f)
+               if (len_squared_v2(d) < (3.0f * 3.0f))
                        snap = false;
        }
 
diff --git a/source/blender/editors/mask/mask_intern.h 
b/source/blender/editors/mask/mask_intern.h
index 9461922..a666daa 100644
--- a/source/blender/editors/mask/mask_intern.h
+++ b/source/blender/editors/mask/mask_intern.h
@@ -66,13 +66,13 @@ void MASK_OT_normals_make_consistent(struct wmOperatorType 
*ot);
 
 void MASK_OT_handle_type_set(struct wmOperatorType *ot);
 
-int ED_mask_feather_find_nearest(
-        const struct bContext *C, struct Mask *mask, float normal_co[2], int 
threshold,
+bool ED_mask_feather_find_nearest(
+        const struct bContext *C, struct Mask *mask, const float normal_co[2], 
const float threshold,
         struct MaskLayer **masklay_r, struct MaskSpline **spline_r, struct 
MaskSplinePoint **point_r,
         struct MaskSplinePointUW **uw_r, float *score);
 
 struct MaskSplinePoint *ED_mask_point_find_nearest(
-        const struct bContext *C, struct Mask *mask, float normal_co[2], int 
threshold,
+        const struct bContext *C, struct Mask *mask, const float normal_co[2], 
const float threshold,
         struct MaskLayer **masklay_r, struct MaskSpline **spline_r, int 
*is_handle_r,
         float *score);
 
diff --git a/source/blender/editors/mask/mask_ops.c 
b/source/blender/editors/mask/mask_ops.c
index c255168..bf2939c 100644
--- a/source/blender/editors/mask/mask_ops.c
+++ b/source/blender/editors/mask/mask_ops.c
@@ -59,7 +59,7 @@
 
 /******************** utility functions *********************/
 
-MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, Mask *mask, 
float normal_co[2], int threshold,
+MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, Mask *mask, 
const float normal_co[2], const float threshold,
                                             MaskLayer **masklay_r, MaskSpline 
**spline_r, int *is_handle_r,
                                             float *score)
 {
@@ -71,6 +71,7 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext 
*C, Mask *mask, float
        MaskSpline *point_spline = NULL;
        MaskSplinePoint *point = NULL;
        float co[2];
+       const float threshold_sq = threshold * threshold;
        float len = FLT_MAX, scalex, scaley;
        int is_handle = FALSE, width, height;
 
@@ -105,7 +106,7 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext 
*C, Mask *mask, float
                                        handle[0] *= scalex;
                                        handle[1] *= scaley;
 
-                                       cur_len = len_v2v2(co, handle);
+                                       cur_len = len_squared_v2v2(co, handle);
 
                                        if (cur_len < len) {
                                                point_masklay = masklay;
@@ -116,7 +117,7 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext 
*C, Mask *mask, float
                                        }
                                }
 
-                               cur_len = len_v2v2(co, vec);
+                               cur_len = len_squared_v2v2(co, vec);
 
                                if (cur_len < len) {
                                        point_spline = spline;
@@ -129,7 +130,7 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext 
*C, Mask *mask, float
                }
        }
 
-       if (len < threshold) {
+       if (len < threshold_sq) {
                if (masklay_r)
                        *masklay_r = point_masklay;
 
@@ -140,7 +141,7 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext 
*C, Mask *mask, float
                        *is_handle_r = is_handle;
 
                if (score)
-                       *score = len;
+                       *score = sqrtf(len);
 
                return point;
        }
@@ -157,9 +158,9 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext 
*C, Mask *mask, float
        return NULL;
 }
 
-int ED_mask_feather_find_nearest(const bContext *C, Mask *mask, float 
normal_co[2], int threshold,
-                                 MaskLayer **masklay_r, MaskSpline **spline_r, 
MaskSplinePoint **point_r,
-                                 MaskSplinePointUW **uw_r, float *score)
+bool ED_mask_feather_find_nearest(const bContext *C, Mask *mask, const float 
normal_co[2], const float threshold,
+                                  MaskLayer **masklay_r, MaskSpline 
**spline_r, MaskSplinePoint **point_r,
+                                  MaskSplinePointUW **uw_r, float *score)
 {
        ScrArea *sa = CTX_wm_area(C);
        ARegion *ar = CTX_wm_region(C);
@@ -168,6 +169,7 @@ int ED_mask_feather_find_nearest(const bContext *C, Mask 
*mask, float normal_co[
        MaskSpline *point_spline = NULL;
        MaskSplinePoint *point = NULL;
        MaskSplinePointUW *uw = NULL;
+       const float thresho

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to