Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/bmesh/intern/bmesh_polygon.c16
-rw-r--r--source/blender/bmesh/intern/bmesh_polygon.h1
-rw-r--r--source/blender/bmesh/operators/bmo_utils.c32
-rw-r--r--source/blender/python/bmesh/bmesh_py_types.c16
4 files changed, 34 insertions, 31 deletions
diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c
index 33549660cb3..67e3d24ade1 100644
--- a/source/blender/bmesh/intern/bmesh_polygon.c
+++ b/source/blender/bmesh/intern/bmesh_polygon.c
@@ -191,6 +191,22 @@ float BM_face_area_calc(BMesh *bm, BMFace *f)
}
/**
+ * 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.
*/
void BM_face_center_bounds_calc(BMesh *UNUSED(bm), BMFace *f, float r_cent[3])
diff --git a/source/blender/bmesh/intern/bmesh_polygon.h b/source/blender/bmesh/intern/bmesh_polygon.h
index 3c8f3dc3339..71387f18ce2 100644
--- a/source/blender/bmesh/intern/bmesh_polygon.h
+++ b/source/blender/bmesh/intern/bmesh_polygon.h
@@ -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]);
diff --git a/source/blender/bmesh/operators/bmo_utils.c b/source/blender/bmesh/operators/bmo_utils.c
index c359d530f73..ea1fc5171e5 100644
--- a/source/blender/bmesh/operators/bmo_utils.c
+++ b/source/blender/bmesh/operators/bmo_utils.c
@@ -459,36 +459,6 @@ void bmo_vertexsmooth_exec(BMesh *bm, BMOperator *op)
}
/*
- * 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
* while this method is far from being exact, it should garantee an invariance.
@@ -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:
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index 4b4dc7caa7f..5fcefc7533b 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -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},