make ngon_perimeter into a public api function and expose to python.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 15 Apr 2012 10:09:27 +0000 (10:09 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 15 Apr 2012 10:09:27 +0000 (10:09 +0000)
source/blender/bmesh/intern/bmesh_polygon.c
source/blender/bmesh/intern/bmesh_polygon.h
source/blender/bmesh/operators/bmo_utils.c
source/blender/python/bmesh/bmesh_py_types.c

index 33549660cb35e6e53e1b6eab82fad4db49cf1613..67e3d24ade193a8486d97ee08107a2fbb4aede81 100644 (file)
@@ -190,6 +190,22 @@ float BM_face_area_calc(BMesh *bm, BMFace *f)
        return area;
 }
 
+/**
+ * compute the perimeter of an ngon
+ */
+float BM_face_perimeter_calc(BMesh *UNUSED(bm), BMFace *f)
+{
+       BMLoop *l_iter, *l_first;
+       float perimeter = 0.0f;
+
+       l_iter = l_first = BM_FACE_FIRST_LOOP(f);
+       do {
+               perimeter += len_v3v3(l_iter->v->co, l_iter->next->v->co);
+       } while ((l_iter = l_iter->next) != l_first);
+
+       return perimeter;
+}
+
 /**
  * computes center of face in 3d.  uses center of bounding box.
  */
index 3c8f3dc333999e4ef8c13490f9134179ede63a4a..71387f18ce2b5dee99edd65c9063dbe310627132 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 float BM_face_area_calc(BMesh *bm, BMFace *f);
+float BM_face_perimeter_calc(BMesh *bm, BMFace *f);
 void  BM_face_center_bounds_calc(BMesh *bm, BMFace *f, float center[3]);
 void  BM_face_center_mean_calc(BMesh *bm, BMFace *f, float center[3]);
 
index c359d530f7362a1cdeffb72a096bb0bbbeb402dd..ea1fc5171e51b75696da9a67bfe1949d43ff07d4 100644 (file)
@@ -458,36 +458,6 @@ void bmo_vertexsmooth_exec(BMesh *bm, BMOperator *op)
        BLI_array_free(cos);
 }
 
-/*
- * compute the perimeter of an ngon
- *
- * NOTE: This should probably go to bmesh_polygon.c
- */
-static float ngon_perimeter(BMesh *bm, BMFace *f)
-{
-       BMIter  liter;
-       BMLoop *l;
-       int     num_verts = 0;
-       float   v[3], sv[3];
-       float   perimeter = 0.0f;
-
-       BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, f) {
-               if (num_verts == 0) {
-                       copy_v3_v3(v, l->v->co);
-                       copy_v3_v3(sv, l->v->co);
-               }
-               else {
-                       perimeter += len_v3v3(v, l->v->co);
-                       copy_v3_v3(v, l->v->co);
-               }
-               num_verts++;
-       }
-
-       perimeter += len_v3v3(v, sv);
-
-       return perimeter;
-}
-
 /*
  * compute the fake surface of an ngon
  * This is done by decomposing the ngon into triangles who share the centroid of the ngon
@@ -593,7 +563,7 @@ void bmo_similarfaces_exec(BMesh *bm, BMOperator *op)
                        switch (type) {
                                case SIMFACE_PERIMETER:
                                        /* set the perimeter */
-                                       f_ext[i].perim = ngon_perimeter(bm, f_ext[i].f);
+                                       f_ext[i].perim = BM_face_perimeter_calc(bm, f_ext[i].f);
                                        break;
 
                                case SIMFACE_COPLANAR:
index 4b4dc7caa7f11bd6421bad20028125162d8610d6..5fcefc7533bf7e2c0823a4ef755532c8051a81e6 100644 (file)
@@ -1400,6 +1400,21 @@ static PyObject *bpy_bmface_calc_area(BPy_BMFace *self)
 }
 
 
+PyDoc_STRVAR(bpy_bmface_calc_perimeter_doc,
+".. method:: calc_perimeter()\n"
+"\n"
+"   Return the perimeter of the face.\n"
+"\n"
+"   :return: Return the perimeter of the face.\n"
+"   :rtype: float\n"
+);
+static PyObject *bpy_bmface_calc_perimeter(BPy_BMFace *self)
+{
+       BPY_BM_CHECK_OBJ(self);
+       return PyFloat_FromDouble(BM_face_perimeter_calc(self->bm, self->f));
+}
+
+
 PyDoc_STRVAR(bpy_bmface_calc_center_mean_doc,
 ".. method:: calc_center_median()\n"
 "\n"
@@ -2081,6 +2096,7 @@ static struct PyMethodDef bpy_bmface_methods[] = {
     {"copy", (PyCFunction)bpy_bmface_copy, METH_VARARGS|METH_KEYWORDS, bpy_bmface_copy_doc},
 
     {"calc_area",          (PyCFunction)bpy_bmface_calc_area,          METH_NOARGS, bpy_bmface_calc_area_doc},
+    {"calc_perimeter",     (PyCFunction)bpy_bmface_calc_perimeter,     METH_NOARGS, bpy_bmface_calc_perimeter_doc},
     {"calc_center_median", (PyCFunction)bpy_bmface_calc_center_mean,   METH_NOARGS, bpy_bmface_calc_center_mean_doc},
     {"calc_center_bounds", (PyCFunction)bpy_bmface_calc_center_bounds, METH_NOARGS, bpy_bmface_calc_center_bounds_doc},