gerber-plotter
Advanced tools
Comparing version 1.0.2 to 1.0.3
// operate the plotter | ||
'use strict' | ||
var filter = require('lodash.filter') | ||
var reduce = require('lodash.reduce') | ||
var forEach = require('lodash.foreach') | ||
var boundingBox = require('./_box') | ||
@@ -143,3 +139,3 @@ | ||
return reduce(points, function(result, m) { | ||
return points.reduce(function(result, m) { | ||
if (!region) { | ||
@@ -227,3 +223,3 @@ var mBox = boundingBox.translate(tool.box, m) | ||
else if (arc === 's') { | ||
validCenters = filter(candidates, function(c) { | ||
validCenters = candidates.filter(function(c) { | ||
var startDist = Math.sqrt(Math.pow(c[0] - start[0], 2) + Math.pow(c[1] - start[1], 2)) | ||
@@ -348,3 +344,3 @@ var endDist = Math.sqrt(Math.pow(c[0] - end[0], 2) + Math.pow(c[1] - end[1], 2)) | ||
forEach(points, function(p, i) { | ||
points.forEach(function(p, i) { | ||
var j = (i < (points.length - 1)) ? i + 1 : 0 | ||
@@ -351,0 +347,0 @@ pathGraph.add({type: 'line', start: p, end: points[j]}) |
// returns a pad shape array given a tool definition | ||
'use strict' | ||
var reduce = require('lodash.reduce') | ||
var transform = require('lodash.transform') | ||
var mapValues = require('lodash.mapvalues') | ||
var isFunction = require('lodash.isfunction') | ||
var isFinite = require('lodash.isfinite') | ||
var clone = require('lodash.clone') | ||
@@ -87,3 +83,3 @@ var boundingBox = require('./_box') | ||
var box = reduce(points, function(result, p) { | ||
var box = points.reduce(function(result, p) { | ||
return boundingBox.addPoint(result, p) | ||
@@ -230,13 +226,20 @@ }, boundingBox.new()) | ||
return transform(blocks, function(result, block) { | ||
blocks = blocks || [] | ||
return blocks.reduce(function(result, block) { | ||
var shapeAndBox | ||
if (block.type !== 'variable' && block.type !== 'comment') { | ||
block = mapValues(block, function(value) { | ||
block = Object.keys(block).reduce(function(result, key) { | ||
var value = block[key] | ||
if (isFunction(value)) { | ||
return value(mods) | ||
result[key] = value(mods) | ||
} | ||
else { | ||
result[key] = value | ||
} | ||
return value | ||
}) | ||
return result | ||
}, {}) | ||
} | ||
@@ -248,3 +251,3 @@ | ||
polarity: (block.exp === 1) ? 'dark' : 'clear', | ||
box: clone(result.box) | ||
box: result.box.slice(0) | ||
}) | ||
@@ -305,9 +308,10 @@ exposure = block.exp | ||
mods = block.set(mods) | ||
return true | ||
return result | ||
default: | ||
return true | ||
return result | ||
} | ||
result.shape = result.shape.concat(shapeAndBox.shape) | ||
// only change the box if the exposure is creating an image | ||
@@ -317,6 +321,8 @@ if (exposure === 1) { | ||
} | ||
return result | ||
}, emptyMacro) | ||
} | ||
var padShape = function(tool, macros) { | ||
module.exports = function padShape(tool, macros) { | ||
var shape = [] | ||
@@ -348,5 +354,8 @@ var box = boundingBox.new() | ||
else { | ||
var mods = transform(params, function(result, val, index) { | ||
var mods = params.reduce(function(result, val, index) { | ||
result['$' + (index + 1)] = val | ||
}) | ||
return result | ||
}, {}) | ||
return runMacro(mods, macros[toolShape]) | ||
@@ -369,3 +378,1 @@ } | ||
} | ||
module.exports = padShape |
// utilities to create a graph of path segments and traverse that graph | ||
'use strict' | ||
var forEachRight = require('lodash.foreachright') | ||
var fill = require('lodash.fill') | ||
var find = require('lodash.find') | ||
var map = require('lodash.map') | ||
var GAP = 0.00011 | ||
var find = function(collection, condition) { | ||
var element | ||
var i | ||
for (i = 0; i < collection.length; i++) { | ||
element = collection[i] | ||
if (condition(element)) { | ||
return element | ||
} | ||
} | ||
} | ||
var distance = function(point, target) { | ||
@@ -66,2 +76,6 @@ return Math.sqrt(Math.pow(point[0] - target[0], 2) + Math.pow(point[1] - target[1], 2)) | ||
}) | ||
end = find(this._points, function(point) { | ||
return pointsEqual(point.position, newSeg.end, fillGaps) | ||
}) | ||
} | ||
@@ -111,3 +125,5 @@ | ||
if (!this._optimize) { | ||
return map(this._edges, 'segment') | ||
return this._edges.map(function(edge) { | ||
return edge.segment | ||
}) | ||
} | ||
@@ -148,3 +164,3 @@ | ||
// add non-walked adjacent nodes to the discovered stack | ||
forEachRight(lastEnd.edges, function(seg) { | ||
lastEnd.edges.reverse().forEach(function(seg) { | ||
if (!walked[seg]) { | ||
@@ -151,0 +167,0 @@ discovered.push(seg) |
@@ -6,5 +6,2 @@ // gerber plotter | ||
var inherits = require('inherits') | ||
var has = require('lodash.has') | ||
var mapValues = require('lodash.mapvalues') | ||
var clone = require('lodash.clone') | ||
@@ -139,12 +136,17 @@ var PathGraph = require('./path-graph') | ||
coord = mapValues(coord, function(value, key) { | ||
coord = Object.keys(coord).reduce(function(result, key) { | ||
var value = coord[key] | ||
if (key === 'x') { | ||
return (_this._pos[0] + value) | ||
result[key] = _this._pos[0] + value | ||
} | ||
if (key === 'y') { | ||
return (_this._pos[1] + value) | ||
else if (key === 'y') { | ||
result[key] = _this._pos[1] + value | ||
} | ||
else { | ||
result[key] = value | ||
} | ||
return value | ||
}) | ||
return result | ||
}, {}) | ||
} | ||
@@ -217,3 +219,3 @@ | ||
} | ||
else if (!has(this._tools, value)) { | ||
else if (!this._tools[value]) { | ||
this._warn('tool ' + value + ' is not defined') | ||
@@ -282,3 +284,3 @@ } | ||
polarity: (levelValue === 'C') ? 'clear' : 'dark', | ||
box: clone(this._box) | ||
box: this._box.slice(0) | ||
}) | ||
@@ -296,3 +298,7 @@ } | ||
this.push({type: 'repeat', offsets: clone(this._stepRep), box: clone(this._box)}) | ||
this.push({ | ||
type: 'repeat', | ||
offsets: this._stepRep.slice(0), | ||
box: this._box.slice(0) | ||
}) | ||
} | ||
@@ -299,0 +305,0 @@ } |
{ | ||
"name": "gerber-plotter", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Transform stream that takes objects from gerber-parser and emits PCB image objects", | ||
@@ -51,17 +51,7 @@ "main": "lib/index.js", | ||
"inherits": "^2.0.1", | ||
"lodash.clone": "^4.3.2", | ||
"lodash.fill": "^3.3.4", | ||
"lodash.filter": "^4.3.0", | ||
"lodash.find": "^4.3.0", | ||
"lodash.foreach": "^4.2.0", | ||
"lodash.foreachright": "^4.1.0", | ||
"lodash.has": "^4.3.1", | ||
"lodash.isfinite": "^3.3.1", | ||
"lodash.isfunction": "^3.0.6", | ||
"lodash.map": "^4.3.0", | ||
"lodash.mapvalues": "^4.3.0", | ||
"lodash.reduce": "^4.3.0", | ||
"lodash.transform": "^4.3.0", | ||
"readable-stream": "^2.1.2" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
6
2948
128473
- Removedlodash.clone@^4.3.2
- Removedlodash.filter@^4.3.0
- Removedlodash.find@^4.3.0
- Removedlodash.foreach@^4.2.0
- Removedlodash.foreachright@^4.1.0
- Removedlodash.has@^4.3.1
- Removedlodash.map@^4.3.0
- Removedlodash.mapvalues@^4.3.0
- Removedlodash.reduce@^4.3.0
- Removedlodash.transform@^4.3.0
- Removedlodash.clone@4.5.0(transitive)
- Removedlodash.filter@4.6.0(transitive)
- Removedlodash.find@4.6.0(transitive)
- Removedlodash.foreach@4.5.0(transitive)
- Removedlodash.foreachright@4.4.0(transitive)
- Removedlodash.has@4.5.2(transitive)
- Removedlodash.map@4.6.0(transitive)
- Removedlodash.mapvalues@4.6.0(transitive)
- Removedlodash.reduce@4.6.0(transitive)
- Removedlodash.transform@4.6.0(transitive)