jpt13653903 / Gerber2PDF

Gerber to PDF converter
https://sourceforge.net/projects/gerber2pdf/
GNU General Public License v3.0
36 stars 11 forks source link

Copper Plane Tearing #26

Closed jpt13653903 closed 9 months ago

jpt13653903 commented 9 months ago

Originally reported in #23 by @JonThe640

The copper plane seems to tear in the PDF output:

PDF Output

jpt13653903 commented 9 months ago

This issue is related to rounding errors and how the Gerber is defined. Instead of following Gerber best practices (i.e. draw a solid copper pour and then cut holes into it with a negative layer), your CAD tool does a manual draw. I made a minimal example to show the problem (I've added white-space for readability, with comments at the end of each line):

G01                                       * Move to origin
G36                                       * Turn on Outline Fill mode
    X19685  Y1021260                  D02 * Move to          (0.019685, 1.021260)
G02 X31495  Y1039300  I19685          D01 * Clockwise arc to (0.031495, 1.039300)
G01         Y0893700                      * Line to          (0.031495, 0.893700)
G03 X43306  Y0881890  I11810              * CCW arc ...
    X55117  Y0893700          J11810      * CCW arc ...
    X43306  Y0905511  I11811              * CCW arc ...
    X31495  Y0893700          J11810      * CCW arc to       (0.031495, 0.893700)
G01         Y0929133                      * Line to          (0.031495, 0.929133)
G03 X43306  Y0917322  I11810              * CCW arc ...
    X55117  Y0929133          J11810      * CCW arc ...
    X43306  Y0940945  I11811              * CCW arc ...
    X31495  Y0929133          J11811      * CCW arc to       (0.031495, 0.929133)
G01         Y0976377                      * Line to          (0.031495, 0.976377)
G01 X60000                                * Line to          (0.060000, 0.976377)
G01         Y850000                       * Line to          (0.060000, 0.850000)
G01 X19685                                * Line to          (0.019685, 0.850000)

This renders as follows in ViewMate:

ViewMateOutput

Now -- the generated PDF (I added white-space for readability and converted the mm back to inches in the comments):

                                                                           q    | Push graphics state
0.499999     25.940004                                                     m    | Move to   (0.019685, 1.021260)
0.499999     26.03728444 0.5283785237 26.13245543 0.5816579945 26.21384819 c    | Bézier ...
0.6349374653 26.29524095 0.7108062443 26.35932561 0.799962159  26.39824483 c    | Bézier to (0.031495, 1.039300)
0.799973     22.69998                                                      l    | Line to   (0.031495, 0.893700)
0.799973     22.75930739 0.8175659611 22.81730471 0.8505259706 22.86663399 c    | Bézier ...
0.8834859801 22.91596326 0.9303351732 22.95441264 0.9851460535 22.97711741 c    | Bézier ...
1.039956934  22.99982218 1.100271884  23.00576429 1.158459682  22.99419194 c    | Bézier ...
1.21664748   22.98261959 1.270099094  22.95405165 1.312051669  22.91210263 c    | Bézier ...
1.354004245  22.87015361 1.382576707  22.81670441 1.394153986  22.75851759 c    | Bézier ...
1.405731265  22.70033078 1.399794257  22.64001532 1.377094128  22.58520252 c    | Bézier ...
1.354394     22.53038972 1.315948583  22.48353727 1.266622104  22.45057308 c    | Bézier ...
1.217295625  22.4176089  1.159299789  22.40001102 1.0999724    22.400006   c    | Bézier ...
1.179527116  22.400006   1.255832369  22.43161267 1.312086049  22.48786635 c    | Bézier ...
1.368339728  22.54412003 1.399946399  22.62042528 1.399946399  22.69998    c    | Bézier ...
1.399946399  22.77953472 1.368339728  22.85583997 1.312086049  22.91209365 c    | Bézier ...
1.255832369  22.96834733 1.179527116  22.999954   1.0999724    22.999954   c    | Bézier ...
1.053397483  22.999954   1.007461565  23.01079841 0.9658040454 23.03162805 c    | Bézier to (0.031495, 0.893700)
0.799973     23.5999782                                                    l    | Line to   (0.031495, 0.929133)
0.799973     23.65930559 0.8175659611 23.71730291 0.8505259707 23.76663219 c    | Bézier ...
0.8834859803 23.81596146 0.9303351736 23.85441084 0.9851460539 23.87711561 c    | Bézier ...
1.039956934  23.89982038 1.100271885  23.90576249 1.158459683  23.89419014 c    | Bézier ...
1.216647481  23.88261779 1.270099095  23.85404985 1.31205167   23.81210083 c    | Bézier ...
1.354004245  23.77015181 1.382576708  23.71670261 1.394153986  23.65851579 c    | Bézier ...
1.405731265  23.60032897 1.399794256  23.54001352 1.377094128  23.48520072 c    | Bézier ...
1.354393999  23.43038792 1.315948582  23.38353547 1.266622102  23.35057128 c    | Bézier ...
1.217295623  23.3176071  1.159299787  23.30000922 1.099972398  23.3000042  c    | Bézier ...
1.040650032  23.3000042  0.9826576178 23.31759567 0.9333325247 23.35055289 c    | Bézier ...
0.8840074316 23.38351011 0.8455613038 23.43035534 0.8228584575 23.48516158 c    | Bézier ...
0.8001556112 23.53996782 0.7942139994 23.60027766 0.8057853719 23.65846053 c    | Bézier ...
0.8173567445 23.7166434  0.845922263  23.77009049 0.8878677347 23.81203951 c    | Bézier ...
0.9298132064 23.85398853 0.9832578753 23.88255858 1.041439766  23.89413487 c    | Bézier ...
1.099621657  23.90571117 1.159932003  23.89977467 1.214740164  23.87707646 c    | Bézier ...
1.269548325  23.85437825 1.316396806  23.81593609 1.3493582    23.76661379 c    | Bézier ...
1.382319595  23.71729148 1.399915976  23.65930056 1.399920998  23.59997819 c    | Bézier ...
1.399921     23.67952617 1.368317007  23.75582497 1.312068092  23.81207388 c    | Bézier ...
1.255819177  23.8683228  1.179520386  23.8999268  1.099972406  23.8999268  c    | Bézier ...
1.053389092  23.8999268  1.007444797  23.91077236 0.9657790615 23.93160435 c    | Bézier to (0.031495, 0.929133)
0.799973     24.7999758                                                    l    | Line to   (0.031495, 0.976377)
1.524        24.7999758                                                    l    | Line to   (0.060000, 0.976377)
1.524        21.59                                                         l    | Line to   (0.060000, 0.850000)
0.499999     21.59                                                         l    | Line to   (0.019685, 0.850000)
                                                                           h    | Close the current path
                                                                           f*   | Fill the path using even-odd fill rule
                                                                           Q    | Pop graphics state

The rounding error is especially evident on line 4. Instead of the correct coordinate (0.799973, 26.39822), the Bézier is drawn to (0.799962159, 26.39824483).

You'll also notice that some of the Bézier curves end in completely the wrong place -- I'll investigate that first before fixing the rounding errors. Converting inches to mm should be exact, so there shouldn't be rounding errors (as is evident in the "line to" command on line 5).

This renders as follows in Acrobat Reader:

AcrobatOutput

jpt13653903 commented 9 months ago

I found the cause...

In the Gerber, the line G03 X43306 Y881890 I11810 means "Draw an arc to coordinate (0.043306, 0.881890) with a centre offset from the starting coordinate of 0.011810". But... The starting coordinate (from the previous lines) are (0.031495, 0.893700).

The arc is 90 deg counter-clockwise, so if you add the center offset to X and Y, you "should" end up at (0.043305, 0.881890). That 0.000001 error is enough to cause confusion in my converter. I'll make it more robust to Gerber errors and push an update.

JonThe640 commented 9 months ago

all work now! thanks!

jpt13653903 commented 9 months ago

Pleasure :-)