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:
authorClément Foucault <foucault.clem@gmail.com>2019-01-10 00:09:27 +0300
committerClément Foucault <foucault.clem@gmail.com>2019-01-11 18:00:23 +0300
commit74260a2b6da86e3f6da0a37afc6d47338c1be034 (patch)
tree711ac149390cc2809b59738ec6723296c1bdfe6a /source/blender/bmesh/intern/bmesh_polygon.c
parentb98e6743dcaf8ec513bbbadc0015cb8729a72a18 (diff)
BMesh: Add BM_face_calc_area_uv
Diffstat (limited to 'source/blender/bmesh/intern/bmesh_polygon.c')
-rw-r--r--source/blender/bmesh/intern/bmesh_polygon.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c
index 87903b3fd58..a3b0f72fbcf 100644
--- a/source/blender/bmesh/intern/bmesh_polygon.c
+++ b/source/blender/bmesh/intern/bmesh_polygon.c
@@ -30,6 +30,7 @@
#include "DNA_listBase.h"
#include "DNA_modifier_types.h"
+#include "DNA_meshdata_types.h"
#include "MEM_guardedalloc.h"
@@ -262,6 +263,25 @@ float BM_face_calc_area_with_mat3(const BMFace *f, const float mat3[3][3])
}
/**
+ * get the area of UV face
+ */
+float BM_face_calc_area_uv(const BMFace *f, int cd_loop_uv_offset)
+{
+ /* inline 'area_poly_v2' logic, avoid creating a temp array */
+ const BMLoop *l_iter, *l_first;
+
+ l_iter = l_first = BM_FACE_FIRST_LOOP(f);
+ /* The Trapezium Area Rule */
+ float cross = 0.0f;
+ do {
+ const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset);
+ const MLoopUV *luv_next = BM_ELEM_CD_GET_VOID_P(l_iter->next, cd_loop_uv_offset);
+ cross += (luv_next->uv[0] - luv->uv[0]) * (luv_next->uv[1] + luv->uv[1]);
+ } while ((l_iter = l_iter->next) != l_first);
+ return fabsf(cross * 0.5f);
+}
+
+/**
* compute the perimeter of an ngon
*/
float BM_face_calc_perimeter(const BMFace *f)