diff --git a/designs/titan/src/back.mjs b/designs/titan/src/back.mjs index 26496c0c725..a26850bc155 100644 --- a/designs/titan/src/back.mjs +++ b/designs/titan/src/back.mjs @@ -18,6 +18,7 @@ function titanBack({ Snippet, sa, absoluteOptions, + log, part, }) { /* @@ -102,6 +103,8 @@ function titanBack({ .rotate(options.crossSeamCurveAngle, points.fork) } + let adjustment_warning = false + // Let's get to work points.waistX = new Point(-1 * measurements.waistBackArc * (1 + options.waistEase), 0) points.upperLegY = new Point(0, measurements.waistToUpperLeg) @@ -173,20 +176,41 @@ function titanBack({ // Should we fit the cross seam? if (options.fitCrossSeam && options.fitCrossSeamBack) { let rotate = ['waistIn', 'waistOut'] + let saved = [] let delta = crossSeamDelta() + let previous_delta = delta let run = 0 do { + previous_delta = delta run++ // Remedy A: Slash and spread - for (const i of rotate) points[i] = points[i].rotate(delta / 15, points.seatOut) + for (const i of rotate) { + saved[i] = points[i] + points[i] = points[i].rotate(delta / 15, points.seatOut) + } // Remedy B: Nudge the fork inwards/outwards + saved.fork = points.fork points.fork = points.fork.shift(0, delta / 5) + saved.forkCp2 = points.forkCp2 points.forkCp2 = points.crossSeamCurveCp2.rotate(-90, points.fork) drawCrossSeam() delta = crossSeamDelta() // Uncomment the line beloe this to see all iterations // paths[`try${run}`] = drawPath().attr('class', 'dotted') - } while (Math.abs(delta) > 1 && run < 15) + } while (Math.abs(delta) > 1 && run < 15 && Math.abs(delta) < Math.abs(previous_delta)) + if (Math.abs(delta) > Math.abs(previous_delta)) { + // The rotations started to produce worse results. + // Revert back to the previous rotation. + for (const i of rotate) { + points[i] = saved[i] + } + points.fork = saved.fork + points.forkCp2 = saved.forkCp2 + } + if (Math.abs(delta) > 1 || Math.abs(delta) > Math.abs(previous_delta)) { + log.warning('Unable to adjust the back crotch seam to fit the given measurements.') + adjustment_warning = true + } } // Store inseam & outseam length @@ -494,6 +518,19 @@ function titanBack({ } } + if (adjustment_warning) { + log.warning( + 'We were not able to generate the Back pattern piece correctly. ' + + 'Manual fitting and alteration of this and other pattern pieces ' + + 'are likely to be needed. ' + + 'First, please retake your measurements and generate a new pattern ' + + 'using the new measurements. ' + + 'If you still see this warning with the new pattern, then please ' + + 'make a test garment, check fit, and make alterations as necessary ' + + 'before trying to make the final garment.' + ) + } + return part } diff --git a/designs/titan/src/front.mjs b/designs/titan/src/front.mjs index 5e057735f89..cb3ec9ac5ea 100644 --- a/designs/titan/src/front.mjs +++ b/designs/titan/src/front.mjs @@ -16,6 +16,7 @@ function titanFront({ Snippet, sa, absoluteOptions, + log, part, }) { /* @@ -173,6 +174,8 @@ function titanFront({ const adaptOutseam = () => adaptSeam('out') const adaptInseam = () => adaptSeam('in') + let adjustment_warning = false + // Let's get to work points.waistX = new Point(measurements.waistFrontArc * (1 + options.waistEase), 0) points.upperLegY = new Point(0, measurements.waistToUpperLeg) @@ -235,19 +238,42 @@ function titanFront({ if (options.fitCrossSeam && options.fitCrossSeamFront) { let delta = crotchSeamDelta() + let previous_delta = delta let rotate = ['waistIn', 'waistOut', 'cfWaist'] + let saved = [] let run = 0 do { + previous_delta = delta run++ // Remedy A: Slash and spread - for (const i of rotate) points[i] = points[i].rotate(delta / -15, points.seatOut) + for (const i of rotate) { + saved[i] = points[i] + points[i] = points[i].rotate(delta / -15, points.seatOut) + } // Remedy B: Nudge the fork inwards/outwards + saved.fork = points.fork points.fork = points.fork.shift(180, delta / 5) drawCrotchSeam() delta = crotchSeamDelta() // Uncomment the line below this to see all iterations // paths[`try${run}`] = drawPath().attr('class', 'dotted') - } while (Math.abs(delta) > 1 && run < 15) + } while (Math.abs(delta) > 1 && run < 15 && Math.abs(delta) < Math.abs(previous_delta)) + if (Math.abs(delta) > Math.abs(previous_delta)) { + // The rotations started to produce worse results. + // Revert back to the previous rotation. + for (const i of rotate) { + points[i] = saved[i] + } + points.fork = saved.fork + } + if (Math.abs(delta) > 1 || Math.abs(delta) > Math.abs(previous_delta)) { + log.warning( + 'Unable to adjust the front crotch seam to fit the given measurements, after ' + + run + + ' iterations.' + ) + adjustment_warning = true + } } // Uncomment this to see the outline prior to fitting the inseam & outseam @@ -563,6 +589,19 @@ function titanFront({ } } + if (adjustment_warning) { + log.warning( + 'We were not able to generate the Front pattern piece correctly. ' + + 'Manual fitting and alteration of this and other pattern pieces ' + + 'are likely to be needed. ' + + 'First, please retake your measurements and generate a new pattern ' + + 'using the new measurements. ' + + 'If you still see this warning with the new pattern, then please ' + + 'make a test garment, check fit, and make alterations as necessary ' + + 'before trying to make the final garment.' + ) + } + return part }