diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-08-14 12:44:35 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-08-14 12:44:35 +0400 |
commit | f2074949e7a3dbf3a1dc5b51a0a3eee0eee9aada (patch) | |
tree | 1912a8eb416499bdba69f0955515b3d905c52024 /source/blender/editors | |
parent | 8d496b3bf2c58a0a161c20c987f414953a6d1e87 (diff) |
code cleanup: reduce calling sqrt() when distances are only calculated for comparison use dist_squared_to_line_segment_v2().
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/mesh/editmesh_rip.c | 5 | ||||
-rw-r--r-- | source/blender/editors/space_clip/tracking_select.c | 20 | ||||
-rw-r--r-- | source/blender/editors/uvedit/uvedit_ops.c | 10 |
3 files changed, 18 insertions, 17 deletions
diff --git a/source/blender/editors/mesh/editmesh_rip.c b/source/blender/editors/mesh/editmesh_rip.c index f71ec56ca5f..8325e0a50d4 100644 --- a/source/blender/editors/mesh/editmesh_rip.c +++ b/source/blender/editors/mesh/editmesh_rip.c @@ -64,6 +64,7 @@ static float edbm_rip_rip_edgedist(ARegion *ar, float mat[][4], ED_view3d_project_float_v2(ar, co1, vec1, mat); ED_view3d_project_float_v2(ar, co2, vec2, mat); + /* TODO: use dist_squared_to_line_segment_v2() looks like we only ever use for comparison */ return dist_to_line_segment_v2(mvalf, vec1, vec2); } @@ -111,8 +112,8 @@ static float edbm_rip_edge_side_measure(BMEdge *e, BMLoop *e_l, score = len_v2v2(e_v1_co, e_v2_co); - if (dist_to_line_segment_v2(fmval_tweak, e_v1_co, e_v2_co) > - dist_to_line_segment_v2(fmval, e_v1_co, e_v2_co)) + if (dist_squared_to_line_segment_v2(fmval_tweak, e_v1_co, e_v2_co) > + dist_squared_to_line_segment_v2(fmval, e_v1_co, e_v2_co)) { return score; } diff --git a/source/blender/editors/space_clip/tracking_select.c b/source/blender/editors/space_clip/tracking_select.c index ea3d1226937..5a79e832ebe 100644 --- a/source/blender/editors/space_clip/tracking_select.c +++ b/source/blender/editors/space_clip/tracking_select.c @@ -161,12 +161,12 @@ static float dist_to_rect(float co[2], float pos[2], float min[2], float max[2]) float v1[2] = {min[0], min[1]}, v2[2] = {max[0], min[1]}; float v3[2] = {max[0], max[1]}, v4[2] = {min[0], max[1]}; - d1 = dist_to_line_segment_v2(p, v1, v2); - d2 = dist_to_line_segment_v2(p, v2, v3); - d3 = dist_to_line_segment_v2(p, v3, v4); - d4 = dist_to_line_segment_v2(p, v4, v1); + d1 = dist_squared_to_line_segment_v2(p, v1, v2); + d2 = dist_squared_to_line_segment_v2(p, v2, v3); + d3 = dist_squared_to_line_segment_v2(p, v3, v4); + d4 = dist_squared_to_line_segment_v2(p, v4, v1); - return MIN4(d1, d2, d3, d4); + return sqrtf(MIN4(d1, d2, d3, d4)); } static float dist_to_crns(float co[2], float pos[2], float crns[4][2]) @@ -176,12 +176,12 @@ static float dist_to_crns(float co[2], float pos[2], float crns[4][2]) float *v1 = crns[0], *v2 = crns[1]; float *v3 = crns[2], *v4 = crns[3]; - d1 = dist_to_line_segment_v2(p, v1, v2); - d2 = dist_to_line_segment_v2(p, v2, v3); - d3 = dist_to_line_segment_v2(p, v3, v4); - d4 = dist_to_line_segment_v2(p, v4, v1); + d1 = dist_squared_to_line_segment_v2(p, v1, v2); + d2 = dist_squared_to_line_segment_v2(p, v2, v3); + d3 = dist_squared_to_line_segment_v2(p, v3, v4); + d4 = dist_squared_to_line_segment_v2(p, v4, v1); - return MIN4(d1, d2, d3, d4); + return sqrtf(MIN4(d1, d2, d3, d4)); } static MovieTrackingTrack *find_nearest_track(SpaceClip *sc, ListBase *tracksbase, float co[2]) diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 38fd3fe5c68..54c5cbfce93 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -680,10 +680,10 @@ void uv_find_nearest_edge(Scene *scene, Image *ima, BMEditMesh *em, const float BMLoop *l; BMIter iter, liter; MLoopUV *luv, *nextluv; - float mindist, dist; + float mindist_squared, dist_squared; int i; - mindist = 1e10f; + mindist_squared = 1e10f; memset(hit, 0, sizeof(*hit)); BM_mesh_elem_index_ensure(em->bm, BM_VERT); @@ -698,9 +698,9 @@ void uv_find_nearest_edge(Scene *scene, Image *ima, BMEditMesh *em, const float luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); nextluv = CustomData_bmesh_get(&em->bm->ldata, l->next->head.data, CD_MLOOPUV); - dist = dist_to_line_segment_v2(co, luv->uv, nextluv->uv); + dist_squared = dist_squared_to_line_segment_v2(co, luv->uv, nextluv->uv); - if (dist < mindist) { + if (dist_squared < mindist_squared) { hit->tf = tf; hit->efa = efa; @@ -712,7 +712,7 @@ void uv_find_nearest_edge(Scene *scene, Image *ima, BMEditMesh *em, const float hit->vert1 = BM_elem_index_get(hit->l->v); hit->vert2 = BM_elem_index_get(hit->l->next->v); - mindist = dist; + mindist_squared = dist_squared; } i++; |