Add new BMesh length query functions.
authorNicholas Bishop <nicholasbishop@gmail.com>
Tue, 22 May 2012 15:19:33 +0000 (15:19 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Tue, 22 May 2012 15:19:33 +0000 (15:19 +0000)
BMEdge *BM_face_find_shortest_edge(BMFace *f);
BMEdge *BM_face_find_longest_edge(BMFace *f);

Reviewed by Campbell Barton.

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

index f61f966..549cc44 100644 (file)
@@ -951,6 +951,49 @@ float BM_vert_calc_mean_tagged_edge_length(BMVert *v)
 }
 
 
+/**
+ * Returns the shortest edge in f.
+ */
+BMEdge *BM_face_find_shortest_edge(BMFace *f)
+{
+       BMIter iter;
+       BMEdge *shortest_edge = NULL, *e;
+       float shortest_len = FLT_MAX;
+
+       BM_ITER_ELEM(e, &iter, f, BM_EDGES_OF_FACE) {
+               float len = BM_edge_calc_length(e);
+
+               if (len <= shortest_len) {
+                       shortest_edge = e;
+                       shortest_len = len;
+               }
+       }
+
+       return shortest_edge;
+}
+
+/**
+ * Returns the longest edge in f.
+ */
+BMEdge *BM_face_find_longest_edge(BMFace *f)
+{
+       BMIter iter;
+       BMEdge *longest_edge = NULL, *e;
+       float longest_len = 0;
+
+       BM_ITER_ELEM(e, &iter, f, BM_EDGES_OF_FACE) {
+               float len = BM_edge_calc_length(e);
+
+               if (len >= longest_len) {
+                       longest_edge = e;
+                       longest_len = len;
+               }
+       }
+
+       return longest_edge;
+}
+
+
 /**
  * Returns the edge existing between v1 and v2, or NULL if there isn't one.
  *
index 08e1588..9712c00 100644 (file)
@@ -67,6 +67,9 @@ float   BM_vert_calc_edge_angle(BMVert *v);
 float   BM_vert_calc_shell_factor(BMVert *v);
 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);
+
 BMEdge *BM_edge_exists(BMVert *v1, BMVert *v2);
 
 int     BM_face_exists_overlap(BMesh *bm, BMVert **varr, int len, BMFace **r_existface);