Getting coverage to 100%
This commit is contained in:
parent
b27e10374e
commit
c45523f38a
25 changed files with 2393 additions and 2282 deletions
|
@ -136,20 +136,15 @@ const whats = {
|
|||
outline
|
||||
}
|
||||
|
||||
const expand_shorthand = (config, units) => {
|
||||
const expand_shorthand = (config, name, units) => {
|
||||
if (a.type(config.expand)(units) == 'string') {
|
||||
const prefix = config.expand.slice(0, -1)
|
||||
const suffix = config.expand.slice(-1)
|
||||
let expand = prefix
|
||||
let joints = 0
|
||||
|
||||
if (suffix == ')') ; // noop
|
||||
else if (suffix == '>') joints = 1
|
||||
else if (suffix == ']') joints = 2
|
||||
else expand = config.expand
|
||||
|
||||
config.expand = parseFloat(expand)
|
||||
config.joints = config.joints || joints
|
||||
const valid_suffixes = [')', '>', ']']
|
||||
a.assert(valid_suffixes.includes(suffix), `If field "${name}" is a string, ` +
|
||||
`it should end with one of [${valid_suffixes.map(s => `'${s}'`).join(', ')}]!`)
|
||||
config.expand = prefix
|
||||
config.joints = config.joints || valid_suffixes.indexOf(suffix)
|
||||
}
|
||||
|
||||
if (a.type(config.joints)(units) == 'string') {
|
||||
|
@ -159,7 +154,7 @@ const expand_shorthand = (config, units) => {
|
|||
}
|
||||
}
|
||||
|
||||
exports.parse = (config = {}, points = {}, units = {}) => {
|
||||
exports.parse = (config, points, units) => {
|
||||
|
||||
// output outlines will be collected here
|
||||
const outlines = {}
|
||||
|
@ -201,7 +196,7 @@ exports.parse = (config = {}, points = {}, units = {}) => {
|
|||
const original_adjust = part.adjust // same as above
|
||||
const adjust = start => anchor(original_adjust || {}, `${name}.adjust`, points, start)(units)
|
||||
const fillet = a.sane(part.fillet || 0, `${name}.fillet`, 'number')(units)
|
||||
expand_shorthand(part, units)
|
||||
expand_shorthand(part, `${name}.expand`, units)
|
||||
const expand = a.sane(part.expand || 0, `${name}.expand`, 'number')(units)
|
||||
const joints = a.in(a.sane(part.joints || 0, `${name}.joints`, 'number')(units), `${name}.joints`, [0, 1, 2])
|
||||
const scale = a.sane(part.scale || 1, `${name}.scale`, 'number')(units)
|
||||
|
|
36
src/pcbs.js
36
src/pcbs.js
|
@ -115,7 +115,7 @@ const kicad_netclass = `
|
|||
)
|
||||
`
|
||||
|
||||
const makerjs2kicad = exports._makerjs2kicad = (model, layer='Edge.Cuts') => {
|
||||
const makerjs2kicad = exports._makerjs2kicad = (model, layer) => {
|
||||
const grs = []
|
||||
const xy = val => `${val[0]} ${-val[1]}`
|
||||
m.model.walk(model, {
|
||||
|
@ -185,30 +185,40 @@ const footprint = exports._footprint = (points, net_indexer, component_indexer,
|
|||
parsed_def = {type: 'boolean', value: param_def}
|
||||
} else if (def_type == 'array') {
|
||||
parsed_def = {type: 'array', value: param_def}
|
||||
} else if (def_type == 'undefined') {
|
||||
} else if (def_type == 'object') {
|
||||
// parsed param definitions also expand to an object
|
||||
// so to detect whether this is an arbitrary object,
|
||||
// we first have to make sure it's not an expanded param def
|
||||
// (this has to be a heuristic, but should be pretty reliable)
|
||||
const defarr = Object.keys(param_def)
|
||||
const already_expanded = defarr.length == 2 && defarr.includes('type') && defarr.includes('value')
|
||||
if (!already_expanded) {
|
||||
parsed_def = {type: 'object', value: param_def}
|
||||
}
|
||||
} else {
|
||||
parsed_def = {type: 'net', value: undefined}
|
||||
}
|
||||
|
||||
// combine default value with potential user override
|
||||
let value = prep.extend(parsed_def.value, params[param_name])
|
||||
let type = parsed_def.type
|
||||
let value = params[param_name] !== undefined ? params[param_name] : parsed_def.value
|
||||
const type = parsed_def.type
|
||||
a.in(type, `${name}.params.${param_name}.type`, [
|
||||
'string', 'number', 'boolean', 'array', 'object', 'net', 'anchor'
|
||||
])
|
||||
|
||||
// templating support, with conversion back to raw datatypes
|
||||
const converters = {
|
||||
string: v => v,
|
||||
number: v => a.sane(v, `${name}.params.${param_name}`, 'number')(units),
|
||||
boolean: v => v === 'true',
|
||||
net: v => v,
|
||||
anchor: v => v,
|
||||
array: v => v
|
||||
boolean: v => v === 'true'
|
||||
}
|
||||
if (a.type(value)() == 'string') {
|
||||
if (a.type(value)() == 'string' && Object.keys(converters).includes(type)) {
|
||||
value = u.template(value, point.meta)
|
||||
value = converters[type](value)
|
||||
}
|
||||
|
||||
// type-specific processing
|
||||
if (['string', 'number', 'boolean', 'array'].includes(type)) {
|
||||
if (['string', 'number', 'boolean', 'array', 'object'].includes(type)) {
|
||||
parsed_params[param_name] = value
|
||||
} else if (type == 'net') {
|
||||
const net = a.sane(value, `${name}.params.${param_name}`, 'string')(units)
|
||||
|
@ -218,8 +228,8 @@ const footprint = exports._footprint = (points, net_indexer, component_indexer,
|
|||
index: index,
|
||||
str: `(net ${index} "${net}")`
|
||||
}
|
||||
} else if (type == 'anchor') {
|
||||
let parsed_anchor = anchor(value || {}, `${name}.params.${param_name}`, points, point)(units)
|
||||
} else { // anchor
|
||||
let parsed_anchor = anchor(value, `${name}.params.${param_name}`, points, point)(units)
|
||||
parsed_anchor.y = -parsed_anchor.y // kicad mirror, as per usual
|
||||
parsed_params[param_name] = parsed_anchor
|
||||
}
|
||||
|
@ -236,7 +246,7 @@ const footprint = exports._footprint = (points, net_indexer, component_indexer,
|
|||
const sign = point.meta.mirrored ? -1 : 1
|
||||
return `${sign * x} ${y}`
|
||||
}
|
||||
const xyfunc = (x, y, resist=true) => {
|
||||
const xyfunc = (x, y, resist) => {
|
||||
const new_anchor = anchor({
|
||||
shift: [x, -y],
|
||||
resist: resist
|
||||
|
|
|
@ -244,7 +244,7 @@ const render_zone = exports._render_zone = (zone_name, zone, anchor, global_key,
|
|||
|
||||
const parse_axis = exports._parse_axis = (config, name, points, units) => {
|
||||
if (!['number', 'undefined'].includes(a.type(config)(units))) {
|
||||
const mirror_obj = a.sane(config || {}, name, 'object')()
|
||||
const mirror_obj = a.sane(config, name, 'object')()
|
||||
const distance = a.sane(mirror_obj.distance || 0, `${name}.distance`, 'number')(units)
|
||||
delete mirror_obj.distance
|
||||
let axis = anchor_lib.parse(mirror_obj, name, points)(units).x
|
||||
|
@ -254,21 +254,18 @@ const parse_axis = exports._parse_axis = (config, name, points, units) => {
|
|||
}
|
||||
|
||||
const perform_mirror = exports._perform_mirror = (point, axis) => {
|
||||
if (axis !== undefined) {
|
||||
point.meta.mirrored = false
|
||||
if (point.meta.asym == 'source') return ['', null]
|
||||
const mp = point.clone().mirror(axis)
|
||||
const mirrored_name = `mirror_${point.meta.name}`
|
||||
mp.meta = prep.extend(mp.meta, mp.meta.mirror || {})
|
||||
mp.meta.name = mirrored_name
|
||||
mp.meta.colrow = `mirror_${mp.meta.colrow}`
|
||||
mp.meta.mirrored = true
|
||||
if (point.meta.asym == 'clone') {
|
||||
point.meta.skip = true
|
||||
}
|
||||
return [mirrored_name, mp]
|
||||
point.meta.mirrored = false
|
||||
if (point.meta.asym == 'source') return ['', null]
|
||||
const mp = point.clone().mirror(axis)
|
||||
const mirrored_name = `mirror_${point.meta.name}`
|
||||
mp.meta = prep.extend(mp.meta, mp.meta.mirror || {})
|
||||
mp.meta.name = mirrored_name
|
||||
mp.meta.colrow = `mirror_${mp.meta.colrow}`
|
||||
mp.meta.mirrored = true
|
||||
if (point.meta.asym == 'clone') {
|
||||
point.meta.skip = true
|
||||
}
|
||||
return ['', null]
|
||||
return [mirrored_name, mp]
|
||||
}
|
||||
|
||||
exports.parse = (config, units) => {
|
||||
|
@ -300,13 +297,11 @@ exports.parse = (config, units) => {
|
|||
|
||||
// simplifying the names in individual point "zones" and single-key columns
|
||||
while (Object.keys(new_points).some(k => k.endsWith('_default'))) {
|
||||
for (const key of Object.keys(new_points)) {
|
||||
if (key.endsWith('_default')) {
|
||||
const new_key = key.slice(0, -8)
|
||||
new_points[new_key] = new_points[key]
|
||||
new_points[new_key].meta.name = new_key
|
||||
delete new_points[key]
|
||||
}
|
||||
for (const key of Object.keys(new_points).filter(k => k.endsWith('_default'))) {
|
||||
const new_key = key.slice(0, -8)
|
||||
new_points[new_key] = new_points[key]
|
||||
new_points[new_key].meta.name = new_key
|
||||
delete new_points[key]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -352,7 +347,7 @@ exports.parse = (config, units) => {
|
|||
const global_axis = parse_axis(global_mirror, `points.mirror`, points, units)
|
||||
const global_mirrored_points = {}
|
||||
for (const point of Object.values(points)) {
|
||||
if (global_axis !== undefined && point.mirrored === undefined) {
|
||||
if (global_axis !== undefined && point.meta.mirrored === undefined) {
|
||||
const [mname, mp] = perform_mirror(point, global_axis)
|
||||
if (mp) {
|
||||
global_mirrored_points[mname] = mp
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue