diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-01-10 12:16:19 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-01-10 12:16:19 +0400 |
commit | 7c64109bce446b91f35e187f081f3244c5c92522 (patch) | |
tree | 7acefa4a99d3182b90f0b0b52d813cd111ab3713 /source/blender/blenlib/intern/math_geom.c | |
parent | 2a43380dedd2aec7d5cb0260448e894c22da04fb (diff) |
bmesh todo: uv stretch area draw mode wasn't calculating ngon area - added area_poly_v2().
Diffstat (limited to 'source/blender/blenlib/intern/math_geom.c')
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 5f1047d054e..fc1d0e99a30 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -149,6 +149,25 @@ float area_poly_v3(int nr, float verts[][3], const float normal[3]) return fabsf(0.5f * area / max); } +float area_poly_v2(int nr, float verts[][2]) +{ + int a; + float area; + float *co_curr, *co_prev; + + /* The Trapezium Area Rule */ + co_prev = verts[nr - 1]; + co_curr = verts[0]; + area = 0.0f; + for (a = 0; a < nr; a++) { + area += (co_curr[0] - co_prev[0]) * (co_curr[1] + co_prev[1]); + co_prev = verts[a]; + co_curr = verts[a + 1]; + } + + return fabsf(0.5f * area); +} + /********************************* Distance **********************************/ /* distance p to line v1-v2 |