1
0
Fork 0

Merge branch 'develop' into eriese-v3-printing

This commit is contained in:
Enoch Riese 2022-12-12 09:44:25 -06:00
commit d78b2bb6c1
54 changed files with 869 additions and 645 deletions

View file

@ -778,17 +778,18 @@ Pattern.prototype.__isStackHidden = function (stackName) {
}
/**
* Generates an array of settings.options objects for sampling a list option
* Generates an array of settings.options objects for sampling a list or boolean option
*
* @private
* @param {string} optionName - Name of the option to sample
* @return {Array} sets - The list of settings objects
*/
Pattern.prototype.__listOptionSets = function (optionName) {
Pattern.prototype.__listBoolOptionSets = function (optionName) {
let option = this.config.options[optionName]
const base = this.__setBase()
const sets = []
let run = 1
if (typeof option.bool !== 'undefined') option = { list: [false, true] }
for (const choice of option.list) {
const settings = {
...base,
@ -1091,11 +1092,15 @@ Pattern.prototype.__needs = function (partName, set = 0) {
* @return {Array} sets - The list of settings objects
*/
Pattern.prototype.__optionSets = function (optionName) {
let option = this.config.options[optionName]
if (typeof option?.list === 'object') return this.__listOptionSets(optionName)
const sets = []
if (!(optionName in this.config.options)) return sets
let option = this.config.options[optionName]
if (typeof option.list === 'object' || typeof option.bool !== 'undefined')
return this.__listBoolOptionSets(optionName)
let factor = 1
let step, val
let numberRuns = 10
let stepFactor = numberRuns - 1
if (typeof option.min === 'undefined' || typeof option.max === 'undefined') {
const min = option * 0.9
const max = option * 1.1
@ -1103,9 +1108,16 @@ Pattern.prototype.__optionSets = function (optionName) {
}
if (typeof option.pct !== 'undefined') factor = 100
val = option.min / factor
step = (option.max / factor - val) / 9
if (typeof option.count !== 'undefined' || typeof option.mm !== 'undefined') {
const numberOfCounts = option.max - option.min + 1
if (numberOfCounts < 10) {
numberRuns = numberOfCounts
stepFactor = Math.max(numberRuns - 1, 1)
}
}
step = (option.max / factor - val) / stepFactor
const base = this.__setBase()
for (let run = 1; run < 11; run++) {
for (let run = 1; run <= numberRuns; run++) {
const settings = {
...base,
options: {
@ -1117,6 +1129,8 @@ Pattern.prototype.__optionSets = function (optionName) {
settings.options[optionName] = val
sets.push(settings)
val += step
if (typeof option.count !== 'undefined' || typeof option.mm !== 'undefined')
val = Math.round(val)
}
return sets

View file

@ -320,7 +320,7 @@ Point.prototype.sitsRoughlyOn = function (that) {
* Returns slope of a line made by this Point and that Point
*
* @param {Point} that - The Point that forms the line together with this Point
* @return {float} slote - The slope of the line made by this Point and that Point
* @return {float} slope - The slope of the line made by this Point and that Point
*/
Point.prototype.slope = function (that) {
return (that.__check().y - this.__check().y) / (that.x - this.x)

View file

@ -44,7 +44,7 @@ export function beamIntersectsCircle(c, r, p1, p2, sort = 'x') {
}
/**
* Finds qhere an endless line intersects with a given X-value
* Finds where an endless line intersects with a given X-value
*
* @param {Point} from - First Point on the line
* @param {Point} to - Second Point on the line
@ -60,7 +60,7 @@ export function beamIntersectsX(from, to, x) {
}
/**
* Finds qhere an endless line intersects with a given Y-value
* Finds where an endless line intersects with a given Y-value
*
* @param {Point} from - First Point 1 on the line
* @param {Point} to - Second Point on the line
@ -162,7 +162,7 @@ export function circlesIntersect(c1, r1, c2, r2, sort = 'x') {
* @param {BezierJs} curve - A BezierJs curve instance
* @param {string} edge - The edge to find: top, bottom, right, or left
* @param {int} steps - The number of steps to divide the curve in while walking it
* @return {Array} intersecions - An Array of Point objects of all intersections
* @return {Point} edgepoint - A Point object located on the edge of the curve. Returns the first point found, if more than one lies on the edge.
*/
export function curveEdge(curve, edge, steps = 500) {
let x = Infinity
@ -194,7 +194,7 @@ export function curveEdge(curve, edge, steps = 500) {
* @param {Point} cp2 - Control Point at the end of the curve
* @param {Point} to - End Point of the curve
* @param {float} x - X-value to check for intersections
* @return {Array} intersecions - An Array of Point objects of all intersections
* @return {Array} intersections - An Array of Point objects of all intersections
*/
export function curveIntersectsX(from, cp1, cp2, to, x) {
let start = new Point(x, -10000)
@ -210,7 +210,7 @@ export function curveIntersectsX(from, cp1, cp2, to, x) {
* @param {Point} cp2 - Control Point at the end of the curve
* @param {Point} to - End Point of the curve
* @param {float} y - Y-value to check for intersections
* @return {Array} intersecions - An Array of Point objects of all intersections
* @return {Array} intersections - An Array of Point objects of all intersections
*/
export function curveIntersectsY(from, cp1, cp2, to, y) {
let start = new Point(-10000, y)
@ -229,7 +229,7 @@ export function curveIntersectsY(from, cp1, cp2, to, y) {
* @param {Point} cp1B - Control Point at the start of the second curve
* @param {Point} cp2B - Control Point at the end of the second curve
* @param {Point} toB - End Point of the fsecond curve
* @return {Array} intersecions - An Array of Point objects of all intersections between the curves
* @return {Array} intersections - An Array of Point objects of all intersections between the curves
*/
export function curvesIntersect(fromA, cp1A, cp2A, toA, fromB, cp1B, cp2B, toB) {
let precision = 0.005 // See https://github.com/Pomax/bezierjs/issues/99