1
0
Fork 0
freesewing/designs/bruce/src/front.mjs

278 lines
8.3 KiB
JavaScript
Raw Normal View History

2022-09-04 06:43:17 -07:00
import { inset } from './inset.mjs'
import { init } from './init.mjs'
2018-09-04 16:51:39 +02:00
2022-09-11 12:42:23 +02:00
function tuskDelta(Path, points, store) {
const len = new Path()
2018-09-04 16:51:39 +02:00
.move(points.midRight)
2019-08-03 15:03:33 +02:00
.curve(points.curveRightCpTop, points.curveRightCpBottom, points.rightTuskRight)
.length()
2018-09-04 16:51:39 +02:00
2019-08-03 15:03:33 +02:00
return len - store.get('curve')
2018-09-04 16:51:39 +02:00
}
2022-09-11 12:42:23 +02:00
function tweakTusk(delta, points) {
2019-08-03 15:03:33 +02:00
let factor
if (Math.abs(delta) > 2) factor = 3
else factor = 5
2018-09-04 16:51:39 +02:00
2019-08-03 15:03:33 +02:00
points.rightTuskRight = points.rightTuskRight.shift(90, delta / factor)
points.rightTuskLeft = points.rightTuskLeft.shift(90, delta / factor)
points.curveRightCpBottom = points.curveRightCpBottom.shift(90, delta / factor)
2018-09-04 16:51:39 +02:00
}
2022-09-11 12:42:23 +02:00
function draftBruceFront({
store,
sa,
Point,
points,
Path,
paths,
options,
complete,
paperless,
macro,
snippets,
Snippet,
part,
}) {
2018-12-19 12:14:48 +01:00
// Initialize
2019-08-03 15:03:33 +02:00
init(part)
2018-12-19 12:14:48 +01:00
2019-08-03 15:03:33 +02:00
points.topRight = new Point(store.get('hipsFront') / 2, 0)
points.topLeft = points.topRight.flipX()
points.midMid = new Point(0, store.get('heightFront'))
points.midRight = new Point(points.topRight.x + store.get('heightFront') * 0.05, points.midMid.y)
points.midLeft = points.midRight.flipX()
2018-12-19 12:14:48 +01:00
// Store this length for a notch on the side part
2019-08-03 15:03:33 +02:00
store.set('frontNotch', points.topRight.dist(points.midRight))
2018-12-19 12:14:48 +01:00
2019-08-03 15:03:33 +02:00
points.bottomMid = new Point(0, store.get('riseLength'))
2018-12-19 12:14:48 +01:00
points.rightTuskRight = new Point(
2019-08-03 15:03:33 +02:00
store.get('gusset') * store.get('xScale') * (1 - store.get('gussetInsetRatio')),
2018-12-19 12:14:48 +01:00
points.bottomMid.y
2019-08-03 15:03:33 +02:00
)
points.rightTuskLeft = points.bottomMid.clone()
points.curveRightCpTop = new Point(
2019-08-03 15:03:33 +02:00
points.midRight.x - store.get('gusset') * 1.3,
points.midRight.y
2019-08-03 15:03:33 +02:00
)
points.curveRightCpBottom = new Point(
points.rightTuskRight.x,
2019-08-03 15:03:33 +02:00
points.rightTuskRight.y - store.get('gusset') * 1.3
)
2018-12-19 12:14:48 +01:00
// Adjust tusk length to fit inset curve
2022-09-11 12:42:23 +02:00
let delta = tuskDelta(Path, points, store)
2019-08-03 15:03:33 +02:00
let count = 0
while (Math.abs(delta) > 1) {
// Below 1mm is good enough
2022-09-11 12:42:23 +02:00
tweakTusk(delta, points)
delta = tuskDelta(Path, points, store)
2019-08-03 15:03:33 +02:00
count++
if (count > 150)
2019-08-03 15:03:33 +02:00
throw 'We got stuck trying to calculate an optimal tusk length. Please report this.'
2018-12-19 12:14:48 +01:00
}
// Adjust midMid to new length
2019-08-03 15:03:33 +02:00
points.bottomMid = new Point(0, points.rightTuskLeft.y)
2018-09-04 16:51:39 +02:00
2018-12-19 12:14:48 +01:00
// Front dart only if bulge > 0
if (options.bulge > 0) {
// Rotate tusk according to bulge option
2019-08-03 15:03:33 +02:00
for (let pid of ['curveRightCpTop', 'curveRightCpBottom', 'rightTuskRight', 'rightTuskLeft']) {
points[pid] = points[pid].rotate(options.bulge, points.midRight)
}
2018-09-04 16:51:39 +02:00
// Dart join point
2019-08-03 15:03:33 +02:00
points.dartJoin = new Point(0, points.midMid.y + 0.65 * points.midMid.dist(points.bottomMid))
2018-09-04 16:51:39 +02:00
// Dart control point
points.dartCpRight = new Point(
0,
2019-08-03 15:03:33 +02:00
points.dartJoin.y + points.dartJoin.dist(points.bottomMid) * (options.bulge / 30)
)
points.dartCpRight = points.dartCpRight.rotate(options.bulge, points.dartJoin)
2018-09-04 16:51:39 +02:00
// Flip control point to left side
2019-08-03 15:03:33 +02:00
points.dartCpLeft = points.dartCpRight.flipX()
2018-12-19 12:14:48 +01:00
} else {
2019-08-03 15:03:33 +02:00
points.dartJoin = points.rightTuskLeft
2018-12-19 12:14:48 +01:00
}
2018-09-04 16:51:39 +02:00
2018-12-19 12:14:48 +01:00
// Flip points to left side
2019-08-03 15:03:33 +02:00
points.leftTuskRight = points.rightTuskLeft.flipX()
points.leftTuskLeft = points.rightTuskRight.flipX()
points.curveLeftCpBottom = points.curveRightCpBottom.flipX()
points.curveLeftCpTop = points.curveRightCpTop.flipX()
2018-12-19 12:14:48 +01:00
// Handle back rise
2019-08-03 15:03:33 +02:00
points.topMid = new Point(0, points.topLeft.y)
points.topLeft = points.topLeft.shift(90, store.get('frontRise'))
points.topRight = points.topRight.shift(90, store.get('frontRise'))
points.topMidCpRight = new Point(points.topRight.x / 2, points.topMid.y)
points.topMidCpLeft = points.topMidCpRight.flipX()
2018-12-19 12:14:48 +01:00
if (options.bulge > 0) {
2018-12-19 12:14:48 +01:00
paths.trimBase = new Path()
.move(points.rightTuskLeft)
.curve(points.rightTuskLeft, points.dartCpRight, points.dartJoin)
2019-08-03 15:03:33 +02:00
.curve(points.dartCpLeft, points.leftTuskRight, points.leftTuskRight)
2018-12-19 12:14:48 +01:00
paths.seamStart = new Path()
.move(points.midLeft)
.line(points.topLeft)
.curve(points.topLeft, points.topMidCpLeft, points.topMid)
.curve(points.topMidCpRight, points.topRight, points.topRight)
.line(points.midRight)
2019-08-03 15:03:33 +02:00
.curve(points.curveRightCpTop, points.curveRightCpBottom, points.rightTuskRight)
.line(points.rightTuskLeft)
2018-12-19 12:14:48 +01:00
paths.seamEnd = new Path()
.move(points.leftTuskRight)
.line(points.leftTuskLeft)
2019-08-03 15:03:33 +02:00
.curve(points.curveLeftCpBottom, points.curveLeftCpTop, points.midLeft)
2022-09-18 17:01:19 +02:00
paths.seamStart.hide()
paths.trimBase.hide()
paths.seamEnd.hide()
2019-08-03 15:03:33 +02:00
paths.seam = paths.seamStart.join(paths.trimBase).join(paths.seamEnd)
2018-12-19 12:14:48 +01:00
} else {
paths.seam = new Path()
.move(points.midLeft)
.line(points.topLeft)
.curve(points.topLeft, points.topMidCpLeft, points.topMid)
.curve(points.topMidCpRight, points.topRight, points.topRight)
.line(points.midRight)
2019-08-03 15:03:33 +02:00
.curve(points.curveRightCpTop, points.curveRightCpBottom, points.rightTuskRight)
2018-12-19 12:14:48 +01:00
.line(points.leftTuskLeft)
2019-08-03 15:03:33 +02:00
.curve(points.curveLeftCpBottom, points.curveLeftCpTop, points.midLeft)
2018-12-19 12:14:48 +01:00
}
2019-08-03 15:03:33 +02:00
paths.seam.close().attr('class', 'fabric')
2018-12-19 12:14:48 +01:00
// Complete pattern?
if (complete) {
if (sa) {
if (options.bulge > 0) {
2019-08-03 15:03:33 +02:00
let saStart = paths.seamStart.offset(sa * -1)
let saTrim = paths.trimBase.offset(sa * -1).trim()
let saEnd = paths.seamEnd.offset(sa * -1)
paths.sa = saStart.join(saTrim).join(saEnd).close().attr('class', 'fabric sa')
2018-12-19 12:14:48 +01:00
} else {
paths.sa = paths.seam
.offset(sa * -1)
.trim()
.close()
2019-08-03 15:03:33 +02:00
.attr('class', 'fabric sa')
2018-12-19 12:14:48 +01:00
}
2018-09-04 16:51:39 +02:00
}
2019-08-03 15:03:33 +02:00
macro('title', {
2018-12-19 12:14:48 +01:00
at: points.midMid,
nr: 2,
2021-04-24 10:16:31 +02:00
title: 'front',
2019-08-03 15:03:33 +02:00
})
macro('grainline', {
2018-12-19 12:14:48 +01:00
from: points.dartJoin,
2021-04-24 10:16:31 +02:00
to: points.topMid,
2019-08-03 15:03:33 +02:00
})
2021-02-07 10:42:17 +01:00
snippets.sideNotch = new Snippet('notch', points.midRight)
points.curveNotch = new Path()
.move(points.midRight)
.curve(points.curveRightCpTop, points.curveRightCpBottom, points.rightTuskRight)
.shiftFractionAlong(0.5)
snippets.curveNotch1 = new Snippet('notch', points.curveNotch)
snippets.curveNotch2 = new Snippet('notch', points.curveNotch.flipX())
2018-12-19 12:14:48 +01:00
}
// Paperless?
if (paperless) {
2019-08-03 15:03:33 +02:00
macro('hd', {
2018-12-19 12:14:48 +01:00
from: points.topLeft,
to: points.topRight,
2021-04-24 10:16:31 +02:00
y: points.topLeft.y - 15 - sa,
2019-08-03 15:03:33 +02:00
})
macro('hd', {
2018-12-19 12:14:48 +01:00
from: points.midLeft,
to: points.midRight,
2021-04-24 10:16:31 +02:00
y: points.topLeft.y - 30 - sa,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2018-12-19 12:14:48 +01:00
from: points.midLeft,
to: points.topMid,
2021-04-24 10:16:31 +02:00
x: points.midLeft.x - 15 - sa,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2018-12-19 12:14:48 +01:00
from: points.midLeft,
to: points.topLeft,
2021-04-24 10:16:31 +02:00
x: points.midLeft.x - 30 - sa,
2019-08-03 15:03:33 +02:00
})
if (options.bulge === 0) {
2019-08-03 15:03:33 +02:00
macro('hd', {
2018-12-19 12:14:48 +01:00
from: points.leftTuskLeft,
to: points.rightTuskRight,
2021-04-24 10:16:31 +02:00
y: points.leftTuskLeft.y + 15 + sa,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2018-12-19 12:14:48 +01:00
from: points.leftTuskLeft,
to: points.topLeft,
2021-04-24 10:16:31 +02:00
x: points.midLeft.x - 45 - sa,
2019-08-03 15:03:33 +02:00
})
2018-09-07 16:35:37 +02:00
} else {
2019-08-03 15:03:33 +02:00
macro('vd', {
2018-12-19 12:14:48 +01:00
from: points.leftTuskLeft,
to: points.topLeft,
2021-04-24 10:16:31 +02:00
x: points.midLeft.x - 45 - sa,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2018-12-19 12:14:48 +01:00
from: points.leftTuskRight,
to: points.topLeft,
2021-04-24 10:16:31 +02:00
x: points.midLeft.x - 60 - sa,
2019-08-03 15:03:33 +02:00
})
2018-12-19 12:14:48 +01:00
points.narrowRight = new Path()
.move(points.midRight)
2019-08-03 15:03:33 +02:00
.curve(points.curveRightCpTop, points.curveRightCpBottom, points.rightTuskRight)
.edge('left')
2018-12-19 12:14:48 +01:00
points.narrowLeft = new Path()
.move(points.midLeft)
2019-08-03 15:03:33 +02:00
.curve(points.curveLeftCpTop, points.curveLeftCpBottom, points.leftTuskLeft)
.attr('class', 'various stroke-xl lashed')
.edge('right')
macro('hd', {
2018-12-19 12:14:48 +01:00
from: points.narrowLeft,
to: points.narrowRight,
2021-04-24 10:16:31 +02:00
y: points.narrowLeft.y,
2019-08-03 15:03:33 +02:00
})
macro('hd', {
2018-12-19 12:14:48 +01:00
from: points.leftTuskRight,
to: points.rightTuskLeft,
2021-04-24 10:16:31 +02:00
y: points.rightTuskLeft.y + 15 + sa,
2019-08-03 15:03:33 +02:00
})
macro('hd', {
2018-12-19 12:14:48 +01:00
from: points.leftTuskLeft,
to: points.rightTuskRight,
2021-04-24 10:16:31 +02:00
y: points.rightTuskLeft.y + 30 + sa,
2019-08-03 15:03:33 +02:00
})
macro('ld', {
2018-12-19 12:14:48 +01:00
from: points.rightTuskLeft,
to: points.rightTuskRight,
2021-04-24 10:16:31 +02:00
d: -15 - sa,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2018-12-19 12:14:48 +01:00
from: points.narrowRight,
to: points.topRight,
2021-04-24 10:16:31 +02:00
x: points.topRight.x + 15 + sa,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2018-12-19 12:14:48 +01:00
from: points.dartJoin,
to: points.topRight,
2021-04-24 10:16:31 +02:00
x: points.topRight.x + 30 + sa,
2019-08-03 15:03:33 +02:00
})
2018-09-04 16:51:39 +02:00
}
}
2019-08-03 15:03:33 +02:00
return part
}
2022-09-04 06:43:17 -07:00
export const front = {
name: 'bruce.front',
after: inset,
draft: draftBruceFront,
}