make ngon_perimeter into a public api function and expose to python.

This commit is contained in:
2012-04-15 10:09:27 +00:00
parent 97538bd9ed
commit db53faffa3
4 changed files with 34 additions and 31 deletions

View 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.
*/

View 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]);

View 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:

View 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},