Merge branch 'develop' into joost
This commit is contained in:
commit
01e2d4e41a
8 changed files with 75 additions and 6 deletions
|
@ -26,6 +26,7 @@ import {
|
|||
lineIntersectsCircle,
|
||||
lineIntersectsCurve,
|
||||
linesIntersect,
|
||||
mergeOptions,
|
||||
pctBasedOn,
|
||||
pointOnBeam,
|
||||
pointOnCurve,
|
||||
|
@ -70,6 +71,7 @@ export {
|
|||
lineIntersectsCircle,
|
||||
lineIntersectsCurve,
|
||||
linesIntersect,
|
||||
mergeOptions,
|
||||
pctBasedOn,
|
||||
pointOnBeam,
|
||||
pointOnCurve,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { PatternDraftQueue } from './pattern-draft-queue.mjs'
|
||||
import { Part } from '../part.mjs'
|
||||
import { __macroName } from '../utils.mjs'
|
||||
import { __macroName, mergeOptions } from '../utils.mjs'
|
||||
|
||||
/**
|
||||
* A class to handle drafting a pattern
|
||||
|
@ -210,7 +210,11 @@ PatternDrafter.prototype.__loadAbsoluteOptionsSet = function (set) {
|
|||
*/
|
||||
PatternDrafter.prototype.__snappedPercentageOption = function (optionName, set) {
|
||||
const conf = this.pattern.config.options[optionName]
|
||||
const abs = conf.toAbs(this.pattern.settings[set].options[optionName], this.pattern.settings[set])
|
||||
const abs = conf.toAbs(
|
||||
this.pattern.settings[set].options[optionName],
|
||||
this.pattern.settings[set],
|
||||
mergeOptions(this.pattern.settings[set], this.pattern.config.options)
|
||||
)
|
||||
// Handle units-specific config - Side-step immutability for the snap conf
|
||||
let snapConf = conf.snap
|
||||
if (!Array.isArray(snapConf) && snapConf.metric && snapConf.imperial)
|
||||
|
|
|
@ -441,6 +441,29 @@ export function lineIntersectsCurve(start, end, from, cp1, cp2, to) {
|
|||
else return intersections
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to merge passed in options with default options from the pattern config
|
||||
*
|
||||
* @param {object} settings - The settings passed to the pattern
|
||||
* @param {object} optionsConfig - The pattern's options config
|
||||
* @return {object} result - An object with the merged options and their values
|
||||
*/
|
||||
export function mergeOptions(settings, optionsConfig) {
|
||||
const merged = typeof settings.options === 'undefined' ? {} : { ...settings.option }
|
||||
for (const [key, option] of Object.entries(optionsConfig)) {
|
||||
if (typeof option === 'object') {
|
||||
if (typeof option.pct !== 'undefined') merged[key] = option.pct / 100
|
||||
else if (typeof option.mm !== 'undefined') merged[key] = option.mm
|
||||
else if (typeof option.deg !== 'undefined') merged[key] = option.deg
|
||||
else if (typeof option.count !== 'undefined') merged[key] = option.count
|
||||
else if (typeof option.bool !== 'undefined') merged[key] = option.bool
|
||||
else if (typeof option.dflt !== 'undefined') merged[key] = option.dflt
|
||||
} else merged[key] = option
|
||||
}
|
||||
|
||||
return merged
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to calculate abolute option value based on a measurement
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue