diff options
author | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2022-06-18 17:29:27 +0200 |
---|---|---|
committer | jaseg <git-bigdata-wsl-arch@jaseg.de> | 2022-06-18 17:29:27 +0200 |
commit | 14e9d7fbc2a935ec9c2e6eb9d68e8d250f9614d4 (patch) | |
tree | 9f86768b8ffc04a39db9b614aa4cc11956dda29b /svg-flatten/src/nopencv.cpp | |
parent | 1622e9c9435d263c3c275718947b1030ad9b6b48 (diff) | |
download | gerbolyze-14e9d7fbc2a935ec9c2e6eb9d68e8d250f9614d4.tar.gz gerbolyze-14e9d7fbc2a935ec9c2e6eb9d68e8d250f9614d4.tar.bz2 gerbolyze-14e9d7fbc2a935ec9c2e6eb9d68e8d250f9614d4.zip |
svg-flatten: add drill handling to outline mode
Diffstat (limited to 'svg-flatten/src/nopencv.cpp')
-rw-r--r-- | svg-flatten/src/nopencv.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/svg-flatten/src/nopencv.cpp b/svg-flatten/src/nopencv.cpp index 121e9e1..e157ab5 100644 --- a/svg-flatten/src/nopencv.cpp +++ b/svg-flatten/src/nopencv.cpp @@ -483,6 +483,33 @@ double gerbolyze::nopencv::polygon_area(Polygon_i &poly) { return acc / 2; } +double gerbolyze::nopencv::polygon_perimeter(Polygon_i &poly) { + double acc = 0; + size_t prev = poly.size() - 1; + for (size_t cur=0; cur<poly.size(); cur++) { + double dx = poly[cur][0] - poly[prev][0]; + double dy = poly[cur][1] - poly[prev][1]; + acc += sqrt(dx*dx + dy*dy); + prev = cur; + } + return acc; +} + +d2p gerbolyze::nopencv::polygon_centroid(Polygon_i &poly) { + double acc_x = 0, acc_y = 0; + + double area = polygon_area(poly); + size_t prev = poly.size() - 1; + for (size_t cur=0; cur<poly.size(); cur++) { + double a = poly[prev][1]*poly[cur][0] - poly[cur][1]*poly[prev][0]; + acc_x += (poly[prev][0] + poly[cur][0]) * a; + acc_y += (poly[prev][1] + poly[cur][1]) * a; + prev = cur; + } + + return { acc_x / (6*area), acc_y / (6*area) }; +} + template<typename T> gerbolyze::nopencv::Image<T>::Image(int size_x, int size_y, const T *data) { assert(size_x > 0 && size_x < 100000); |