1
0
Fork 0
freesewing/designs/penelope/src/utils.mjs

171 lines
5.1 KiB
JavaScript
Raw Normal View History

2019-08-21 11:11:05 -07:00
function dartCalcFront(options, seatWaistDiff, nrOfDarts) {
/*
console.log(
"F: seatWaistDiff: " + seatWaistDiff + " nrOfDarts: " + nrOfDarts
);
*/
return (
((options.dartMinimumWidth +
(Math.max(
Math.min(seatWaistDiff, options.dartMaximumDifference),
options.dartMinimumDifference
) -
options.dartMinimumDifference) /
4) /
nrOfDarts) *
(0.5 + options.dartToSideSeamFactor)
2020-01-04 14:23:08 +01:00
)
2019-08-21 11:11:05 -07:00
}
function dartCalcBack(options, seatWaistDiff, nrOfDarts) {
/*
console.log(
"B: seatWaistDiff: " + seatWaistDiff + " nrOfDarts: " + nrOfDarts
);
*/
return (
((options.dartMinimumWidth +
(seatWaistDiff -
options.dartBackControl1 -
(seatWaistDiff - options.dartBackControl1) / options.dartBackControl2) /
options.dartBackControl3) /
nrOfDarts) *
(0.5 + options.dartToSideSeamFactor)
2020-01-04 14:23:08 +01:00
)
2019-08-21 11:11:05 -07:00
}
2021-02-14 18:13:46 -08:00
function dartCalc(store, options, seat, seatEase, waist, waistEase) {
2020-01-04 14:23:08 +01:00
seat += seatEase
waist += waistEase
let seatWaistDiff = Math.max(seat - waist, 0)
2019-08-21 11:11:05 -07:00
2020-01-04 14:23:08 +01:00
let nrOfDarts = options.nrOfDarts
2019-08-21 11:11:05 -07:00
2020-01-04 14:23:08 +01:00
let frontDartSize = dartCalcFront(options, seatWaistDiff, nrOfDarts)
2019-08-21 11:11:05 -07:00
/*
console.log({
frontDartSize: frontDartSize,
dartMinimumWidth: options.dartMinimumWidth,
nrOfDarts: nrOfDarts
});
*/
// If the front darts are too small and we have more than one, remove one.
if (frontDartSize <= options.dartMinimumWidth * nrOfDarts && nrOfDarts > 1) {
2020-01-04 14:23:08 +01:00
nrOfDarts--
frontDartSize = dartCalcFront(options, seatWaistDiff, nrOfDarts)
2019-08-21 11:11:05 -07:00
}
// See if the dart created by the side seam becomes too small:
if (seatWaistDiff / 4 - frontDartSize < options.dartSideMinimum) {
2020-01-04 14:23:08 +01:00
frontDartSize = 0
2019-08-21 11:11:05 -07:00
}
// if( seatWaistDiff/4 -frontDartSize < options.dartSideMinimum || frontDartSize < options.dartMinimumWidth *nrOfDarts ) {
// nrOfDarts = 1;
// }
/*
console.log({
frontDartSize: frontDartSize,
dartMinimumWidth: options.dartMinimumWidth,
nrOfDarts: nrOfDarts
});
*/
2020-01-04 14:23:08 +01:00
let backDartSize = dartCalcBack(options, seatWaistDiff, nrOfDarts)
2019-08-21 11:11:05 -07:00
// If the back darts are too small and we have more than one, remove one.
if (backDartSize < options.dartMinimumWidth * nrOfDarts && nrOfDarts > 1) {
2020-01-04 14:23:08 +01:00
nrOfDarts = 1
frontDartSize = dartCalcFront(options, seatWaistDiff, nrOfDarts)
backDartSize = dartCalcBack(options, seatWaistDiff, nrOfDarts)
2019-08-21 11:11:05 -07:00
}
/*
console.log({
backDartSize: backDartSize,
dartMinimumWidth: options.dartMinimumWidth,
nrOfDarts: nrOfDarts
});
*/
2021-03-09 17:43:06 +01:00
store.set('frontDartSize', frontDartSize)
store.set('backDartSize', backDartSize)
store.set('nrOfDarts', nrOfDarts)
2019-08-21 11:11:05 -07:00
}
/**
* Method to add a dart onto a curve
* The dart is added at an 90 degree angle with the curve for a certain depth and Width
* @param part The part that will provide that Paths
* @param curvePath The curve the dart needs to divide
* @param distance Distance from $p1 where the middle of the dart will be
* @param dartSize The width of the dart opening at the curve
* @param dartDepth The depth of the dart
*
* @return Object with three path attributes; left, dart, right
*/
function addDartToCurve(part, curvePath, distance, dartSize, dartDepth) {
2020-01-04 14:23:08 +01:00
let dartMiddle = curvePath.shiftAlong(distance)
2019-08-21 11:11:05 -07:00
2020-01-04 14:23:08 +01:00
let curvePaths = curvePath.split(dartMiddle)
// Fixme: These darts are too close to each other and when
// measurments get a certain way, they cross into each other
// which breaks the pattern. I've side-stepped the issue below
// but this needs to be handled somehow.
let dartLeft, dartRight
if (curvePaths[0].length() > dartSize / 2) {
dartLeft = curvePaths[0].reverse().shiftAlong(dartSize / 2)
} else {
dartLeft = curvePaths[0].start()
}
if (curvePaths[1].length() > dartSize / 2) {
dartRight = curvePaths[1].shiftAlong(dartSize / 2)
} else {
dartLeft = curvePaths[1].start()
}
2019-08-21 11:11:05 -07:00
2020-01-04 14:23:08 +01:00
let distanceFactor = 0.15
2019-08-21 11:11:05 -07:00
let leftCPdistance = Math.min(
curvePaths[0].length() * distanceFactor,
curvePaths[0].ops[1].to.dist(curvePaths[0].ops[1].cp2)
2020-01-04 14:23:08 +01:00
)
2019-08-21 11:11:05 -07:00
let rightCPdistance = Math.min(
curvePaths[1].length() * distanceFactor,
curvePaths[1].ops[0].to.dist(curvePaths[1].ops[1].cp1)
2020-01-04 14:23:08 +01:00
)
2019-08-21 11:11:05 -07:00
2020-01-04 14:23:08 +01:00
let dartBottom = dartMiddle.shift(dartLeft.angle(dartRight) - 90, dartDepth)
2019-08-21 11:11:05 -07:00
2020-01-04 14:23:08 +01:00
let leftDartCP = dartLeft.shift(dartLeft.angle(dartBottom) - 90, leftCPdistance)
let rightDartCP = dartRight.shift(dartRight.angle(dartBottom) + 90, rightCPdistance)
2019-08-21 11:11:05 -07:00
let curveLeftOfDart = new part.Path()
.move(curvePaths[0].ops[0].to)
.curve(curvePaths[0].ops[1].cp1, leftDartCP, dartLeft)
2020-01-04 14:23:08 +01:00
.setRender(false)
2019-08-21 11:11:05 -07:00
let curveRightOfDart = new part.Path()
.move(dartRight)
.curve(rightDartCP, curvePaths[1].ops[1].cp2, curvePaths[1].ops[1].to)
2020-01-04 14:23:08 +01:00
.setRender(false)
2019-08-21 11:11:05 -07:00
2021-01-31 09:22:15 +01:00
let dart = new part.Path().move(dartLeft).line(dartBottom).line(dartRight).setRender(false)
2019-08-21 11:11:05 -07:00
let curveWithDart = {
left: curveLeftOfDart,
dart: dart,
2021-04-24 10:16:31 +02:00
right: curveRightOfDart,
2020-01-04 14:23:08 +01:00
}
2019-08-21 11:11:05 -07:00
/*
part.points.dartMiddle = dartMiddle ;
part.points.dartLeft = dartLeft ;
part.points.dartRight = dartRight ;
part.points.dartBottom = dartBottom ;
*/
2020-01-04 14:23:08 +01:00
return curveWithDart
2019-08-21 11:11:05 -07:00
}
2020-01-04 14:23:08 +01:00
export { addDartToCurve, dartCalc }