aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/src/nopencv.cpp
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2021-06-02 11:57:00 +0200
committerjaseg <git@jaseg.de>2021-06-02 11:57:00 +0200
commit0530c365ca569435c396481605c05392829708ac (patch)
tree10865daba54121e18453236082faebd55371aa9a /svg-flatten/src/nopencv.cpp
parent536a34cd59258d3a75d4caa8431fc688b1e788f6 (diff)
downloadgerbolyze-0530c365ca569435c396481605c05392829708ac.tar.gz
gerbolyze-0530c365ca569435c396481605c05392829708ac.tar.bz2
gerbolyze-0530c365ca569435c396481605c05392829708ac.zip
Add polygon area function & tests. These tests catch a single-px bug.
Diffstat (limited to 'svg-flatten/src/nopencv.cpp')
-rw-r--r--svg-flatten/src/nopencv.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/svg-flatten/src/nopencv.cpp b/svg-flatten/src/nopencv.cpp
index 18d3f20..c222734 100644
--- a/svg-flatten/src/nopencv.cpp
+++ b/svg-flatten/src/nopencv.cpp
@@ -427,3 +427,14 @@ bool gerbolyze::nopencv::Image32::stb_to_internal(uint8_t *data) {
stbi_image_free(data);
return true;
}
+
+double gerbolyze::nopencv::polygon_area(Polygon_i &poly) {
+ double acc = 0;
+ size_t prev = poly.size() - 1;
+ for (size_t cur=0; cur<poly.size(); cur++) {
+ acc += (poly[prev][0] + poly[cur][0]) * (poly[prev][1] - poly[cur][1]);
+ prev = cur;
+ }
+ return acc / 2;
+}
+