use faces longest edge when orienting the manipulator to the active face
authorCampbell Barton <ideasman42@gmail.com>
Tue, 22 May 2012 15:49:41 +0000 (15:49 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 22 May 2012 15:49:41 +0000 (15:49 +0000)
also small speedup for finding the longest edge

source/blender/bmesh/intern/bmesh_marking.c
source/blender/bmesh/intern/bmesh_queries.c
source/blender/bmesh/intern/bmesh_queries.h

index a69558e..4e3f50b 100644 (file)
@@ -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);
                        }
 
                }
index 549cc44..94b2217 100644 (file)
@@ -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.
index 9712c00..6979900 100644 (file)
@@ -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);