From 27cbe491bbd85bb4a6d8704e03b22e51461080a6 Mon Sep 17 00:00:00 2001 From: Mike Cousins Date: Mon, 11 Aug 2014 08:42:35 -0400 Subject: [PATCH] fix flipped pad hole dimensions --- dist/gerber-to-svg.js | 16 ++++++++-------- dist/gerber-to-svg.min.js | 2 +- lib/plotter.js | 16 ++++++++-------- src/plotter.coffee | 16 ++++++++-------- test/plotter_test.coffee | 16 ++++++++-------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/dist/gerber-to-svg.js b/dist/gerber-to-svg.js index 979e0dc..22ddc5e 100755 --- a/dist/gerber-to-svg.js +++ b/dist/gerber-to-svg.js @@ -1088,8 +1088,8 @@ parseAD = function(block) { }; if (mods.length > 2) { params.hole = { - width: parseFloat(mods[2]), - height: parseFloat(mods[1]) + width: parseFloat(mods[1]), + height: parseFloat(mods[2]) }; } else if (mods.length > 1) { params.hole = { @@ -1106,8 +1106,8 @@ parseAD = function(block) { }; if (mods.length > 3) { params.hole = { - width: parseFloat(mods[3]), - height: parseFloat(mods[2]) + width: parseFloat(mods[2]), + height: parseFloat(mods[3]) }; } else if (mods.length > 2) { params.hole = { @@ -1124,8 +1124,8 @@ parseAD = function(block) { }; if (mods.length > 3) { params.hole = { - width: parseFloat(mods[3]), - height: parseFloat(mods[2]) + width: parseFloat(mods[2]), + height: parseFloat(mods[3]) }; } else if (mods.length > 2) { params.hole = { @@ -1146,8 +1146,8 @@ parseAD = function(block) { } if (mods.length > 4) { params.hole = { - width: parseFloat(mods[4]), - height: parseFloat(mods[3]) + width: parseFloat(mods[3]), + height: parseFloat(mods[4]) }; } else if (mods.length > 3) { params.hole = { diff --git a/dist/gerber-to-svg.min.js b/dist/gerber-to-svg.min.js index 593a436..ba1c409 100755 --- a/dist/gerber-to-svg.min.js +++ b/dist/gerber-to-svg.min.js @@ -1 +1 @@ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.gerberToSvg=t()}}(function(){return function t(e,r,i){function o(s,h){if(!r[s]){if(!e[s]){var a="function"==typeof require&&require;if(!h&&a)return a(s,!0);if(n)return n(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var u=r[s]={exports:{}};e[s][0].call(u.exports,function(t){var r=e[s][1][t];return o(r?r:t)},u,u.exports,t,e,r,i)}return r[s].exports}for(var n="function"==typeof require&&require,s=0;s=" "&&"~">=e?r+=e:"\n"===e&&this.line++;this.index++}return t},t}(),e.exports=r},{}],3:[function(t,e){var r,i,o,n,s,h;i=/[\+-\/x\(\)]/,r=/[\$\d\.]+/,o=new RegExp("("+i.source+")|("+r.source+")","g"),h=function(t){var e;return e=t.match(o)},n=function(t){return r.test(t)},s=function(t){var e,r,i,o,s,a,l;return l=h(t),r=0,a=function(){return l[r]},e=function(t){return t===a()?r++:void 0},s=function(){var t,r;if(r=a(),e(r),n(r))t={type:"n",val:r};else{if("("!==r)throw new SytaxError(""+r+" is unexpected in an arithmetic string");if(t=i(),")"!==a())throw new SytaxError("expected ')'");e(")")}return t},o=function(){var t,r,i;for(t=s(),i=a();"x"===i||"/"===i;)e(i),r=s(),t={type:i,left:t,right:r},i=a();return t},(i=function(){var t,r,i;for(t=o(),i=a();"+"===i||"-"===i;)e(i),r=o(),t={type:i,left:t,right:r},i=a();return t})()},e.exports={tokenize:h,isNumber:n,parse:s}},{}],4:[function(t,e){var r,i,o,n;o=t("./pad-shapes"),i=t("./macro-calc"),n=t("./unique-id"),r=function(){function t(t){this.modifiers={},this.name=t[0].slice(2),this.blocks=t.slice(1),this.shapes=[],this.masks=[],this.bbox=[null,null,null,null]}return t.prototype.run=function(t,e){var r,i,o,s,h,a,l,u,c,x,f,p,d,y,b,w,g,m,v;for(null==e&&(e=[]),o=c=0,d=e.length;d>c;o=++c)s=e[o],this.modifiers["$"+(o+1)]=s;for(g=this.blocks,x=0,y=g.length;y>x;x++)r=g[x],this.runBlock(r);for(a="tool-"+t+"-pad-"+n(),h=[],m=this.masks,f=0,b=m.length;b>f;f++)s=m[f],h.push(s);if(this.shapes.length>1){for(i={id:a,_:[]},v=this.shapes,p=0,w=v.length;w>p;p++)l=v[p],i._.push(l);h=[{g:i}]}else 1===this.shapes.length&&(u=Object.keys(this.shapes[0])[0],this.shapes[0][u].id=a,h.push(this.shapes[0]));return{pad:h,padId:a,bbox:this.bbox,trace:!1}},t.prototype.runBlock=function(t){var e,r,i,o,n,s,h,a;switch(t[0]){case"$":return o=null!=(a=t.match(/^\$\d+(?=\=)/))?a[0]:void 0,n=t.slice(1+o.length),this.modifiers[o]=this.getNumber(n);case"1":case"2":case"20":case"21":case"22":case"4":case"5":case"6":case"7":for(r=t.split(","),i=s=0,h=r.length;h>s;i=++s)e=r[i],r[i]=this.getNumber(e);return this.primitive(r);default:if("0"!==t[0])throw new SyntaxError("'"+t+"' unrecognized tool macro block")}},t.prototype.primitive=function(t){var e,r,i,s,h,a,l,u,c,x,f,p,d,y,b,w,g,m,v,M,k,E,S,q,R,I,T,D,F;switch(h=!1,c=!1,f=null,t[0]){case 1:f=o.circle({dia:t[2],cx:t[3],cy:t[4]}),0===t[1]?h=!0:this.addBbox(f.bbox);break;case 2:case 20:f=o.vector({width:t[2],x1:t[3],y1:t[4],x2:t[5],y2:t[6]}),t[7]&&(f.shape.line.transform="rotate("+t[7]+")"),0===t[1]?h=!0:this.addBbox(f.bbox,t[7]);break;case 21:f=o.rect({cx:t[4],cy:t[5],width:t[2],height:t[3]}),t[6]&&(f.shape.rect.transform="rotate("+t[6]+")"),0===t[1]?h=!0:this.addBbox(f.bbox,t[6]);break;case 22:f=o.lowerLeftRect({x:t[4],y:t[5],width:t[2],height:t[3]}),t[6]&&(f.shape.rect.transform="rotate("+t[6]+")"),0===t[1]?h=!0:this.addBbox(f.bbox,t[6]);break;case 4:for(l=[],r=p=3,S=3+2*t[2];S>=p;r=p+=2)l.push([t[r],t[r+1]]);f=o.outline({points:l}),(u=t[t.length-1])&&(f.shape.polygon.transform="rotate("+u+")"),0===t[1]?h=!0:this.addBbox(f.bbox,t[t.length-1]);break;case 5:if(0!==t[6]&&(0!==t[3]||0!==t[4]))throw new RangeError("polygon center must be 0,0 if rotated in macro");f=o.polygon({cx:t[3],cy:t[4],dia:t[5],verticies:t[2],degrees:t[6]}),0===t[1]?h=!0:this.addBbox(f.bbox);break;case 6:if(0!==t[9]&&(0!==t[1]||0!==t[2]))throw new RangeError("moiré center must be 0,0 if rotated in macro");if(f=o.moire({cx:t[1],cy:t[2],outerDia:t[3],ringThx:t[4],ringGap:t[5],maxRings:t[6],crossThx:t[7],crossLength:t[8]}),t[9])for(q=f.shape,d=0,w=q.length;w>d;d++)x=q[d],null!=x.line&&(x.line.transform="rotate("+t[9]+")");this.addBbox(f.bbox,t[9]);break;case 7:if(0!==t[9]&&(0!==t[1]||0!==t[2]))throw new RangeError("thermal center must be 0,0 if rotated in macro");if(f=o.thermal({cx:t[1],cy:t[2],outerDia:t[3],innerDia:t[4],gap:t[5]}),t[6])for(R=f.shape,y=0,g=R.length;g>y;y++)if(x=R[y],null!=x.mask)for(I=x.mask._,b=0,m=I.length;m>b;b++)s=I[b],null!=s.rect&&(s.rect.transform="rotate("+t[6]+")");this.addBbox(f.bbox,t[6]);break;default:throw new SyntaxError(""+t[0]+" is not a valid primitive code")}if(h){for(i in f.shape)f.shape[i].fill="#000";if(a="macro-"+this.name+"-mask-"+n(),s={mask:{id:a,_:[{rect:{x:this.bbox[0],y:this.bbox[1],width:this.bbox[2]-this.bbox[0],height:this.bbox[3]-this.bbox[1],fill:"#fff"}},f.shape]}},1===this.shapes.length)for(i in this.shapes[0])this.shapes[0][i].mask="url(#"+a+")";else if(this.shapes.length>1){for(e={mask:"url(#"+a+")",_:[]},T=this.shapes,k=0,v=T.length;v>k;k++)x=T[k],e._.push(x);this.shapes=[{g:e}]}return this.masks.push(s)}if(Array.isArray(f.shape)){for(D=f.shape,F=[],E=0,M=D.length;M>E;E++)x=D[E],F.push(null!=x.mask?this.masks.push(x):this.shapes.push(x));return F}return this.shapes.push(f.shape)},t.prototype.addBbox=function(t,e){var r,i,o,n,s,h,a,l,u;if(null==e&&(e=0),e){for(n=Math.sin(e*Math.PI/180),r=Math.cos(e*Math.PI/180),Math.abs(n)<1e-9&&(n=0),Math.abs(r)<1e-9&&(r=0),o=[[t[0],t[1]],[t[2],t[1]],[t[2],t[3]],[t[0],t[3]]],u=[],a=0,l=o.length;l>a;a++)i=o[a],s=i[0]*r-i[1]*n,h=i[0]*n+i[1]*r,(null===this.bbox[0]||sthis.bbox[2])&&(this.bbox[2]=s),u.push(null===this.bbox[3]||h>this.bbox[3]?this.bbox[3]=h:void 0);return u}return(null===this.bbox[0]||t[0]this.bbox[2])&&(this.bbox[2]=t[2]),null===this.bbox[3]||t[3]>this.bbox[3]?this.bbox[3]=t[3]:void 0},t.prototype.getNumber=function(t){return t.match(/^[+-]?[\d.]+$/)?parseFloat(t):t.match(/^\$\d+$/)?parseFloat(this.modifiers[t]):this.evaluate(i.parse(t))},t.prototype.evaluate=function(t){switch(t.type){case"n":return this.getNumber(t.val);case"+":return this.evaluate(t.left)+this.evaluate(t.right);case"-":return this.evaluate(t.left)-this.evaluate(t.right);case"x":return this.evaluate(t.left)*this.evaluate(t.right);case"/":return this.evaluate(t.left)/this.evaluate(t.right)}},t}(),e.exports=r},{"./macro-calc":3,"./pad-shapes":6,"./unique-id":9}],5:[function(t,e){var r,i,o,n;n=function(t,e){var r;if(r="",0===e)return"";for(;e>1;)1&e&&(r+=t),e>>=1,t+=t;return r+t},r="_",i=" ",o=function(t,e){var s,h,a,l,u,c,x,f,p,d,y,b,w,g,m;if(null==e&&(e={}),f=e.pretty,l=null!=(g=e.indent)?g:0,c=f?"\n":"",p=c?"string"==typeof f?f:i:"",p=n(p,l),y="",Array.isArray(t))for(a=b=0,w=t.length;w>b;a=++b)x=t[a],y+=(0!==a?c:"")+o(x,e);else if(s=!1,h=Object.keys(t)[0],null!=h){y=""+p+"<"+h,m=t[h];for(u in m)d=m[u],u===r?s=d:y+=" "+u+'="'+d+'"';s&&(y+=">"+c+o(s,{pretty:f,indent:l+1})),y+=null!=t[h]._?""+c+p+"":"/>"}return y},e.exports=o},{}],6:[function(t,e){var r,i,o,n,s,h,a,l,u;l=t("./unique-id"),r=function(t){var e;if(null==t.dia)throw new SyntaxError("circle function requires diameter");if(null==t.cx)throw new SyntaxError("circle function requires x center");if(null==t.cy)throw new SyntaxError("circle function requires y center");return e=t.dia/2,{shape:{circle:{cx:t.cx,cy:t.cy,r:e,"stroke-width":0,fill:"currentColor"}},bbox:[t.cx-e,t.cy-e,t.cx+e,t.cy+e]}},h=function(t){var e,r,i,o;if(null==t.width)throw new SyntaxError("rectangle requires width");if(null==t.height)throw new SyntaxError("rectangle requires height");if(null==t.cx)throw new SyntaxError("rectangle function requires x center");if(null==t.cy)throw new SyntaxError("rectangle function requires y center");return i=t.cx-t.width/2,o=t.cy-t.height/2,r={shape:{rect:{x:i,y:o,width:t.width,height:t.height,"stroke-width":0,fill:"currentColor"}},bbox:[i,o,i+t.width,o+t.height]},t.obround&&(e=.5*Math.min(t.width,t.height),r.shape.rect.rx=e,r.shape.rect.ry=e),r},s=function(t){var e,r,i,o,n,s,h,a,l,u,c,x,f,p,d,y;if(null==t.dia)throw new SyntaxError("polygon requires diameter");if(null==t.verticies)throw new SyntaxError("polygon requires verticies");if(null==t.cx)throw new SyntaxError("polygon function requires x center");if(null==t.cy)throw new SyntaxError("polygon function requires y center");for(s=null!=t.degrees?t.degrees*Math.PI/180:0,h=2*Math.PI/t.verticies,i=t.dia/2,r="",c=null,p=null,u=null,f=null,e=d=0,y=t.verticies;y>=0?y>d:d>y;e=y>=0?++d:--d)a=s+e*h,o=i*Math.cos(a),n=i*Math.sin(a),Math.abs(o)<1e-9&&(o=0),Math.abs(n)<1e-9&&(n=0),l=t.cx+o,x=t.cy+n,(c>l||null===c)&&(c=l),(l>u||null===u)&&(u=l),(p>x||null===p)&&(p=x),(x>f||null===f)&&(f=x),r+=" "+l+","+x;return{shape:{polygon:{points:r.slice(1),"stroke-width":0,fill:"currentColor"}},bbox:[c,p,u,f]}},u=function(t){var e,r,i;if(null==t.x1)throw new SyntaxError("vector function requires start x");if(null==t.y1)throw new SyntaxError("vector function requires start y");if(null==t.x2)throw new SyntaxError("vector function requires end x");if(null==t.y2)throw new SyntaxError("vector function requires end y");if(null==t.width)throw new SyntaxError("vector function requires width");return e=Math.abs(Math.atan((t.y2-t.y1)/(t.x2-t.x1))),r=t.width/2*Math.sin(e),i=t.width/2*Math.cos(e),1e-7>r&&(r=0),1e-7>i&&(i=0),{shape:{line:{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,"stroke-width":t.width,stroke:"currentColor"}},bbox:[Math.min(t.x1,t.x2)-r,Math.min(t.y1,t.y2)-i,Math.max(t.x1,t.x2)+r,Math.max(t.y1,t.y2)+i]}},i=function(t){if(null==t.width)throw new SyntaxError("lower left rect requires width");if(null==t.height)throw new SyntaxError("lower left rect requires height");if(null==t.x)throw new SyntaxError("lower left rectangle requires x");if(null==t.y)throw new SyntaxError("lower left rectangle requires y");return{shape:{rect:{x:t.x,y:t.y,width:t.width,height:t.height,"stroke-width":0,fill:"currentColor"}},bbox:[t.x,t.y,t.x+t.width,t.y+t.height]}},n=function(t){var e,r,i,o,n,s,h,a,l,u,c,x,f;if(!(Array.isArray(t.points)&&t.points.length>1))throw new SyntaxError("outline function requires points array");for(s=null,u=null,n=null,l=null,r="",f=t.points,c=0,x=f.length;x>c;c++){if(e=f[c],!Array.isArray(e)||2!==e.length)throw new SyntaxError("outline function requires points array");i=e[0],h=e[1],(s>i||null===s)&&(s=i),(i>n||null===n)&&(n=i),(u>h||null===u)&&(u=h),(h>l||null===l)&&(l=h),r+=" "+i+","+h}if(o=t.points[t.points.length-1][0],a=t.points[t.points.length-1][1],o!==t.points[0][0]||a!==t.points[0][1])throw new RangeError("last point must match first point of outline");return{shape:{polygon:{points:r.slice(1),"stroke-width":0,fill:"currentColor"}},bbox:[s,u,n,l]}},o=function(t){var e,r,i;if(null==t.cx)throw new SyntaxError("moiré requires x center");if(null==t.cy)throw new SyntaxError("moiré requires y center");if(null==t.outerDia)throw new SyntaxError("moiré requires outer diameter");if(null==t.ringThx)throw new SyntaxError("moiré requires ring thickness");if(null==t.ringGap)throw new SyntaxError("moiré requires ring gap");if(null==t.maxRings)throw new SyntaxError("moiré requires max rings");if(null==t.crossLength)throw new SyntaxError("moiré requires crosshair length");if(null==t.crossThx)throw new SyntaxError("moiré requires crosshair thickness");for(i=[{line:{x1:t.cx-t.crossLength/2,y1:0,x2:t.cx+t.crossLength/2,y2:0,"stroke-width":t.crossThx,stroke:"currentColor"}},{line:{x1:0,y1:t.cy-t.crossLength/2,x2:0,y2:t.cy+t.crossLength/2,"stroke-width":t.crossThx,stroke:"currentColor"}}],e=(t.outerDia-t.ringThx)/2,r=0;e>=t.ringThx&&r<=t.maxRings;)i.push({circle:{cx:t.cx,cy:t.cy,r:e,fill:"none","stroke-width":t.ringThx,stroke:"currentColor"}}),r++,e-=t.ringThx+t.ringGap;return e>0&&r<=t.maxRings&&i.push({circle:{cx:t.cx,cy:t.cy,r:e,"stroke-width":0,fill:"currentColor"}}),{shape:i,bbox:[Math.min(t.cx-t.crossLength/2,t.cx-t.outerDia/2),Math.min(t.cy-t.crossLength/2,t.cy-t.outerDia/2),Math.max(t.cx+t.crossLength/2,t.cx+t.outerDia/2),Math.max(t.cy+t.crossLength/2,t.cy+t.outerDia/2)]}},a=function(t){var e,r,i,o,n,s,h,a,u;if(null==t.cx)throw new SyntaxError("thermal requires x center");if(null==t.cy)throw new SyntaxError("thermal requires y center");if(null==t.outerDia)throw new SyntaxError("thermal requires outer diameter");if(null==t.innerDia)throw new SyntaxError("thermal requires inner diameter");if(null==t.gap)throw new SyntaxError("thermal requires gap");return r="thermal-mask-"+l(),n=(t.outerDia-t.innerDia)/2,i=t.outerDia/2,o=i-n/2,h=t.cx-i,s=t.cx+i,u=t.cy-i,a=t.cy+i,e=t.gap/2,{shape:[{mask:{id:r,_:[{circle:{cx:t.cx,cy:t.cy,r:i,"stroke-width":0,fill:"#fff"}},{rect:{x:h,y:-e,width:t.outerDia,height:t.gap,"stroke-width":0,fill:"#000"}},{rect:{x:-e,y:u,width:t.gap,height:t.outerDia,"stroke-width":0,fill:"#000"}}]}},{circle:{cx:t.cx,cy:t.cy,r:o,fill:"none","stroke-width":n,stroke:"currentColor",mask:"url(#"+r+")"}}],bbox:[h,u,s,a]}},e.exports={circle:r,rect:h,polygon:s,vector:u,lowerLeftRect:i,outline:n,moire:o,thermal:a}},{"./unique-id":9}],7:[function(t,e){var r,i,o,n,s,h;i=t("./gerber-parser"),h=t("./unique-id"),r=t("./macro-tool"),s=t("./standard-tool"),n=function(t){var e,r,i,o,n,h,a,l,u,c;if(i=null!=(l=t.match(/^ADD\d+/))&&null!=(u=l[0])?u.slice(2):void 0,!(null!=i&&parseInt(i.slice(1),10)>9))throw new SyntaxError(""+i+" is an invalid tool code (must be >= 10)");switch(e=null,r=!1,t.slice(2+i.length,4+i.length)){case"C,":n=t.slice(4+i.length).split("X"),a={dia:parseFloat(n[0])},n.length>2?a.hole={width:parseFloat(n[2]),height:parseFloat(n[1])}:n.length>1&&(a.hole={dia:parseFloat(n[1])}),e=s(i,a);break;case"R,":n=t.slice(4+i.length).split("X"),a={width:parseFloat(n[0]),height:parseFloat(n[1])},n.length>3?a.hole={width:parseFloat(n[3]),height:parseFloat(n[2])}:n.length>2&&(a.hole={dia:parseFloat(n[2])}),e=s(i,a);break;case"O,":n=t.slice(4+i.length).split("X"),a={width:parseFloat(n[0]),height:parseFloat(n[1])},n.length>3?a.hole={width:parseFloat(n[3]),height:parseFloat(n[2])}:n.length>2&&(a.hole={dia:parseFloat(n[2])}),a.obround=!0,e=s(i,a);break;case"P,":n=t.slice(4+i.length).split("X"),a={dia:parseFloat(n[0]),verticies:parseFloat(n[1])},null!=n[2]&&(a.degrees=parseFloat(n[2])),n.length>4?a.hole={width:parseFloat(n[4]),height:parseFloat(n[3])}:n.length>3&&(a.hole={dia:parseFloat(n[3])}),e=s(i,a);break;default:if(o=t.slice(2+i.length),h=null!=(c=o.match(/[a-zA-Z_$][a-zA-Z_$.0-9]{0,126}(?=,)?/))?c[0]:void 0,!h)throw new SyntaxError("invalid definition with macro");n=o.slice(h.length+1).split("X"),1===n.length&&""===n[0]&&(n=null),r={name:h,mods:n}}return{macro:r,tool:e,code:i}},o=function(){function t(t){null==t&&(t=""),this.parser=new i(t),this.macros={},this.tools={},this.currentTool="",this.defs=[],this.gerberId="gerber-"+h(),this.group={g:{id:""+this.gerberId+"-layer-0",_:[]}},this.layer={level:0,type:"g",current:this.group},this.stepRepeat={x:1,y:1,xStep:null,yStep:null,block:0},this.done=!1,this.units=null,this.format={set:!1,zero:null,notation:null,places:null},this.position={x:0,y:0},this.mode=null,this.trace={region:!1,path:""},this.quad=null,this.bbox={xMin:1/0,yMin:1/0,xMax:-1/0,yMax:-1/0}}return t.prototype.plot=function(){for(var t;!this.done;)t=this.parser.nextCommand(),"%"===t[0]?this.parameter(t):this.operate(t[0]);return this.finish()},t.prototype.finish=function(){var t,e,r;return this.finishTrace(),this.finishStepRepeat(),e=parseFloat((this.bbox.xMax-this.bbox.xMin).toPrecision(10)),t=parseFloat((this.bbox.yMax-this.bbox.yMin).toPrecision(10)),r={svg:{xmlns:"http://www.w3.org/2000/svg",version:"1.1","xmlns:xlink":"http://www.w3.org/1999/xlink",width:""+e+this.units,height:""+t+this.units,viewBox:""+this.bbox.xMin+" "+this.bbox.yMin+" "+e+" "+t,id:this.gerberId,_:[]}},this.defs.length&&r.svg._.push({defs:{_:this.defs}}),this.group.g.transform="translate(0,"+(this.bbox.yMin+this.bbox.yMax)+") scale(1,-1)",r.svg._.push(this.group),r},t.prototype.parameter=function(t){var e,i,o,s,h,a,l,u,c,x,f,p,d,y,b,w,g,m,v,M,k,E,S,q,R,I,T;if(o=!1,"%"===t[0]&&"%"!==t[t.length-1])throw new SyntaxError("@parameter should only be called with paramters");for(t=t.slice(1),l=0,T=[];!o;){switch(i=t[l],i.slice(0,2)){case"FS":if(u=!1,this.format.set)throw new SyntaxError("format spec cannot be redefined");try{"L"===i[2]||"T"===i[2]?this.format.zero=i[2]:u=!0,"A"===i[3]||"I"===i[3]?this.format.notation=i[3]:u=!0,"X"===i[4]&&"Y"===i[7]&&i.slice(5,7)===i.slice(8,10)?(this.format.places=[parseInt(i[5],10),parseInt(i[6],10)],(this.format.places[0]>7||this.format.places[1]>7)&&(u=!0)):u=!0}catch(D){s=D,u=!0}if(u)throw new SyntaxError("invalid format spec");this.format.set=!0;break;case"MO":if(y=i.slice(2),null!=this.units)throw new SyntaxError("gerber file may not redifine units");if("MM"===y)this.units="mm";else{if("IN"!==y)throw new SyntaxError(""+y+" are unrecognized units");this.units="in"}break;case"AD":if(e=n(t[l]),null!=this.tools[e.code])throw new SyntaxError("duplicate tool code");for(e.macro&&(e.tool=this.macros[e.macro.name].run(e.code,e.macro.mods)),this.tools[e.code]={stroke:e.tool.trace,flash:function(t,r){return{use:{x:t,y:r,"xlink:href":"#"+e.tool.padId}}},bbox:function(t,r){return null==t&&(t=0),null==r&&(r=0),{xMin:t+e.tool.bbox[0],yMin:r+e.tool.bbox[1],xMax:t+e.tool.bbox[2],yMax:r+e.tool.bbox[3]}}},M=e.tool.pad,m=0,v=M.length;v>m;m++)f=M[m],this.defs.push(f);this.currentTool=e.code;break;case"AM":c=new r(t.slice(0,-1)),this.macros[c.name]=c,o=!0;break;case"SR":this.finishTrace(),this.finishStepRepeat(),this.stepRepeat.x=Number(null!=(k=null!=(E=i.match(/X\d+/))?E[0].slice(1):void 0)?k:1),this.stepRepeat.y=Number(null!=(S=null!=(q=i.match(/Y\d+/))?q[0].slice(1):void 0)?S:1),this.stepRepeat.x>1&&(this.stepRepeat.xStep=Number(null!=(R=i.match(/I[\d\.]+/))?R[0].slice(1):void 0)),this.stepRepeat.y>1&&(this.stepRepeat.yStep=Number(null!=(I=i.match(/J[\d\.]+/))?I[0].slice(1):void 0)),(1!==this.stepRepeat.x||1!==this.stepRepeat.y)&&0===this.layer.level&&(d={g:{id:""+this.gerberId+"-sr-block-"+this.stepRepeat.block,_:[]}},this.layer.current[this.layer.type]._.push(d),this.layer.current=d);break;case"LP":if(this.finishTrace(),p=i[2],"D"!==p&&"C"!==p)throw new SyntaxError(""+i+" is an unrecognized level polarity");"D"===p&&"mask"===this.layer.type?(h=""+this.gerberId+"-layer-"+ ++this.layer.level,this.group={g:{id:h,_:[this.group]}},this.layer.current=this.group,this.layer.type="g"):"C"===p&&"g"===this.layer.type&&(x=""+this.gerberId+"-layer-"+ ++this.layer.level,w=this.bbox.xMin,g=this.bbox.yMin,b=this.bbox.xMax-this.bbox.xMin,a=this.bbox.yMax-this.bbox.yMin,c={mask:{id:x,color:"#000",_:[{rect:{x:w,y:g,width:b,height:a,fill:"#fff"}}]}},this.defs.push(c),this.layer.current.g.mask="url(#"+x+")",this.layer.current=this.defs[this.defs.length-1],this.layer.type="mask"),this.position.x=null,this.position.y=null}T.push("%"===t[++l]?o=!0:void 0)}return T},t.prototype.operate=function(t){var e,r,i,o,n,s,h,a,l,u,c,x,f,p,d,y,b,w,g,m,v,M,k,E,S,q,R,I,T,D,F,_,P,C,B,G,L,A,j,N,z;if(g=!1,i=t.slice(0,3),"M"===t[0]){if("M02"===i)this.done=!0,t="";else if("M00"!==i&&"M01"!==i)throw new SyntaxError("invalid operation M code");g=!0}else if("G"===t[0]){if(t.match(/^G0?1/))this.mode="i";else if(t.match(/^G0?2/))this.mode="cw";else if(t.match(/^G0?3(?![67])/))this.mode="ccw";else if("G36"===i)this.finishTrace(),this.trace.region=!0;else if("G37"===i)this.finishTrace(),this.trace.region=!1;else if("G74"===i)this.quad="s";else if("G75"===i)this.quad="m";else if("G70"===i)this.backupUnits="in";else if("G71"===i)this.backupUnits="mm";else if(!i.match(/^G(0?4)|(5[45])|(7[01])|(9[01])/))throw new SyntaxError("invalid operation G code");g=!0}if(d=null!=(D=t.match(/D[1-9]\d{1,}$/))?D[0]:void 0,null!=d){if(this.finishTrace(),null==this.tools[d])throw new SyntaxError("tool "+d+" does not exist");if(this.trace.region)throw new SyntaxError("cannot change tool while region mode is on");this.currentTool=d}if(t.match(/^(G0?[123])?([XYIJ][+-]?\d+){0,4}D0?[123]$/)){if(u=t[t.length-1],o=null!=(F=t.match(/[XYIJ][+-]?\d+/g))?F.join(""):void 0,f={x:this.position.x,y:this.position.y},a=this.move(o),"3"===u)return this.finishTrace(),this.layer.current[this.layer.type]._.push(this.tools[this.currentTool].flash(this.position.x,this.position.y)),this.addBbox(this.tools[this.currentTool].bbox(this.position.x,this.position.y));if("1"===u){if(this.trace.path||(this.trace.path="M"+f.x+" "+f.y,"i"===this.mode&&this.addBbox(this.trace.region?{xMin:f.x,yMin:f.y,xMax:f.x,yMax:f.y}:this.tools[this.currentTool].bbox(f.x,f.y))),null==this.mode&&(this.mode="i"),"i"===this.mode)return this.trace.path+="L"+a.x+" "+a.y,this.addBbox(this.trace.region?{xMin:a.x,yMin:a.y,xMax:a.x,yMax:a.y}:this.tools[this.currentTool].bbox(a.x,a.y));if("cw"===this.mode||"ccw"===this.mode){if(c=Math.sqrt(Math.pow(a.i,2)+Math.pow(a.j,2)),p="cw"===this.mode?0:1,l=0,r=[],b=0,w=0,"s"===this.quad)for(C=[f.x-a.i,f.x+a.i],E=0,R=C.length;R>E;E++)for(n=C[E],B=[f.y-a.j,f.y+a.j],S=0,I=B.length;I>S;S++)s=B[S],h=Math.sqrt(Math.pow(n-a.x,2)+Math.pow(s-a.y,2)),Math.abs(c-h)<1e-7&&r.push({x:n,y:s});else"m"===this.quad&&r.push({x:f.x+a.i,y:f.y+a.j});for(q=0,T=r.length;T>q;q++)if(e=r[q],b=Math.atan2(a.y-e.y,a.x-e.x),0>b&&(b+=2*Math.PI),w=Math.atan2(f.y-e.y,f.x-e.x),0>w&&(w+=2*Math.PI),"cw"===this.mode&&b>w?w+=2*Math.PI:"ccw"===this.mode&&w>b&&(b+=2*Math.PI),y=Math.abs(b-w),!("s"===this.quad&&Math.abs(b-w)>Math.PI/2)){"m"===this.quad&&y>=Math.PI&&(l=1),r={x:e.x,y:e.y};break}return x=this.trace.region?0:this.tools[this.currentTool].bbox().xMax,v=w<=(G=Math.PI)&&b>=G||w>=(L=Math.PI)&&L>=b?r.x-c-x:Math.min(f.x,a.x)-x,m=w<=(A=2*Math.PI)&&b>=A||w>=(j=2*Math.PI)&&j>=b||0>=w&&b>=0||w>=0&&0>=b?r.x+c+x:Math.max(f.x,a.x)+x,k=w<=(N=3*Math.PI/2)&&b>=N||w>=(z=3*Math.PI/2)&&z>=b?r.y-c-x:Math.min(f.y,a.y)-x,M=w<=(_=Math.PI/2)&&b>=_||w>=(P=Math.PI/2)&&P>=b?r.y+c+x:Math.max(f.y,a.y)+x,"m"===this.quad&&Math.abs(f.x-a.x)<1e-6&&Math.abs(f.y-a.y)<1e-6&&(this.trace.path+="A"+c+" "+c+" 0 0 "+p+" "+(a.x+2*a.i)+" "+(a.y+2*a.j),v=r.x-c-x,k=r.y-c-x,m=r.x+c+x,M=r.y+c+x),this.trace.path+="A"+c+" "+c+" 0 "+l+" "+p+" "+a.x+" "+a.y,this.addBbox({xMin:v,yMin:k,xMax:m,yMax:M})}throw new SyntaxError("cannot interpolate without a G01/2/3")}if("2"===u)return this.finishTrace();throw new SyntaxError(""+u+" is an invalid operation (D) code")}},t.prototype.finishStepRepeat=function(){var t,e,r,i,o,n;if(1!==this.stepRepeat.x||1!==this.stepRepeat.y){if(0!==this.layer.level)throw new Error("step repeat with clear levels is unimplimented");for(t=this.layer.current.g.id,this.layer.current=this.group,n=[],e=i=0,o=this.stepRepeat.x;o>=0?o>i:i>o;e=o>=0?++i:--i)n.push(function(){var i,o,n;for(n=[],r=i=0,o=this.stepRepeat.y;o>=0?o>i:i>o;r=o>=0?++i:--i)n.push(0!==e||0!==r?this.layer.current[this.layer.type]._.push({use:{x:e*this.stepRepeat.xStep,y:r*this.stepRepeat.yStep,"xlink:href":t}}):void 0);return n}.call(this));return n}},t.prototype.finishTrace=function(){var t,e,r,i;if(this.trace.path){if(e={path:{d:this.trace.path}},this.trace.region)e.path["stroke-width"]=0,e.path.fill="currentColor";else{i=this.tools[this.currentTool].stroke;for(t in i)r=i[t],e.path[t]=r}return this.layer.current[this.layer.type]._.push(e),this.trace.path=""}},t.prototype.move=function(t){var e;if(null==this.units){if(null==this.backupUnits)throw new Error("units have not been set");this.units=this.backupUnits}return e=this.coordinate(t),this.position.x=e.x,this.position.y=e.y,e},t.prototype.coordinate=function(t){var e,r,i,o,n,s,h,a,l,u,c,x,f;if(!this.format.set)throw new SyntaxError("format undefined");i={x:0,y:0},i.x=null!=(n=t.match(/X[+-]?\d+/))&&null!=(s=n[0])?s.slice(1):void 0,i.y=null!=(h=t.match(/Y[+-]?\d+/))&&null!=(a=h[0])?a.slice(1):void 0,i.i=null!=(l=t.match(/I[+-]?\d+/))&&null!=(u=l[0])?u.slice(1):void 0,i.j=null!=(c=t.match(/J[+-]?\d+/))&&null!=(x=c[0])?x.slice(1):void 0;for(r in i)if(o=i[r],null!=o){if(e=1,("+"===o[0]||"-"===o[0])&&("-"===o[0]&&(e=-1),o=o.slice(1)),"L"===this.format.zero)e*=Math.pow(10,this.format.places[1]);else{if("T"!==this.format.zero)throw new SyntaxError("invalid zero suppression format");e*=Math.pow(10,o.length-this.format.places[0])}i[r]=Number(o)/e,"I"===this.format.notation&&(i[r]+=null!=(f=this.position[r])?f:0)}return null==i.x&&(i.x=this.position.x),null==i.y&&(i.y=this.position.y),null==i.i&&(i.i=0),null==i.j&&(i.j=0),i},t.prototype.addBbox=function(t){return t.xMinthis.bbox.xMax&&(this.bbox.xMax=t.xMax),t.yMax>this.bbox.yMax?this.bbox.yMax=t.yMax:void 0},t}(),e.exports=o},{"./gerber-parser":2,"./macro-tool":4,"./standard-tool":8,"./unique-id":9}],8:[function(t,e){var r,i,o;o=t("./unique-id"),r=t("./pad-shapes"),i=function(t,e){var i,n,s,h,a,l,u;if(l={pad:[],trace:!1},e.cx=0,e.cy=0,n="tool-"+t+"-pad-"+o(),u="",null!=e.dia&&null==e.verticies){if(null!=e.obround||null!=e.width||null!=e.height||null!=e.degrees)throw new Error("incompatible parameters for tool "+t);if(e.dia<0)throw new RangeError(""+t+" circle diameter out of range ("+e.dia+"<0)");u="circle",null==e.hole&&(l.trace={"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":e.dia,stroke:"currentColor",fill:"none"})}else if(null!=e.width&&null!=e.height){if(null!=e.dia||null!=e.verticies||null!=e.degrees)throw new Error("incompatible parameters for tool "+t);if(e.width<=0)throw new RangeError(""+t+" rect width out of range ("+e.width+"<=0)");if(e.height<=0)throw new RangeError(""+t+" rect height out of range ("+e.height+"<=0)");u="rect",null!=e.hole||e.obround||(l.trace={"stroke-width":0})}else{if(null==e.dia||null==e.verticies)throw new Error("unidentified standard tool shape");if(null!=e.obround||null!=e.width||null!=e.height)throw new Error("incompatible parameters for tool "+t);if(e.verticies<3||e.verticies>12)throw new RangeError(""+t+" polygon points out of range ("+e.verticies+"<3 or >12)]");u="polygon"}if(a=r[u](e),null!=e.hole){if(i=null,null!=e.hole.dia&&null==e.hole.width&&null==e.hole.height){if(!(e.hole.dia>=0))throw new RangeError(""+t+" hole diameter out of range ("+e.hole.dia+"<0)");i=r.circle({cx:e.cx,cy:e.cy,dia:e.hole.dia}),i=i.shape,i.circle.fill="#000"}else{if(null==e.hole.width||null==e.hole.height)throw new Error(""+t+" has invalid hole parameters");if(!(e.hole.width>=0))throw new RangeError(""+t+" hole width out of range ("+e.hole.width+"<0)");if(!(e.hole.height>=0))throw new RangeError(""+t+" hole height out of range");i=r.rect({cx:e.cx,cy:e.cy,width:e.hole.width,height:e.hole.height}),i=i.shape,i.rect.fill="#000"}h=n+"-mask",s={mask:{id:n+"-mask",_:[{rect:{x:a.bbox[0],y:a.bbox[1],width:a.bbox[2]-a.bbox[0],height:a.bbox[3]-a.bbox[1],fill:"#fff"}},i]}},a.shape[u].mask="url(#"+h+")",l.pad.push(s)}return n&&(a.shape[u].id=n),l.pad.push(a.shape),l.bbox=a.bbox,l.padId=n,l},e.exports=i},{"./pad-shapes":6,"./unique-id":9}],9:[function(t,e){var r,i;i=1e3,r=function(){return i++},e.exports=r},{}]},{},[1])(1)}); \ No newline at end of file +!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.gerberToSvg=t()}}(function(){return function t(e,r,i){function o(s,h){if(!r[s]){if(!e[s]){var a="function"==typeof require&&require;if(!h&&a)return a(s,!0);if(n)return n(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var u=r[s]={exports:{}};e[s][0].call(u.exports,function(t){var r=e[s][1][t];return o(r?r:t)},u,u.exports,t,e,r,i)}return r[s].exports}for(var n="function"==typeof require&&require,s=0;s=" "&&"~">=e?r+=e:"\n"===e&&this.line++;this.index++}return t},t}(),e.exports=r},{}],3:[function(t,e){var r,i,o,n,s,h;i=/[\+-\/x\(\)]/,r=/[\$\d\.]+/,o=new RegExp("("+i.source+")|("+r.source+")","g"),h=function(t){var e;return e=t.match(o)},n=function(t){return r.test(t)},s=function(t){var e,r,i,o,s,a,l;return l=h(t),r=0,a=function(){return l[r]},e=function(t){return t===a()?r++:void 0},s=function(){var t,r;if(r=a(),e(r),n(r))t={type:"n",val:r};else{if("("!==r)throw new SytaxError(""+r+" is unexpected in an arithmetic string");if(t=i(),")"!==a())throw new SytaxError("expected ')'");e(")")}return t},o=function(){var t,r,i;for(t=s(),i=a();"x"===i||"/"===i;)e(i),r=s(),t={type:i,left:t,right:r},i=a();return t},(i=function(){var t,r,i;for(t=o(),i=a();"+"===i||"-"===i;)e(i),r=o(),t={type:i,left:t,right:r},i=a();return t})()},e.exports={tokenize:h,isNumber:n,parse:s}},{}],4:[function(t,e){var r,i,o,n;o=t("./pad-shapes"),i=t("./macro-calc"),n=t("./unique-id"),r=function(){function t(t){this.modifiers={},this.name=t[0].slice(2),this.blocks=t.slice(1),this.shapes=[],this.masks=[],this.bbox=[null,null,null,null]}return t.prototype.run=function(t,e){var r,i,o,s,h,a,l,u,c,x,f,p,d,y,b,w,g,m,v;for(null==e&&(e=[]),o=c=0,d=e.length;d>c;o=++c)s=e[o],this.modifiers["$"+(o+1)]=s;for(g=this.blocks,x=0,y=g.length;y>x;x++)r=g[x],this.runBlock(r);for(a="tool-"+t+"-pad-"+n(),h=[],m=this.masks,f=0,b=m.length;b>f;f++)s=m[f],h.push(s);if(this.shapes.length>1){for(i={id:a,_:[]},v=this.shapes,p=0,w=v.length;w>p;p++)l=v[p],i._.push(l);h=[{g:i}]}else 1===this.shapes.length&&(u=Object.keys(this.shapes[0])[0],this.shapes[0][u].id=a,h.push(this.shapes[0]));return{pad:h,padId:a,bbox:this.bbox,trace:!1}},t.prototype.runBlock=function(t){var e,r,i,o,n,s,h,a;switch(t[0]){case"$":return o=null!=(a=t.match(/^\$\d+(?=\=)/))?a[0]:void 0,n=t.slice(1+o.length),this.modifiers[o]=this.getNumber(n);case"1":case"2":case"20":case"21":case"22":case"4":case"5":case"6":case"7":for(r=t.split(","),i=s=0,h=r.length;h>s;i=++s)e=r[i],r[i]=this.getNumber(e);return this.primitive(r);default:if("0"!==t[0])throw new SyntaxError("'"+t+"' unrecognized tool macro block")}},t.prototype.primitive=function(t){var e,r,i,s,h,a,l,u,c,x,f,p,d,y,b,w,g,m,v,M,k,E,S,q,R,I,T,D,F;switch(h=!1,c=!1,f=null,t[0]){case 1:f=o.circle({dia:t[2],cx:t[3],cy:t[4]}),0===t[1]?h=!0:this.addBbox(f.bbox);break;case 2:case 20:f=o.vector({width:t[2],x1:t[3],y1:t[4],x2:t[5],y2:t[6]}),t[7]&&(f.shape.line.transform="rotate("+t[7]+")"),0===t[1]?h=!0:this.addBbox(f.bbox,t[7]);break;case 21:f=o.rect({cx:t[4],cy:t[5],width:t[2],height:t[3]}),t[6]&&(f.shape.rect.transform="rotate("+t[6]+")"),0===t[1]?h=!0:this.addBbox(f.bbox,t[6]);break;case 22:f=o.lowerLeftRect({x:t[4],y:t[5],width:t[2],height:t[3]}),t[6]&&(f.shape.rect.transform="rotate("+t[6]+")"),0===t[1]?h=!0:this.addBbox(f.bbox,t[6]);break;case 4:for(l=[],r=p=3,S=3+2*t[2];S>=p;r=p+=2)l.push([t[r],t[r+1]]);f=o.outline({points:l}),(u=t[t.length-1])&&(f.shape.polygon.transform="rotate("+u+")"),0===t[1]?h=!0:this.addBbox(f.bbox,t[t.length-1]);break;case 5:if(0!==t[6]&&(0!==t[3]||0!==t[4]))throw new RangeError("polygon center must be 0,0 if rotated in macro");f=o.polygon({cx:t[3],cy:t[4],dia:t[5],verticies:t[2],degrees:t[6]}),0===t[1]?h=!0:this.addBbox(f.bbox);break;case 6:if(0!==t[9]&&(0!==t[1]||0!==t[2]))throw new RangeError("moiré center must be 0,0 if rotated in macro");if(f=o.moire({cx:t[1],cy:t[2],outerDia:t[3],ringThx:t[4],ringGap:t[5],maxRings:t[6],crossThx:t[7],crossLength:t[8]}),t[9])for(q=f.shape,d=0,w=q.length;w>d;d++)x=q[d],null!=x.line&&(x.line.transform="rotate("+t[9]+")");this.addBbox(f.bbox,t[9]);break;case 7:if(0!==t[9]&&(0!==t[1]||0!==t[2]))throw new RangeError("thermal center must be 0,0 if rotated in macro");if(f=o.thermal({cx:t[1],cy:t[2],outerDia:t[3],innerDia:t[4],gap:t[5]}),t[6])for(R=f.shape,y=0,g=R.length;g>y;y++)if(x=R[y],null!=x.mask)for(I=x.mask._,b=0,m=I.length;m>b;b++)s=I[b],null!=s.rect&&(s.rect.transform="rotate("+t[6]+")");this.addBbox(f.bbox,t[6]);break;default:throw new SyntaxError(""+t[0]+" is not a valid primitive code")}if(h){for(i in f.shape)f.shape[i].fill="#000";if(a="macro-"+this.name+"-mask-"+n(),s={mask:{id:a,_:[{rect:{x:this.bbox[0],y:this.bbox[1],width:this.bbox[2]-this.bbox[0],height:this.bbox[3]-this.bbox[1],fill:"#fff"}},f.shape]}},1===this.shapes.length)for(i in this.shapes[0])this.shapes[0][i].mask="url(#"+a+")";else if(this.shapes.length>1){for(e={mask:"url(#"+a+")",_:[]},T=this.shapes,k=0,v=T.length;v>k;k++)x=T[k],e._.push(x);this.shapes=[{g:e}]}return this.masks.push(s)}if(Array.isArray(f.shape)){for(D=f.shape,F=[],E=0,M=D.length;M>E;E++)x=D[E],F.push(null!=x.mask?this.masks.push(x):this.shapes.push(x));return F}return this.shapes.push(f.shape)},t.prototype.addBbox=function(t,e){var r,i,o,n,s,h,a,l,u;if(null==e&&(e=0),e){for(n=Math.sin(e*Math.PI/180),r=Math.cos(e*Math.PI/180),Math.abs(n)<1e-9&&(n=0),Math.abs(r)<1e-9&&(r=0),o=[[t[0],t[1]],[t[2],t[1]],[t[2],t[3]],[t[0],t[3]]],u=[],a=0,l=o.length;l>a;a++)i=o[a],s=i[0]*r-i[1]*n,h=i[0]*n+i[1]*r,(null===this.bbox[0]||sthis.bbox[2])&&(this.bbox[2]=s),u.push(null===this.bbox[3]||h>this.bbox[3]?this.bbox[3]=h:void 0);return u}return(null===this.bbox[0]||t[0]this.bbox[2])&&(this.bbox[2]=t[2]),null===this.bbox[3]||t[3]>this.bbox[3]?this.bbox[3]=t[3]:void 0},t.prototype.getNumber=function(t){return t.match(/^[+-]?[\d.]+$/)?parseFloat(t):t.match(/^\$\d+$/)?parseFloat(this.modifiers[t]):this.evaluate(i.parse(t))},t.prototype.evaluate=function(t){switch(t.type){case"n":return this.getNumber(t.val);case"+":return this.evaluate(t.left)+this.evaluate(t.right);case"-":return this.evaluate(t.left)-this.evaluate(t.right);case"x":return this.evaluate(t.left)*this.evaluate(t.right);case"/":return this.evaluate(t.left)/this.evaluate(t.right)}},t}(),e.exports=r},{"./macro-calc":3,"./pad-shapes":6,"./unique-id":9}],5:[function(t,e){var r,i,o,n;n=function(t,e){var r;if(r="",0===e)return"";for(;e>1;)1&e&&(r+=t),e>>=1,t+=t;return r+t},r="_",i=" ",o=function(t,e){var s,h,a,l,u,c,x,f,p,d,y,b,w,g,m;if(null==e&&(e={}),f=e.pretty,l=null!=(g=e.indent)?g:0,c=f?"\n":"",p=c?"string"==typeof f?f:i:"",p=n(p,l),y="",Array.isArray(t))for(a=b=0,w=t.length;w>b;a=++b)x=t[a],y+=(0!==a?c:"")+o(x,e);else if(s=!1,h=Object.keys(t)[0],null!=h){y=""+p+"<"+h,m=t[h];for(u in m)d=m[u],u===r?s=d:y+=" "+u+'="'+d+'"';s&&(y+=">"+c+o(s,{pretty:f,indent:l+1})),y+=null!=t[h]._?""+c+p+"":"/>"}return y},e.exports=o},{}],6:[function(t,e){var r,i,o,n,s,h,a,l,u;l=t("./unique-id"),r=function(t){var e;if(null==t.dia)throw new SyntaxError("circle function requires diameter");if(null==t.cx)throw new SyntaxError("circle function requires x center");if(null==t.cy)throw new SyntaxError("circle function requires y center");return e=t.dia/2,{shape:{circle:{cx:t.cx,cy:t.cy,r:e,"stroke-width":0,fill:"currentColor"}},bbox:[t.cx-e,t.cy-e,t.cx+e,t.cy+e]}},h=function(t){var e,r,i,o;if(null==t.width)throw new SyntaxError("rectangle requires width");if(null==t.height)throw new SyntaxError("rectangle requires height");if(null==t.cx)throw new SyntaxError("rectangle function requires x center");if(null==t.cy)throw new SyntaxError("rectangle function requires y center");return i=t.cx-t.width/2,o=t.cy-t.height/2,r={shape:{rect:{x:i,y:o,width:t.width,height:t.height,"stroke-width":0,fill:"currentColor"}},bbox:[i,o,i+t.width,o+t.height]},t.obround&&(e=.5*Math.min(t.width,t.height),r.shape.rect.rx=e,r.shape.rect.ry=e),r},s=function(t){var e,r,i,o,n,s,h,a,l,u,c,x,f,p,d,y;if(null==t.dia)throw new SyntaxError("polygon requires diameter");if(null==t.verticies)throw new SyntaxError("polygon requires verticies");if(null==t.cx)throw new SyntaxError("polygon function requires x center");if(null==t.cy)throw new SyntaxError("polygon function requires y center");for(s=null!=t.degrees?t.degrees*Math.PI/180:0,h=2*Math.PI/t.verticies,i=t.dia/2,r="",c=null,p=null,u=null,f=null,e=d=0,y=t.verticies;y>=0?y>d:d>y;e=y>=0?++d:--d)a=s+e*h,o=i*Math.cos(a),n=i*Math.sin(a),Math.abs(o)<1e-9&&(o=0),Math.abs(n)<1e-9&&(n=0),l=t.cx+o,x=t.cy+n,(c>l||null===c)&&(c=l),(l>u||null===u)&&(u=l),(p>x||null===p)&&(p=x),(x>f||null===f)&&(f=x),r+=" "+l+","+x;return{shape:{polygon:{points:r.slice(1),"stroke-width":0,fill:"currentColor"}},bbox:[c,p,u,f]}},u=function(t){var e,r,i;if(null==t.x1)throw new SyntaxError("vector function requires start x");if(null==t.y1)throw new SyntaxError("vector function requires start y");if(null==t.x2)throw new SyntaxError("vector function requires end x");if(null==t.y2)throw new SyntaxError("vector function requires end y");if(null==t.width)throw new SyntaxError("vector function requires width");return e=Math.abs(Math.atan((t.y2-t.y1)/(t.x2-t.x1))),r=t.width/2*Math.sin(e),i=t.width/2*Math.cos(e),1e-7>r&&(r=0),1e-7>i&&(i=0),{shape:{line:{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,"stroke-width":t.width,stroke:"currentColor"}},bbox:[Math.min(t.x1,t.x2)-r,Math.min(t.y1,t.y2)-i,Math.max(t.x1,t.x2)+r,Math.max(t.y1,t.y2)+i]}},i=function(t){if(null==t.width)throw new SyntaxError("lower left rect requires width");if(null==t.height)throw new SyntaxError("lower left rect requires height");if(null==t.x)throw new SyntaxError("lower left rectangle requires x");if(null==t.y)throw new SyntaxError("lower left rectangle requires y");return{shape:{rect:{x:t.x,y:t.y,width:t.width,height:t.height,"stroke-width":0,fill:"currentColor"}},bbox:[t.x,t.y,t.x+t.width,t.y+t.height]}},n=function(t){var e,r,i,o,n,s,h,a,l,u,c,x,f;if(!(Array.isArray(t.points)&&t.points.length>1))throw new SyntaxError("outline function requires points array");for(s=null,u=null,n=null,l=null,r="",f=t.points,c=0,x=f.length;x>c;c++){if(e=f[c],!Array.isArray(e)||2!==e.length)throw new SyntaxError("outline function requires points array");i=e[0],h=e[1],(s>i||null===s)&&(s=i),(i>n||null===n)&&(n=i),(u>h||null===u)&&(u=h),(h>l||null===l)&&(l=h),r+=" "+i+","+h}if(o=t.points[t.points.length-1][0],a=t.points[t.points.length-1][1],o!==t.points[0][0]||a!==t.points[0][1])throw new RangeError("last point must match first point of outline");return{shape:{polygon:{points:r.slice(1),"stroke-width":0,fill:"currentColor"}},bbox:[s,u,n,l]}},o=function(t){var e,r,i;if(null==t.cx)throw new SyntaxError("moiré requires x center");if(null==t.cy)throw new SyntaxError("moiré requires y center");if(null==t.outerDia)throw new SyntaxError("moiré requires outer diameter");if(null==t.ringThx)throw new SyntaxError("moiré requires ring thickness");if(null==t.ringGap)throw new SyntaxError("moiré requires ring gap");if(null==t.maxRings)throw new SyntaxError("moiré requires max rings");if(null==t.crossLength)throw new SyntaxError("moiré requires crosshair length");if(null==t.crossThx)throw new SyntaxError("moiré requires crosshair thickness");for(i=[{line:{x1:t.cx-t.crossLength/2,y1:0,x2:t.cx+t.crossLength/2,y2:0,"stroke-width":t.crossThx,stroke:"currentColor"}},{line:{x1:0,y1:t.cy-t.crossLength/2,x2:0,y2:t.cy+t.crossLength/2,"stroke-width":t.crossThx,stroke:"currentColor"}}],e=(t.outerDia-t.ringThx)/2,r=0;e>=t.ringThx&&r<=t.maxRings;)i.push({circle:{cx:t.cx,cy:t.cy,r:e,fill:"none","stroke-width":t.ringThx,stroke:"currentColor"}}),r++,e-=t.ringThx+t.ringGap;return e>0&&r<=t.maxRings&&i.push({circle:{cx:t.cx,cy:t.cy,r:e,"stroke-width":0,fill:"currentColor"}}),{shape:i,bbox:[Math.min(t.cx-t.crossLength/2,t.cx-t.outerDia/2),Math.min(t.cy-t.crossLength/2,t.cy-t.outerDia/2),Math.max(t.cx+t.crossLength/2,t.cx+t.outerDia/2),Math.max(t.cy+t.crossLength/2,t.cy+t.outerDia/2)]}},a=function(t){var e,r,i,o,n,s,h,a,u;if(null==t.cx)throw new SyntaxError("thermal requires x center");if(null==t.cy)throw new SyntaxError("thermal requires y center");if(null==t.outerDia)throw new SyntaxError("thermal requires outer diameter");if(null==t.innerDia)throw new SyntaxError("thermal requires inner diameter");if(null==t.gap)throw new SyntaxError("thermal requires gap");return r="thermal-mask-"+l(),n=(t.outerDia-t.innerDia)/2,i=t.outerDia/2,o=i-n/2,h=t.cx-i,s=t.cx+i,u=t.cy-i,a=t.cy+i,e=t.gap/2,{shape:[{mask:{id:r,_:[{circle:{cx:t.cx,cy:t.cy,r:i,"stroke-width":0,fill:"#fff"}},{rect:{x:h,y:-e,width:t.outerDia,height:t.gap,"stroke-width":0,fill:"#000"}},{rect:{x:-e,y:u,width:t.gap,height:t.outerDia,"stroke-width":0,fill:"#000"}}]}},{circle:{cx:t.cx,cy:t.cy,r:o,fill:"none","stroke-width":n,stroke:"currentColor",mask:"url(#"+r+")"}}],bbox:[h,u,s,a]}},e.exports={circle:r,rect:h,polygon:s,vector:u,lowerLeftRect:i,outline:n,moire:o,thermal:a}},{"./unique-id":9}],7:[function(t,e){var r,i,o,n,s,h;i=t("./gerber-parser"),h=t("./unique-id"),r=t("./macro-tool"),s=t("./standard-tool"),n=function(t){var e,r,i,o,n,h,a,l,u,c;if(i=null!=(l=t.match(/^ADD\d+/))&&null!=(u=l[0])?u.slice(2):void 0,!(null!=i&&parseInt(i.slice(1),10)>9))throw new SyntaxError(""+i+" is an invalid tool code (must be >= 10)");switch(e=null,r=!1,t.slice(2+i.length,4+i.length)){case"C,":n=t.slice(4+i.length).split("X"),a={dia:parseFloat(n[0])},n.length>2?a.hole={width:parseFloat(n[1]),height:parseFloat(n[2])}:n.length>1&&(a.hole={dia:parseFloat(n[1])}),e=s(i,a);break;case"R,":n=t.slice(4+i.length).split("X"),a={width:parseFloat(n[0]),height:parseFloat(n[1])},n.length>3?a.hole={width:parseFloat(n[2]),height:parseFloat(n[3])}:n.length>2&&(a.hole={dia:parseFloat(n[2])}),e=s(i,a);break;case"O,":n=t.slice(4+i.length).split("X"),a={width:parseFloat(n[0]),height:parseFloat(n[1])},n.length>3?a.hole={width:parseFloat(n[2]),height:parseFloat(n[3])}:n.length>2&&(a.hole={dia:parseFloat(n[2])}),a.obround=!0,e=s(i,a);break;case"P,":n=t.slice(4+i.length).split("X"),a={dia:parseFloat(n[0]),verticies:parseFloat(n[1])},null!=n[2]&&(a.degrees=parseFloat(n[2])),n.length>4?a.hole={width:parseFloat(n[3]),height:parseFloat(n[4])}:n.length>3&&(a.hole={dia:parseFloat(n[3])}),e=s(i,a);break;default:if(o=t.slice(2+i.length),h=null!=(c=o.match(/[a-zA-Z_$][a-zA-Z_$.0-9]{0,126}(?=,)?/))?c[0]:void 0,!h)throw new SyntaxError("invalid definition with macro");n=o.slice(h.length+1).split("X"),1===n.length&&""===n[0]&&(n=null),r={name:h,mods:n}}return{macro:r,tool:e,code:i}},o=function(){function t(t){null==t&&(t=""),this.parser=new i(t),this.macros={},this.tools={},this.currentTool="",this.defs=[],this.gerberId="gerber-"+h(),this.group={g:{id:""+this.gerberId+"-layer-0",_:[]}},this.layer={level:0,type:"g",current:this.group},this.stepRepeat={x:1,y:1,xStep:null,yStep:null,block:0},this.done=!1,this.units=null,this.format={set:!1,zero:null,notation:null,places:null},this.position={x:0,y:0},this.mode=null,this.trace={region:!1,path:""},this.quad=null,this.bbox={xMin:1/0,yMin:1/0,xMax:-1/0,yMax:-1/0}}return t.prototype.plot=function(){for(var t;!this.done;)t=this.parser.nextCommand(),"%"===t[0]?this.parameter(t):this.operate(t[0]);return this.finish()},t.prototype.finish=function(){var t,e,r;return this.finishTrace(),this.finishStepRepeat(),e=parseFloat((this.bbox.xMax-this.bbox.xMin).toPrecision(10)),t=parseFloat((this.bbox.yMax-this.bbox.yMin).toPrecision(10)),r={svg:{xmlns:"http://www.w3.org/2000/svg",version:"1.1","xmlns:xlink":"http://www.w3.org/1999/xlink",width:""+e+this.units,height:""+t+this.units,viewBox:""+this.bbox.xMin+" "+this.bbox.yMin+" "+e+" "+t,id:this.gerberId,_:[]}},this.defs.length&&r.svg._.push({defs:{_:this.defs}}),this.group.g.transform="translate(0,"+(this.bbox.yMin+this.bbox.yMax)+") scale(1,-1)",r.svg._.push(this.group),r},t.prototype.parameter=function(t){var e,i,o,s,h,a,l,u,c,x,f,p,d,y,b,w,g,m,v,M,k,E,S,q,R,I,T;if(o=!1,"%"===t[0]&&"%"!==t[t.length-1])throw new SyntaxError("@parameter should only be called with paramters");for(t=t.slice(1),l=0,T=[];!o;){switch(i=t[l],i.slice(0,2)){case"FS":if(u=!1,this.format.set)throw new SyntaxError("format spec cannot be redefined");try{"L"===i[2]||"T"===i[2]?this.format.zero=i[2]:u=!0,"A"===i[3]||"I"===i[3]?this.format.notation=i[3]:u=!0,"X"===i[4]&&"Y"===i[7]&&i.slice(5,7)===i.slice(8,10)?(this.format.places=[parseInt(i[5],10),parseInt(i[6],10)],(this.format.places[0]>7||this.format.places[1]>7)&&(u=!0)):u=!0}catch(D){s=D,u=!0}if(u)throw new SyntaxError("invalid format spec");this.format.set=!0;break;case"MO":if(y=i.slice(2),null!=this.units)throw new SyntaxError("gerber file may not redifine units");if("MM"===y)this.units="mm";else{if("IN"!==y)throw new SyntaxError(""+y+" are unrecognized units");this.units="in"}break;case"AD":if(e=n(t[l]),null!=this.tools[e.code])throw new SyntaxError("duplicate tool code");for(e.macro&&(e.tool=this.macros[e.macro.name].run(e.code,e.macro.mods)),this.tools[e.code]={stroke:e.tool.trace,flash:function(t,r){return{use:{x:t,y:r,"xlink:href":"#"+e.tool.padId}}},bbox:function(t,r){return null==t&&(t=0),null==r&&(r=0),{xMin:t+e.tool.bbox[0],yMin:r+e.tool.bbox[1],xMax:t+e.tool.bbox[2],yMax:r+e.tool.bbox[3]}}},M=e.tool.pad,m=0,v=M.length;v>m;m++)f=M[m],this.defs.push(f);this.currentTool=e.code;break;case"AM":c=new r(t.slice(0,-1)),this.macros[c.name]=c,o=!0;break;case"SR":this.finishTrace(),this.finishStepRepeat(),this.stepRepeat.x=Number(null!=(k=null!=(E=i.match(/X\d+/))?E[0].slice(1):void 0)?k:1),this.stepRepeat.y=Number(null!=(S=null!=(q=i.match(/Y\d+/))?q[0].slice(1):void 0)?S:1),this.stepRepeat.x>1&&(this.stepRepeat.xStep=Number(null!=(R=i.match(/I[\d\.]+/))?R[0].slice(1):void 0)),this.stepRepeat.y>1&&(this.stepRepeat.yStep=Number(null!=(I=i.match(/J[\d\.]+/))?I[0].slice(1):void 0)),(1!==this.stepRepeat.x||1!==this.stepRepeat.y)&&0===this.layer.level&&(d={g:{id:""+this.gerberId+"-sr-block-"+this.stepRepeat.block,_:[]}},this.layer.current[this.layer.type]._.push(d),this.layer.current=d);break;case"LP":if(this.finishTrace(),p=i[2],"D"!==p&&"C"!==p)throw new SyntaxError(""+i+" is an unrecognized level polarity");"D"===p&&"mask"===this.layer.type?(h=""+this.gerberId+"-layer-"+ ++this.layer.level,this.group={g:{id:h,_:[this.group]}},this.layer.current=this.group,this.layer.type="g"):"C"===p&&"g"===this.layer.type&&(x=""+this.gerberId+"-layer-"+ ++this.layer.level,w=this.bbox.xMin,g=this.bbox.yMin,b=this.bbox.xMax-this.bbox.xMin,a=this.bbox.yMax-this.bbox.yMin,c={mask:{id:x,color:"#000",_:[{rect:{x:w,y:g,width:b,height:a,fill:"#fff"}}]}},this.defs.push(c),this.layer.current.g.mask="url(#"+x+")",this.layer.current=this.defs[this.defs.length-1],this.layer.type="mask"),this.position.x=null,this.position.y=null}T.push("%"===t[++l]?o=!0:void 0)}return T},t.prototype.operate=function(t){var e,r,i,o,n,s,h,a,l,u,c,x,f,p,d,y,b,w,g,m,v,M,k,E,S,q,R,I,T,D,F,_,P,C,B,G,L,A,j,N,z;if(g=!1,i=t.slice(0,3),"M"===t[0]){if("M02"===i)this.done=!0,t="";else if("M00"!==i&&"M01"!==i)throw new SyntaxError("invalid operation M code");g=!0}else if("G"===t[0]){if(t.match(/^G0?1/))this.mode="i";else if(t.match(/^G0?2/))this.mode="cw";else if(t.match(/^G0?3(?![67])/))this.mode="ccw";else if("G36"===i)this.finishTrace(),this.trace.region=!0;else if("G37"===i)this.finishTrace(),this.trace.region=!1;else if("G74"===i)this.quad="s";else if("G75"===i)this.quad="m";else if("G70"===i)this.backupUnits="in";else if("G71"===i)this.backupUnits="mm";else if(!i.match(/^G(0?4)|(5[45])|(7[01])|(9[01])/))throw new SyntaxError("invalid operation G code");g=!0}if(d=null!=(D=t.match(/D[1-9]\d{1,}$/))?D[0]:void 0,null!=d){if(this.finishTrace(),null==this.tools[d])throw new SyntaxError("tool "+d+" does not exist");if(this.trace.region)throw new SyntaxError("cannot change tool while region mode is on");this.currentTool=d}if(t.match(/^(G0?[123])?([XYIJ][+-]?\d+){0,4}D0?[123]$/)){if(u=t[t.length-1],o=null!=(F=t.match(/[XYIJ][+-]?\d+/g))?F.join(""):void 0,f={x:this.position.x,y:this.position.y},a=this.move(o),"3"===u)return this.finishTrace(),this.layer.current[this.layer.type]._.push(this.tools[this.currentTool].flash(this.position.x,this.position.y)),this.addBbox(this.tools[this.currentTool].bbox(this.position.x,this.position.y));if("1"===u){if(this.trace.path||(this.trace.path="M"+f.x+" "+f.y,"i"===this.mode&&this.addBbox(this.trace.region?{xMin:f.x,yMin:f.y,xMax:f.x,yMax:f.y}:this.tools[this.currentTool].bbox(f.x,f.y))),null==this.mode&&(this.mode="i"),"i"===this.mode)return this.trace.path+="L"+a.x+" "+a.y,this.addBbox(this.trace.region?{xMin:a.x,yMin:a.y,xMax:a.x,yMax:a.y}:this.tools[this.currentTool].bbox(a.x,a.y));if("cw"===this.mode||"ccw"===this.mode){if(c=Math.sqrt(Math.pow(a.i,2)+Math.pow(a.j,2)),p="cw"===this.mode?0:1,l=0,r=[],b=0,w=0,"s"===this.quad)for(C=[f.x-a.i,f.x+a.i],E=0,R=C.length;R>E;E++)for(n=C[E],B=[f.y-a.j,f.y+a.j],S=0,I=B.length;I>S;S++)s=B[S],h=Math.sqrt(Math.pow(n-a.x,2)+Math.pow(s-a.y,2)),Math.abs(c-h)<1e-7&&r.push({x:n,y:s});else"m"===this.quad&&r.push({x:f.x+a.i,y:f.y+a.j});for(q=0,T=r.length;T>q;q++)if(e=r[q],b=Math.atan2(a.y-e.y,a.x-e.x),0>b&&(b+=2*Math.PI),w=Math.atan2(f.y-e.y,f.x-e.x),0>w&&(w+=2*Math.PI),"cw"===this.mode&&b>w?w+=2*Math.PI:"ccw"===this.mode&&w>b&&(b+=2*Math.PI),y=Math.abs(b-w),!("s"===this.quad&&Math.abs(b-w)>Math.PI/2)){"m"===this.quad&&y>=Math.PI&&(l=1),r={x:e.x,y:e.y};break}return x=this.trace.region?0:this.tools[this.currentTool].bbox().xMax,v=w<=(G=Math.PI)&&b>=G||w>=(L=Math.PI)&&L>=b?r.x-c-x:Math.min(f.x,a.x)-x,m=w<=(A=2*Math.PI)&&b>=A||w>=(j=2*Math.PI)&&j>=b||0>=w&&b>=0||w>=0&&0>=b?r.x+c+x:Math.max(f.x,a.x)+x,k=w<=(N=3*Math.PI/2)&&b>=N||w>=(z=3*Math.PI/2)&&z>=b?r.y-c-x:Math.min(f.y,a.y)-x,M=w<=(_=Math.PI/2)&&b>=_||w>=(P=Math.PI/2)&&P>=b?r.y+c+x:Math.max(f.y,a.y)+x,"m"===this.quad&&Math.abs(f.x-a.x)<1e-6&&Math.abs(f.y-a.y)<1e-6&&(this.trace.path+="A"+c+" "+c+" 0 0 "+p+" "+(a.x+2*a.i)+" "+(a.y+2*a.j),v=r.x-c-x,k=r.y-c-x,m=r.x+c+x,M=r.y+c+x),this.trace.path+="A"+c+" "+c+" 0 "+l+" "+p+" "+a.x+" "+a.y,this.addBbox({xMin:v,yMin:k,xMax:m,yMax:M})}throw new SyntaxError("cannot interpolate without a G01/2/3")}if("2"===u)return this.finishTrace();throw new SyntaxError(""+u+" is an invalid operation (D) code")}},t.prototype.finishStepRepeat=function(){var t,e,r,i,o,n;if(1!==this.stepRepeat.x||1!==this.stepRepeat.y){if(0!==this.layer.level)throw new Error("step repeat with clear levels is unimplimented");for(t=this.layer.current.g.id,this.layer.current=this.group,n=[],e=i=0,o=this.stepRepeat.x;o>=0?o>i:i>o;e=o>=0?++i:--i)n.push(function(){var i,o,n;for(n=[],r=i=0,o=this.stepRepeat.y;o>=0?o>i:i>o;r=o>=0?++i:--i)n.push(0!==e||0!==r?this.layer.current[this.layer.type]._.push({use:{x:e*this.stepRepeat.xStep,y:r*this.stepRepeat.yStep,"xlink:href":t}}):void 0);return n}.call(this));return n}},t.prototype.finishTrace=function(){var t,e,r,i;if(this.trace.path){if(e={path:{d:this.trace.path}},this.trace.region)e.path["stroke-width"]=0,e.path.fill="currentColor";else{i=this.tools[this.currentTool].stroke;for(t in i)r=i[t],e.path[t]=r}return this.layer.current[this.layer.type]._.push(e),this.trace.path=""}},t.prototype.move=function(t){var e;if(null==this.units){if(null==this.backupUnits)throw new Error("units have not been set");this.units=this.backupUnits}return e=this.coordinate(t),this.position.x=e.x,this.position.y=e.y,e},t.prototype.coordinate=function(t){var e,r,i,o,n,s,h,a,l,u,c,x,f;if(!this.format.set)throw new SyntaxError("format undefined");i={x:0,y:0},i.x=null!=(n=t.match(/X[+-]?\d+/))&&null!=(s=n[0])?s.slice(1):void 0,i.y=null!=(h=t.match(/Y[+-]?\d+/))&&null!=(a=h[0])?a.slice(1):void 0,i.i=null!=(l=t.match(/I[+-]?\d+/))&&null!=(u=l[0])?u.slice(1):void 0,i.j=null!=(c=t.match(/J[+-]?\d+/))&&null!=(x=c[0])?x.slice(1):void 0;for(r in i)if(o=i[r],null!=o){if(e=1,("+"===o[0]||"-"===o[0])&&("-"===o[0]&&(e=-1),o=o.slice(1)),"L"===this.format.zero)e*=Math.pow(10,this.format.places[1]);else{if("T"!==this.format.zero)throw new SyntaxError("invalid zero suppression format");e*=Math.pow(10,o.length-this.format.places[0])}i[r]=Number(o)/e,"I"===this.format.notation&&(i[r]+=null!=(f=this.position[r])?f:0)}return null==i.x&&(i.x=this.position.x),null==i.y&&(i.y=this.position.y),null==i.i&&(i.i=0),null==i.j&&(i.j=0),i},t.prototype.addBbox=function(t){return t.xMinthis.bbox.xMax&&(this.bbox.xMax=t.xMax),t.yMax>this.bbox.yMax?this.bbox.yMax=t.yMax:void 0},t}(),e.exports=o},{"./gerber-parser":2,"./macro-tool":4,"./standard-tool":8,"./unique-id":9}],8:[function(t,e){var r,i,o;o=t("./unique-id"),r=t("./pad-shapes"),i=function(t,e){var i,n,s,h,a,l,u;if(l={pad:[],trace:!1},e.cx=0,e.cy=0,n="tool-"+t+"-pad-"+o(),u="",null!=e.dia&&null==e.verticies){if(null!=e.obround||null!=e.width||null!=e.height||null!=e.degrees)throw new Error("incompatible parameters for tool "+t);if(e.dia<0)throw new RangeError(""+t+" circle diameter out of range ("+e.dia+"<0)");u="circle",null==e.hole&&(l.trace={"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":e.dia,stroke:"currentColor",fill:"none"})}else if(null!=e.width&&null!=e.height){if(null!=e.dia||null!=e.verticies||null!=e.degrees)throw new Error("incompatible parameters for tool "+t);if(e.width<=0)throw new RangeError(""+t+" rect width out of range ("+e.width+"<=0)");if(e.height<=0)throw new RangeError(""+t+" rect height out of range ("+e.height+"<=0)");u="rect",null!=e.hole||e.obround||(l.trace={"stroke-width":0})}else{if(null==e.dia||null==e.verticies)throw new Error("unidentified standard tool shape");if(null!=e.obround||null!=e.width||null!=e.height)throw new Error("incompatible parameters for tool "+t);if(e.verticies<3||e.verticies>12)throw new RangeError(""+t+" polygon points out of range ("+e.verticies+"<3 or >12)]");u="polygon"}if(a=r[u](e),null!=e.hole){if(i=null,null!=e.hole.dia&&null==e.hole.width&&null==e.hole.height){if(!(e.hole.dia>=0))throw new RangeError(""+t+" hole diameter out of range ("+e.hole.dia+"<0)");i=r.circle({cx:e.cx,cy:e.cy,dia:e.hole.dia}),i=i.shape,i.circle.fill="#000"}else{if(null==e.hole.width||null==e.hole.height)throw new Error(""+t+" has invalid hole parameters");if(!(e.hole.width>=0))throw new RangeError(""+t+" hole width out of range ("+e.hole.width+"<0)");if(!(e.hole.height>=0))throw new RangeError(""+t+" hole height out of range");i=r.rect({cx:e.cx,cy:e.cy,width:e.hole.width,height:e.hole.height}),i=i.shape,i.rect.fill="#000"}h=n+"-mask",s={mask:{id:n+"-mask",_:[{rect:{x:a.bbox[0],y:a.bbox[1],width:a.bbox[2]-a.bbox[0],height:a.bbox[3]-a.bbox[1],fill:"#fff"}},i]}},a.shape[u].mask="url(#"+h+")",l.pad.push(s)}return n&&(a.shape[u].id=n),l.pad.push(a.shape),l.bbox=a.bbox,l.padId=n,l},e.exports=i},{"./pad-shapes":6,"./unique-id":9}],9:[function(t,e){var r,i;i=1e3,r=function(){return i++},e.exports=r},{}]},{},[1])(1)}); \ No newline at end of file diff --git a/lib/plotter.js b/lib/plotter.js index da8c53b..33b0e8f 100644 --- a/lib/plotter.js +++ b/lib/plotter.js @@ -25,8 +25,8 @@ }; if (mods.length > 2) { params.hole = { - width: parseFloat(mods[2]), - height: parseFloat(mods[1]) + width: parseFloat(mods[1]), + height: parseFloat(mods[2]) }; } else if (mods.length > 1) { params.hole = { @@ -43,8 +43,8 @@ }; if (mods.length > 3) { params.hole = { - width: parseFloat(mods[3]), - height: parseFloat(mods[2]) + width: parseFloat(mods[2]), + height: parseFloat(mods[3]) }; } else if (mods.length > 2) { params.hole = { @@ -61,8 +61,8 @@ }; if (mods.length > 3) { params.hole = { - width: parseFloat(mods[3]), - height: parseFloat(mods[2]) + width: parseFloat(mods[2]), + height: parseFloat(mods[3]) }; } else if (mods.length > 2) { params.hole = { @@ -83,8 +83,8 @@ } if (mods.length > 4) { params.hole = { - width: parseFloat(mods[4]), - height: parseFloat(mods[3]) + width: parseFloat(mods[3]), + height: parseFloat(mods[4]) }; } else if (mods.length > 3) { params.hole = { diff --git a/src/plotter.coffee b/src/plotter.coffee index c7ed078..160f4d3 100644 --- a/src/plotter.coffee +++ b/src/plotter.coffee @@ -24,8 +24,8 @@ parseAD = (block) -> mods = block[4+code.length..].split 'X' params = { dia: parseFloat mods[0] } if mods.length > 2 then params.hole = { - width: parseFloat mods[2] - height: parseFloat mods[1] + width: parseFloat mods[1] + height: parseFloat mods[2] } else if mods.length > 1 then params.hole = { dia: parseFloat mods[1] } ad = tool code, params @@ -33,8 +33,8 @@ parseAD = (block) -> mods = block[4+code.length..].split 'X' params = { width: parseFloat(mods[0]), height: parseFloat(mods[1]) } if mods.length > 3 then params.hole = { - width: parseFloat mods[3] - height: parseFloat mods[2] + width: parseFloat mods[2] + height: parseFloat mods[3] } else if mods.length > 2 then params.hole = { dia: parseFloat mods[2] } ad = tool code, params @@ -42,8 +42,8 @@ parseAD = (block) -> mods = block[4+code.length..].split 'X' params = { width: parseFloat(mods[0]), height: parseFloat(mods[1]) } if mods.length > 3 then params.hole = { - width: parseFloat mods[3] - height: parseFloat mods[2] + width: parseFloat mods[2] + height: parseFloat mods[3] } else if mods.length > 2 then params.hole = { dia: parseFloat mods[2] } params.obround = true @@ -56,8 +56,8 @@ parseAD = (block) -> } if mods[2]? then params.degrees = parseFloat mods[2] if mods.length > 4 then params.hole = { - width: parseFloat mods[4] - height: parseFloat mods[3] + width: parseFloat mods[3] + height: parseFloat mods[4] } else if mods.length > 3 then params.hole = { dia: parseFloat mods[3] } ad = tool code, params diff --git a/test/plotter_test.coffee b/test/plotter_test.coffee index e6ffe4e..6061b9f 100644 --- a/test/plotter_test.coffee +++ b/test/plotter_test.coffee @@ -96,10 +96,10 @@ describe 'Plotter class', -> { circle: { r: 0.7 } } ] (p.tools.D12?).should.be.false - p.parameter [ '%', 'ADD12C,1.6X0.5X0.5', '%' ] + p.parameter [ '%', 'ADD12C,1.6X0.6X0.5', '%' ] (p.tools.D12?).should.be.true p.defs.should.containDeep [ - { mask: { _: [ { rect: {} }, { rect: {} } ] } } + { mask: { _: [ { rect: {} }, { rect: {width:0.6, height:0.5} } ] } } { circle: { r: 0.8 } } ] it 'should add standard rectangles to the tools list', -> @@ -110,7 +110,7 @@ describe 'Plotter class', -> '%' 'ADD10R,1X1' 'ADD11R,1.1X1.1X0.5' - 'ADD12R,1.2X1.2X0.5X0.5' + 'ADD12R,1.2X1.2X0.6X0.5' '%' ] (p.tools.D10?).should.be.true @@ -120,7 +120,7 @@ describe 'Plotter class', -> { rect: { width: 1 } } { mask: { _: [ { circle: { r: 0.25 } } ] } } { rect: { width: 1.1 } } - { mask: { _: [ { rect: {} }, { rect: {} } ] } } + { mask: { _: [ { rect: {} }, { rect: {width:0.6, height:0.5} } ] } } { rect: { width: 1.2 } } ] @@ -132,7 +132,7 @@ describe 'Plotter class', -> '%' 'ADD10O,1X1' 'ADD11O,1.2X1.2X0.5' - 'ADD12O,1.4X1.4X0.5X0.5' + 'ADD12O,1.4X1.4X0.6X0.5' '%' ] (p.tools.D10?).should.be.true @@ -142,7 +142,7 @@ describe 'Plotter class', -> { rect: { width: 1, rx: 0.5 } } { mask: { _: [ { circle: { r: 0.25 } } ] } } { rect: { width: 1.2, rx: 0.6 } } - { mask: { _: [ { rect: {} }, { rect: {} } ] } } + { mask: { _: [ { rect: {} }, { rect: {width:0.6, height:0.5} } ] } } { rect: { width: 1.4, rx: 0.7 } } ] it 'should add standard polygons to the tools list', -> @@ -155,7 +155,7 @@ describe 'Plotter class', -> 'ADD10P,5X3' 'ADD11P,5X4X45' 'ADD12P,5X4X0X0.6' - 'ADD13P,5X4X0X0.6X0.6' + 'ADD13P,5X4X0X0.6X0.5' '%' ] (p.tools.D10?).should.be.true @@ -167,7 +167,7 @@ describe 'Plotter class', -> { polygon: {} } { mask: { _: [ { circle: { r: 0.3 } } ] } } { polygon: {} } - { mask: { _: [ { rect: {} }, { rect: {} } ] } } + { mask: { _: [ { rect: {} }, { rect: {width:0.6, height:0.5} } ] } } { polygon: {} } ]