From cdba862223230ed0fd69df333296b800e156e961 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 22 May 2012 15:49:41 +0000 Subject: use faces longest edge when orienting the manipulator to the active face also small speedup for finding the longest edge --- source/blender/bmesh/intern/bmesh_marking.c | 16 ++-------- source/blender/bmesh/intern/bmesh_queries.c | 49 +++++++++++++++++++---------- source/blender/bmesh/intern/bmesh_queries.h | 3 ++ 3 files changed, 37 insertions(+), 31 deletions(-) (limited to 'source') diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c index a69558eeeca..4e3f50b1106 100644 --- a/source/blender/bmesh/intern/bmesh_marking.c +++ b/source/blender/bmesh/intern/bmesh_marking.c @@ -691,21 +691,9 @@ void BM_editselection_plane(BMEditSelection *ese, float r_plane[3]) } } else { - /* BMESH_TODO (not urgent, use longest ngon edge for alignment) */ + BMLoop *l_long = BM_face_find_longest_loop(efa); - /* start with v1-2 */ - sub_v3_v3v3(r_plane, verts[0]->co, verts[1]->co); - - /* test the edge between v2-3, use if longer */ - sub_v3_v3v3(vec, verts[1]->co, verts[2]->co); - if (dot_v3v3(r_plane, r_plane) < dot_v3v3(vec, vec)) - copy_v3_v3(r_plane, vec); - - /* test the edge between v1-3, use if longer */ - sub_v3_v3v3(vec, verts[2]->co, verts[0]->co); - if (dot_v3v3(r_plane, r_plane) < dot_v3v3(vec, vec)) { - copy_v3_v3(r_plane, vec); - } + sub_v3_v3v3(r_plane, l_long->v->co, l_long->next->v->co); } } diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index 549cc44c338..94b221797b4 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -954,45 +954,60 @@ float BM_vert_calc_mean_tagged_edge_length(BMVert *v) /** * Returns the shortest edge in f. */ -BMEdge *BM_face_find_shortest_edge(BMFace *f) +BMLoop *BM_face_find_shortest_loop(BMFace *f) { - BMIter iter; - BMEdge *shortest_edge = NULL, *e; + BMLoop *shortest_loop = NULL; float shortest_len = FLT_MAX; - BM_ITER_ELEM(e, &iter, f, BM_EDGES_OF_FACE) { - float len = BM_edge_calc_length(e); + BMLoop *l_iter; + BMLoop *l_first; + 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) { - shortest_edge = e; + shortest_loop = l_iter; shortest_len = len; } - } + } while ((l_iter = l_iter->next) != l_first); - return shortest_edge; + return shortest_loop; } /** * Returns the longest edge in f. */ -BMEdge *BM_face_find_longest_edge(BMFace *f) +BMLoop *BM_face_find_longest_loop(BMFace *f) { - BMIter iter; - BMEdge *longest_edge = NULL, *e; - float longest_len = 0; + BMLoop *longest_loop = NULL; + float longest_len = 0.0f; - BM_ITER_ELEM(e, &iter, f, BM_EDGES_OF_FACE) { - float len = BM_edge_calc_length(e); + BMLoop *l_iter; + BMLoop *l_first; + 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) { - longest_edge = e; + longest_loop = l_iter; longest_len = len; } - } + } while ((l_iter = l_iter->next) != l_first); + + return longest_loop; +} - return longest_edge; +BMEdge *BM_face_find_shortest_edge(BMFace *f) +{ + return BM_face_find_shortest_loop(f)->e; } +BMEdge *BM_face_find_longest_edge(BMFace *f) +{ + return BM_face_find_longest_loop(f)->e; +} /** * Returns the edge existing between v1 and v2, or NULL if there isn't one. diff --git a/source/blender/bmesh/intern/bmesh_queries.h b/source/blender/bmesh/intern/bmesh_queries.h index 9712c0066b7..697990046be 100644 --- a/source/blender/bmesh/intern/bmesh_queries.h +++ b/source/blender/bmesh/intern/bmesh_queries.h @@ -70,6 +70,9 @@ float BM_vert_calc_mean_tagged_edge_length(BMVert *v); BMEdge *BM_face_find_shortest_edge(BMFace *f); BMEdge *BM_face_find_longest_edge(BMFace *f); +BMLoop *BM_face_find_shortest_loop(BMFace *f); +BMLoop *BM_face_find_longest_loop(BMFace *f); + BMEdge *BM_edge_exists(BMVert *v1, BMVert *v2); int BM_face_exists_overlap(BMesh *bm, BMVert **varr, int len, BMFace **r_existface); -- cgit v1.2.3