aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/src/svg_doc.cpp
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2023-03-30 14:54:46 +0200
committerjaseg <git@jaseg.de>2023-03-30 14:54:46 +0200
commitbc63166a40f522014dfd11e830cce11d6d61be6d (patch)
tree68cfdb9fc743a07b1d5f3ac7bd5909208b355e0e /svg-flatten/src/svg_doc.cpp
parent2df63318a272fcf2d1f1f6652c999cc3c415d431 (diff)
downloadgerbolyze-bc63166a40f522014dfd11e830cce11d6d61be6d.tar.gz
gerbolyze-bc63166a40f522014dfd11e830cce11d6d61be6d.tar.bz2
gerbolyze-bc63166a40f522014dfd11e830cce11d6d61be6d.zip
svg-flatten: Make drill size mapping more precise, add tests
Diffstat (limited to 'svg-flatten/src/svg_doc.cpp')
-rw-r--r--svg-flatten/src/svg_doc.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/svg-flatten/src/svg_doc.cpp b/svg-flatten/src/svg_doc.cpp
index 47e73ee..77b561e 100644
--- a/svg-flatten/src/svg_doc.cpp
+++ b/svg-flatten/src/svg_doc.cpp
@@ -282,7 +282,7 @@ void gerbolyze::SVGDocument::export_svg_path(RenderContext &ctx, const pugi::xml
}
double area = nopencv::polygon_area(geom_poly);
- double polsby_popper = 4*M_PI * area / pow(nopencv::polygon_perimeter(geom_poly), 2);
+ double polsby_popper = 4*std::numbers::pi * area / pow(nopencv::polygon_perimeter(geom_poly), 2);
polsby_popper = fabs(fabs(polsby_popper) - 1.0);
if (polsby_popper < ctx.settings().drill_test_polsby_popper_tolerance) {
if (!ctx.clip().empty()) {
@@ -298,7 +298,9 @@ void gerbolyze::SVGDocument::export_svg_path(RenderContext &ctx, const pugi::xml
d2p centroid = nopencv::polygon_centroid(geom_poly);
centroid[0] /= clipper_scale;
centroid[1] /= clipper_scale;
- double diameter = sqrt(4*fabs(area)/M_PI) / clipper_scale;
+ /* area of n-gon with circumradius 1 relative to circle with radius 1 */
+ double ngon_area_relative = p.size()/(2*std::numbers::pi) * sin(2*std::numbers::pi / p.size());
+ double diameter = sqrt(4*fabs(area)/std::numbers::pi) / clipper_scale / ngon_area_relative;
double tolerance = ctx.settings().geometric_tolerance_mm / 2;
diameter = round(diameter/tolerance) * tolerance;
ctx.sink() << ApertureToken(diameter) << FlashToken(centroid);