diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-11-10 11:54:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-11-10 11:56:02 +0300 |
commit | 3756f920f4894c9ec748c0ece5f63e1bc9c616df (patch) | |
tree | 9c75009e8998407a72b51e03328aa59f6c30a81a /source/blender/bmesh/intern/bmesh_polygon.c | |
parent | 7efac2b0b09d9e76d9fc573ec7936a1c6440c067 (diff) |
BMesh: backport minor changes from 2.8
Diffstat (limited to 'source/blender/bmesh/intern/bmesh_polygon.c')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_polygon.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index 3137725d6e7..5e3f5958a32 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -240,6 +240,28 @@ float BM_face_calc_area(const BMFace *f) } /** + * Get the area of the face in world space. + */ +float BM_face_calc_area_with_mat3(const BMFace *f, float mat3[3][3]) +{ + /* inline 'area_poly_v3' logic, avoid creating a temp array */ + const BMLoop *l_iter, *l_first; + float co[3]; + float n[3]; + + zero_v3(n); + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + mul_v3_m3v3(co, mat3, l_iter->v->co); + do { + float co_next[3]; + mul_v3_m3v3(co_next, mat3, l_iter->next->v->co); + add_newell_cross_v3_v3v3(n, co, co_next); + copy_v3_v3(co, co_next); + } while ((l_iter = l_iter->next) != l_first); + return len_v3(n) * 0.5f; +} + +/** * compute the perimeter of an ngon */ float BM_face_calc_perimeter(const BMFace *f) @@ -256,6 +278,27 @@ float BM_face_calc_perimeter(const BMFace *f) } /** + * Calculate the perimeter of a ngon in world space. + */ +float BM_face_calc_perimeter_with_mat3(const BMFace *f, float mat3[3][3]) +{ + const BMLoop *l_iter, *l_first; + float co[3]; + float perimeter = 0.0f; + + l_iter = l_first = BM_FACE_FIRST_LOOP(f); + mul_v3_m3v3(co, mat3, l_iter->v->co); + do { + float co_next[3]; + mul_v3_m3v3(co_next, mat3, l_iter->next->v->co); + perimeter += len_v3v3(co, co_next); + copy_v3_v3(co, co_next); + } while ((l_iter = l_iter->next) != l_first); + + return perimeter; +} + +/** * Utility function to calculate the edge which is most different from the other two. * * \return The first edge index, where the second vertex is ``(index + 1) % 3``. @@ -487,7 +530,7 @@ void BM_face_calc_tangent_vert_diagonal(const BMFace *f, float r_tangent[3]) } /** - * Compute a meaningful direction along the face (use for manipulator axis). + * Compute a meaningful direction along the face (use for gizmo axis). * * \note Callers shouldn't depend on the *exact* method used here. */ |