aboutsummaryrefslogtreecommitdiff
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
parent2df63318a272fcf2d1f1f6652c999cc3c415d431 (diff)
downloadgerbolyze-bc63166a40f522014dfd11e830cce11d6d61be6d.tar.gz
gerbolyze-bc63166a40f522014dfd11e830cce11d6d61be6d.tar.bz2
gerbolyze-bc63166a40f522014dfd11e830cce11d6d61be6d.zip
svg-flatten: Make drill size mapping more precise, add tests
-rwxr-xr-xgerbolyze/__init__.py24
-rw-r--r--gerbolyze/tests/resources/layers.svg22
-rw-r--r--gerbolyze/tests/test_integration.py20
-rw-r--r--svg-flatten/src/svg_doc.cpp6
4 files changed, 32 insertions, 40 deletions
diff --git a/gerbolyze/__init__.py b/gerbolyze/__init__.py
index e817471..2989169 100755
--- a/gerbolyze/__init__.py
+++ b/gerbolyze/__init__.py
@@ -335,30 +335,6 @@ def parse_subtract_script(script, default_dilation=0.1, default_script=DEFAULT_S
subtract_script[out_layer] = subtract_script.get(out_layer, []) + [(in_layer, dilation)]
return subtract_script
-# Parameter parsing foo
-#======================
-
-def parse_bbox(bbox):
- if not bbox:
- return None
- elems = [ int(elem) for elem in re.split('[,/ ]', bbox) ]
- if len(elems) not in (2, 4):
- raise click.BadParameter(
- '--bbox must be either two floating-point values like: w,h or four like: x,y,w,h')
-
- elems = [ float(e) for e in elems ]
-
- if len(elems) == 2:
- bounds = [0, 0, *elems]
- else:
- bounds = elems
-
- # now transform bounds to the format pcb-tools uses. Instead of (x, y, w, h) or even (x1, y1, x2, y2), that
- # is ((x1, x2), (y1, y2)
-
- x, y, w, h = bounds
- return ((x, x+w), (y, y+h))
-
# Utility foo
# ===========
diff --git a/gerbolyze/tests/resources/layers.svg b/gerbolyze/tests/resources/layers.svg
index fd263c7..1879033 100644
--- a/gerbolyze/tests/resources/layers.svg
+++ b/gerbolyze/tests/resources/layers.svg
@@ -94,7 +94,7 @@
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="1.326224"
- inkscape:cx="153.44316"
+ inkscape:cx="145.52594"
inkscape:cy="302.3622"
inkscape:window-width="1920"
inkscape:window-height="1011"
@@ -109,38 +109,38 @@
aria-label="Top Paste"
transform="matrix(0.70241335,0,0,0.70241335,-8.580134,-12.02921)"
id="text1132"
- style="font-style:italic;font-size:9.00953px;font-family:'Bodoni Moda';-inkscape-font-specification:'Bodoni Moda Italic';text-align:justify;white-space:pre;shape-inside:url(#rect1134);display:inline;opacity:1;stroke:#000000;stroke-width:0.141882;stroke-linecap:round;stroke-linejoin:round">
+ style="font-style:italic;font-size:9.00953px;font-family:'Bodoni Moda';-inkscape-font-specification:'Bodoni Moda Italic';text-align:justify;white-space:pre;shape-inside:url(#rect1134);display:inline;opacity:1;stroke:#000000;stroke-width:0.14236632;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:none">
<path
d="m 22.205888,31.598738 1.567658,-6.757148 h 0.855905 l -1.567658,6.757148 z m -0.991049,0 v -0.01802 h 2.838002 v 0.01802 z m -0.162171,-4.730004 0.468495,-2.027144 h 5.360671 l -0.468496,2.027144 h -0.01802 q 0.130638,-0.572105 0.112619,-1.027086 -0.01802,-0.454981 -0.256771,-0.716258 -0.238753,-0.265781 -0.76581,-0.265781 h -2.657812 q -0.396419,0 -0.684724,0.153162 -0.288305,0.153162 -0.491019,0.427953 -0.202715,0.270286 -0.342363,0.635172 -0.139647,0.364886 -0.238752,0.792838 z"
- style="stroke-width:0.141883;stroke-linejoin:round"
+ style="stroke-width:0.14236632;stroke-linejoin:round;stroke-dasharray:none"
id="path7617" />
<path
d="m 27.584577,31.688833 q -0.680219,0 -1.009067,-0.414438 -0.328848,-0.414439 -0.328848,-1.022582 0,-0.590124 0.193705,-1.112677 0.19821,-0.522553 0.536067,-0.918972 0.337857,-0.400924 0.770315,-0.626162 0.436962,-0.229743 0.914467,-0.229743 0.684724,0 1.009067,0.418943 0.328848,0.414438 0.328848,1.022581 0,0.590125 -0.198209,1.112677 -0.193705,0.522553 -0.531563,0.923477 -0.337857,0.39642 -0.774819,0.621658 -0.432458,0.225238 -0.909963,0.225238 z m -0.09009,-0.01802 q 0.247762,0 0.48201,-0.166676 0.238752,-0.171181 0.454981,-0.459486 0.216229,-0.288305 0.396419,-0.653191 0.180191,-0.364886 0.310829,-0.76581 0.135143,-0.400924 0.207219,-0.792839 0.07658,-0.391915 0.07658,-0.725267 0,-0.333353 -0.162171,-0.527058 -0.162172,-0.193705 -0.509039,-0.193705 -0.243257,0 -0.48201,0.171182 -0.238752,0.166676 -0.454981,0.454981 -0.216229,0.288305 -0.396419,0.653191 -0.180191,0.364886 -0.315334,0.76581 -0.130638,0.400924 -0.207219,0.792838 -0.07208,0.38741 -0.07208,0.725268 0,0.328847 0.162171,0.527057 0.166677,0.193705 0.509039,0.193705 z"
- style="stroke-width:0.141883;stroke-linejoin:round"
+ style="stroke-width:0.14236632;stroke-linejoin:round;stroke-dasharray:none"
id="path7619" />
<path
d="m 30.093737,33.85112 1.711811,-6.378747 h -0.648687 v -0.01802 h 1.252325 l -0.360381,1.54063 -0.171181,0.684724 -0.05406,0.373895 -1.009068,3.797517 z m -0.675715,0 v -0.01802 h 2.157783 v 0.01802 z m 3.031707,-2.207335 q 0.234248,0 0.463991,-0.207219 0.229743,-0.211724 0.432457,-0.558591 0.202715,-0.346867 0.360381,-0.76581 0.157667,-0.423448 0.247762,-0.8514 0.0901,-0.427953 0.0901,-0.792839 0,-0.48201 -0.157667,-0.752296 -0.157667,-0.270286 -0.450477,-0.270286 -0.270285,0 -0.513543,0.189201 -0.243257,0.184695 -0.445971,0.500028 -0.19821,0.310829 -0.346867,0.698239 -0.144153,0.382905 -0.225239,0.783829 -0.08108,0.400924 -0.08108,0.756801 0,0.527057 0.126133,0.900953 0.130638,0.36939 0.500029,0.36939 z m 0.0901,0.04505 q -0.319838,0 -0.477505,-0.1892 -0.157667,-0.193705 -0.207219,-0.495524 -0.04955,-0.301819 -0.04955,-0.630667 0,-0.30182 0.05406,-0.635172 0.05856,-0.337858 0.166676,-0.675715 0.108114,-0.337857 0.261276,-0.639677 0.157667,-0.306324 0.355877,-0.545076 0.198209,-0.238753 0.436962,-0.373896 0.238753,-0.139647 0.509038,-0.139647 0.603639,0 0.873925,0.387409 0.270286,0.382905 0.270286,1.076639 0,0.518048 -0.1892,1.027087 -0.1892,0.504533 -0.509039,0.918972 -0.319838,0.414438 -0.707248,0.666705 -0.38741,0.247762 -0.788334,0.247762 z"
- style="stroke-width:0.141883;stroke-linejoin:round"
+ style="stroke-width:0.14236632;stroke-linejoin:round;stroke-dasharray:none"
id="path7621" />
<path
d="m 39.085241,28.544507 0.0045,-0.01802 h 1.225296 q 0.459486,0 0.819868,-0.207219 0.360381,-0.211724 0.608143,-0.545077 0.247762,-0.337857 0.3784,-0.729772 0.130638,-0.391914 0.130638,-0.761305 0,-0.19821 -0.04054,-0.441467 -0.04054,-0.247762 -0.153162,-0.468496 -0.112619,-0.225238 -0.315333,-0.36939 -0.202714,-0.144153 -0.527058,-0.144153 h -0.905457 l -1.567659,6.72111 h 0.896449 v 0.01802 h -2.477621 v -0.01802 h 0.725267 l 1.567658,-6.72111 h -0.806353 v -0.01802 h 2.567716 q 0.590125,0 1.045106,0.157667 0.459486,0.157667 0.720762,0.495524 0.261277,0.337858 0.261277,0.878429 0,0.675715 -0.355877,1.16223 -0.351371,0.486514 -1.009067,0.747791 -0.657696,0.261276 -1.563154,0.261276 z"
- style="stroke-width:0.141883;stroke-linejoin:round"
+ style="stroke-width:0.14236632;stroke-linejoin:round;stroke-dasharray:none"
id="path7623" />
<path
d="m 44.378339,31.688833 q -0.603639,0 -0.873924,-0.382905 -0.265782,-0.38741 -0.265782,-1.081144 0,-0.518048 0.189201,-1.022581 0.1892,-0.509039 0.509038,-0.923477 0.319838,-0.414438 0.707248,-0.662201 0.391915,-0.252266 0.788334,-0.252266 0.324343,0 0.48201,0.193705 0.157667,0.1892 0.202714,0.491019 0.04955,0.301819 0.04955,0.630667 0,0.297315 -0.05856,0.635172 -0.05406,0.337857 -0.162172,0.675715 -0.108114,0.337857 -0.265781,0.644181 -0.153162,0.301819 -0.355876,0.540572 -0.19821,0.238752 -0.436963,0.3784 -0.234247,0.135143 -0.509038,0.135143 z m 0.157667,-0.08109 q 0.270286,0 0.509038,-0.184695 0.243258,-0.1892 0.445972,-0.500029 0.202714,-0.315334 0.346867,-0.698239 0.148657,-0.387409 0.229743,-0.788333 0.08109,-0.400925 0.08109,-0.756801 0,-0.351372 -0.05406,-0.639677 -0.04955,-0.288305 -0.1892,-0.459486 -0.135143,-0.171181 -0.387409,-0.171181 -0.234248,0 -0.463991,0.211724 -0.229743,0.207219 -0.432458,0.554086 -0.202714,0.342362 -0.360381,0.761306 -0.157667,0.414438 -0.247762,0.833381 -0.09009,0.418943 -0.09009,0.770315 0,0.549581 0.166676,0.810858 0.171181,0.256771 0.445972,0.256771 z m 1.801906,0.08109 q -0.315334,0 -0.463991,-0.171181 -0.148657,-0.171181 -0.148657,-0.441467 0,-0.07658 0.0045,-0.135143 0.0045,-0.06307 0.01351,-0.108114 l 0.103609,-0.572105 0.202715,-0.666706 0.117124,-0.720762 0.342362,-1.419001 h 0.761305 l -1.031591,3.874098 q -0.01802,0.06757 -0.01802,0.144152 0,0.07658 0.04054,0.126134 0.04505,0.05406 0.144152,0.05406 0.261277,0 0.473001,-0.144153 0.216228,-0.148657 0.409933,-0.46399 0.193705,-0.319839 0.382905,-0.828877 l 0.01351,0.0045 q -0.193705,0.518048 -0.391915,0.842391 -0.193705,0.324343 -0.423448,0.477505 -0.229743,0.148657 -0.531562,0.148657 z"
- style="stroke-width:0.141883;stroke-linejoin:round"
+ style="stroke-width:0.14236632;stroke-linejoin:round;stroke-dasharray:none"
id="path7625" />
<path
d="m 49.491254,31.688833 q -0.3784,0 -0.720762,-0.117124 -0.337858,-0.121628 -0.554086,-0.351371 -0.216229,-0.234248 -0.216229,-0.567601 0,-0.19821 0.117124,-0.342362 0.121629,-0.148657 0.333353,-0.148657 0.184695,0 0.301819,0.130638 0.117124,0.126133 0.117124,0.324343 0,0.207219 -0.130638,0.315334 -0.130639,0.108114 -0.30182,0.108114 -0.117124,0 -0.216228,-0.04054 -0.0946,-0.04054 -0.153162,-0.126133 -0.05856,-0.08559 -0.05856,-0.220734 h 0.009 q 0,0.333353 0.211724,0.563096 0.211724,0.225238 0.549581,0.342362 0.337858,0.112619 0.707249,0.112619 0.252266,0 0.527057,-0.08109 0.279295,-0.08109 0.473,-0.261276 0.19821,-0.180191 0.19821,-0.477505 0,-0.252267 -0.153162,-0.445972 -0.153162,-0.193705 -0.396419,-0.355876 -0.243258,-0.162172 -0.518048,-0.315334 -0.274791,-0.157667 -0.518048,-0.328848 -0.243258,-0.175686 -0.39642,-0.38741 -0.153162,-0.216228 -0.153162,-0.500029 0,-0.333352 0.193705,-0.590124 0.193705,-0.261276 0.536067,-0.405429 0.342362,-0.148657 0.783829,-0.148657 0.39642,0 0.67121,0.121629 0.279296,0.121628 0.423448,0.306324 0.148658,0.184695 0.148658,0.373895 0,0.243258 -0.126134,0.355877 -0.121628,0.108114 -0.279295,0.108114 -0.166677,0 -0.297315,-0.103609 -0.126133,-0.108115 -0.126133,-0.328848 0,-0.175686 0.117124,-0.297315 0.121628,-0.126133 0.306324,-0.126133 0.1892,0 0.292809,0.112619 0.10361,0.108114 0.10361,0.279295 h -0.009 q 0,-0.184695 -0.144153,-0.364886 -0.139648,-0.18019 -0.414438,-0.297314 -0.270286,-0.121629 -0.666706,-0.121629 -0.229743,0 -0.482009,0.06757 -0.247762,0.06757 -0.423448,0.220733 -0.171181,0.153162 -0.171181,0.418943 0,0.225239 0.148657,0.39642 0.153162,0.171181 0.391914,0.319838 0.238753,0.144152 0.504534,0.29281 0.270286,0.148657 0.509039,0.328848 0.238752,0.18019 0.387409,0.414438 0.153162,0.234248 0.153162,0.558591 0,0.400924 -0.234247,0.689229 -0.234248,0.2838 -0.599134,0.436962 -0.364886,0.153162 -0.756801,0.153162 z"
- style="stroke-width:0.141883;stroke-linejoin:round"
+ style="stroke-width:0.14236632;stroke-linejoin:round;stroke-dasharray:none"
id="path7627" />
<path
d="m 52.757206,31.688833 q -0.279295,0 -0.454981,-0.09009 -0.175686,-0.08559 -0.261277,-0.225238 -0.08109,-0.144153 -0.08109,-0.297315 0,-0.07208 0.02252,-0.202714 0.02252,-0.130639 0.05856,-0.265782 l 1.099163,-4.054288 h 0.720762 l -1.297372,4.716489 q -0.01351,0.04505 -0.02703,0.108114 -0.01351,0.05856 -0.01351,0.121629 0,0.162171 0.279296,0.162171 0.243257,0 0.459486,-0.0991 0.220733,-0.10361 0.409933,-0.297315 0.193705,-0.19821 0.360382,-0.48201 0.171181,-0.288305 0.315333,-0.657695 l 0.01351,0.0045 q -0.193705,0.495525 -0.432457,0.846896 -0.234248,0.346867 -0.527058,0.531562 -0.288305,0.180191 -0.644181,0.180191 z m -0.76581,-4.21646 v -0.01802 h 2.432573 v 0.01802 z"
- style="stroke-width:0.141883;stroke-linejoin:round"
+ style="stroke-width:0.14236632;stroke-linejoin:round;stroke-dasharray:none"
id="path7629" />
<path
d="m 56.005134,31.688833 q -0.432457,0 -0.729772,-0.180191 -0.297314,-0.184695 -0.450476,-0.509038 -0.153162,-0.324343 -0.153162,-0.752296 0,-0.518048 0.1892,-1.027086 0.1892,-0.513543 0.531562,-0.932487 0.342362,-0.418943 0.801848,-0.67121 0.463991,-0.252266 1.004563,-0.252266 0.486515,0 0.752296,0.243257 0.270286,0.238753 0.270286,0.594629 0,0.369391 -0.252267,0.648686 -0.252267,0.279296 -0.675715,0.473 -0.418943,0.189201 -0.927982,0.297315 -0.504533,0.108114 -1.018077,0.144152 v -0.01802 q 0.409934,-0.02703 0.752296,-0.0991 0.346867,-0.07658 0.612648,-0.20722 0.270286,-0.130638 0.454982,-0.324343 0.1892,-0.198209 0.288305,-0.473 0.0991,-0.274791 0.0991,-0.635172 0,-0.229743 -0.09009,-0.427953 -0.08559,-0.198209 -0.328848,-0.198209 -0.256771,0 -0.491019,0.153162 -0.229743,0.153162 -0.432458,0.418943 -0.198209,0.261276 -0.360381,0.599134 -0.162171,0.333352 -0.279295,0.702743 -0.112619,0.369391 -0.175686,0.734277 -0.05856,0.364886 -0.05856,0.684724 0,0.5676 0.207219,0.77482 0.211724,0.207219 0.527058,0.207219 0.400924,0 0.734276,-0.166677 0.337858,-0.166676 0.599134,-0.441467 0.265781,-0.279295 0.441467,-0.617152 l 0.01351,0.0045 q -0.175685,0.342363 -0.445971,0.626163 -0.265782,0.2838 -0.621658,0.454981 -0.351372,0.171181 -0.788334,0.171181 z"
- style="stroke-width:0.141883;stroke-linejoin:round"
+ style="stroke-width:0.14236632;stroke-linejoin:round;stroke-dasharray:none"
id="path7631" />
</g>
</g>
@@ -544,7 +544,7 @@
id="path7795" />
</g>
<rect
- style="fill:none;stroke:#000000;stroke-width:0.0999999;stroke-linecap:round;stroke-dasharray:none"
+ style="fill:none;stroke:#000000;stroke-width:0.09;stroke-linecap:round;stroke-dasharray:none"
id="rect5087"
width="79.900002"
height="159.89999"
diff --git a/gerbolyze/tests/test_integration.py b/gerbolyze/tests/test_integration.py
index 668e745..7456e85 100644
--- a/gerbolyze/tests/test_integration.py
+++ b/gerbolyze/tests/test_integration.py
@@ -20,6 +20,7 @@ import subprocess
import tempfile
from pathlib import Path
+import gerbonara
import pytest
@@ -67,7 +68,20 @@ def test_convert_layers():
infile = reference_path('layers.svg')
with tempfile.TemporaryDirectory() as out_dir:
run_command('python3', '-m', 'gerbolyze', 'convert', infile, out_dir)
- out_dir = Path(out_dir)
- print(list(out_dir.glob('*')))
- assert False
+ stack = gerbonara.layers.LayerStack.open(out_dir)
+ for layer, dia in {
+ 'top paste': 0.100,
+ 'top silk': 0.110,
+ 'top mask': 0.120,
+ 'top copper': 0.130,
+ 'bottom copper': 0.140,
+ 'bottom mask': 0.150,
+ 'bottom silk': 0.160,
+ 'bottom paste': 0.170,
+ 'mechanical outline': 0.09}.items():
+ assert set(round(ap.diameter, 4) for ap in stack[layer].apertures) == {dia, 0.05}
+
+ # Note: svg-flatten rounds these diameters to the geometric tolerance given on the command line (0.01mm by
+ # default). Thus, these values are different from the more precise values in the SVG.
+ assert set(stack.drill_layers[0].drill_sizes()) == {0.67, 0.51}
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);