1
0
Fork 0
freesewing/packages/benjamin/src/base.js

215 lines
6.4 KiB
JavaScript
Raw Normal View History

2019-07-08 11:54:47 +02:00
export default function(part) {
let {
store,
sa,
Point,
points,
Path,
paths,
Snippet,
snippets,
options,
measurements,
2019-07-08 15:54:19 +02:00
complete,
2019-07-08 11:54:47 +02:00
paperless,
macro
2019-08-03 15:03:33 +02:00
} = part.shorthand()
2019-07-08 11:54:47 +02:00
2019-08-03 15:03:33 +02:00
if (options.bowStyle === 'square') options.tipWidth = options.knotWidth
2019-07-08 11:54:47 +02:00
for (let option of [
2019-08-03 15:03:33 +02:00
'ribbonWidth',
'bandLength',
'tipWidth',
'knotWidth',
'bowLength',
'collarEase'
2019-07-08 11:54:47 +02:00
])
2019-08-03 15:03:33 +02:00
store.set(option, measurements.neckCircumference * options[option])
2019-07-08 11:54:47 +02:00
// For easy access
2019-08-03 15:03:33 +02:00
const knot = store.get('knotWidth')
const ribbon = store.get('ribbonWidth')
const tip = store.get('tipWidth')
const band = store.get('bandLength')
const transition = band * options.transitionLength
const bow = store.get('bowLength')
2019-07-08 11:54:47 +02:00
// Points
2019-08-03 15:03:33 +02:00
points.bandBottomLeft = new Point(0, ribbon / 2)
points.bandTopLeft = points.bandBottomLeft.flipY()
points.bandBottomRight = points.bandBottomLeft.shift(0, band)
points.bandTopRight = points.bandBottomRight.flipY()
2019-07-08 11:54:47 +02:00
2019-08-03 15:03:33 +02:00
points.transitionBottomRight = new Point(band + transition, knot / 2)
points.transitionTopRight = points.transitionBottomRight.flipY()
2019-07-08 11:54:47 +02:00
2019-08-03 15:03:33 +02:00
points.tip1Bottom = new Point(band + transition + 0.5 * bow, tip / 2)
points.tip1Top = points.tip1Bottom.flipY()
points.tip2Bottom = new Point(band + transition + 1.5 * bow, tip / 2)
points.tip2Top = points.tip2Bottom.flipY()
points.knotBottom = new Point(band + transition + bow, knot / 2)
points.knotTop = points.knotBottom.flipY()
2019-07-08 11:54:47 +02:00
2019-08-03 15:03:33 +02:00
if (options.endStyle === 'pointed' || options.endStyle === 'rounded') {
points.tip = new Point(points.tip2Bottom.x + points.tip2Bottom.y, 0)
} else points.tip = new Point(points.tip2Bottom.x, 0)
2019-07-08 11:54:47 +02:00
2019-08-03 15:03:33 +02:00
points.grainlineStart = new Point(0, 0)
points.titleAnchor = new Point(points.tip1Top.x, 0)
2019-07-08 15:54:19 +02:00
// Paths
2019-08-03 15:03:33 +02:00
paths.cap = new Path().move(points.tip2Bottom)
if (options.endStyle === 'straight') {
paths.cap = new Path().move(points.tip2Bottom).line(points.tip2Top)
} else if (options.endStyle === 'pointed') {
2019-07-08 15:54:19 +02:00
paths.cap = new Path()
.move(points.tip2Bottom)
.line(points.tip)
2019-08-03 15:03:33 +02:00
.line(points.tip2Top)
2019-07-08 15:54:19 +02:00
} else {
2019-08-03 15:03:33 +02:00
points.roundBottom = new Point(points.tip.x, points.tip2Bottom.y)
points.roundTop = points.roundBottom.flipY()
macro('round', {
2019-07-08 15:54:19 +02:00
from: points.tip2Bottom,
to: points.tip,
via: points.roundBottom,
2019-08-03 15:03:33 +02:00
prefix: 'bottom'
})
macro('round', {
2019-07-08 15:54:19 +02:00
from: points.tip,
to: points.tip2Top,
via: points.roundTop,
2019-08-03 15:03:33 +02:00
prefix: 'top'
})
paths.cap = paths.bottomRounded.join(paths.topRounded)
2019-07-08 15:54:19 +02:00
}
2019-08-03 15:03:33 +02:00
paths.cap.render = false
2019-07-08 15:54:19 +02:00
2019-08-03 15:03:33 +02:00
if (options.bowStyle === 'diamond' || options.bowStyle === 'butterfly') {
const cpl = options.bowStyle === 'diamond' ? bow / 10 : bow / 4
2019-07-08 11:54:47 +02:00
2019-07-08 15:54:19 +02:00
points.transitionBottomRightCp2 = points.bandBottomRight.shiftOutwards(
2019-07-08 11:54:47 +02:00
points.transitionBottomRight,
cpl
2019-08-03 15:03:33 +02:00
)
points.transitionTopRightCp1 = points.transitionBottomRightCp2.flipY()
points.tip1TopCp2 = points.tip1Top.shift(180, cpl)
points.tip1TopCp1 = points.tip1Top.shift(0, cpl)
points.tip1BottomCp1 = points.tip1Bottom.shift(180, cpl)
points.tip1BottomCp2 = points.tip1Bottom.shift(0, cpl)
points.knotTopCp2 = points.knotTop.shift(180, cpl)
points.knotTopCp1 = points.knotTop.shift(0, cpl)
points.knotBottomCp2 = points.knotBottom.shift(0, cpl)
points.knotBottomCp1 = points.knotBottom.shift(180, cpl)
points.tip2TopCp2 = points.tip2Top.shift(180, cpl)
points.tip2BottomCp1 = points.tip2Bottom.shift(180, cpl)
2019-07-08 11:54:47 +02:00
2019-07-08 15:54:19 +02:00
paths.seam = new Path()
.move(points.bandTopLeft)
.line(points.bandBottomLeft)
.line(points.bandBottomRight)
.line(points.transitionBottomRight)
2019-08-03 15:03:33 +02:00
.curve(points.transitionBottomRightCp2, points.tip1BottomCp1, points.tip1Bottom)
2019-07-08 15:54:19 +02:00
.curve(points.tip1BottomCp2, points.knotBottomCp1, points.knotBottom)
.curve(points.knotBottomCp2, points.tip2BottomCp1, points.tip2Bottom)
.join(paths.cap)
.line(points.tip2Top)
.curve(points.tip2TopCp2, points.knotTopCp1, points.knotTop)
.curve(points.knotTopCp2, points.tip1TopCp1, points.tip1Top)
2019-08-03 15:03:33 +02:00
.curve(points.tip1TopCp2, points.transitionTopRightCp1, points.transitionTopRight)
2019-07-08 15:54:19 +02:00
.line(points.bandTopRight)
.line(points.bandTopLeft)
2019-08-03 15:03:33 +02:00
.close()
2019-07-08 11:54:47 +02:00
} else {
2019-07-08 15:54:19 +02:00
paths.seam = new Path()
.move(points.bandTopLeft)
.line(points.bandBottomLeft)
.line(points.bandBottomRight)
.line(points.transitionBottomRight)
.line(points.tip2Bottom)
.join(paths.cap)
.line(points.tip2Top)
.line(points.transitionTopRight)
.line(points.bandTopRight)
.line(points.bandTopLeft)
2019-08-03 15:03:33 +02:00
.close()
2019-07-08 11:54:47 +02:00
}
2019-08-03 15:03:33 +02:00
paths.seam.attr('class', 'fabric')
2019-07-08 11:54:47 +02:00
2019-07-08 15:54:19 +02:00
// Complete?
if (complete) {
2019-08-03 15:03:33 +02:00
if (sa) paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa')
2019-07-08 11:54:47 +02:00
2019-08-03 15:03:33 +02:00
macro('grainline', {
2019-07-08 15:54:19 +02:00
from: points.grainlineStart,
to: points.tip
2019-08-03 15:03:33 +02:00
})
points.logoAnchor = points.tip.shift(180, 20)
snippets.logo = new Snippet('logo', points.logoAnchor).attr('data-scale', 0.5)
2019-07-08 11:54:47 +02:00
2019-07-08 15:54:19 +02:00
// Paperless?
if (paperless) {
2019-08-03 15:03:33 +02:00
let baseY = points.tip2Bottom.y + 15 + sa
if (options.bowStyle === 'butterfly' || options.bowStyle === 'diamond') {
macro('hd', {
2019-07-08 15:54:19 +02:00
from: points.knotBottom,
to: points.tip2Bottom,
y: baseY
2019-08-03 15:03:33 +02:00
})
baseY += 15
macro('hd', {
2019-07-08 15:54:19 +02:00
from: points.tip1Bottom,
to: points.tip2Bottom,
y: baseY
2019-08-03 15:03:33 +02:00
})
baseY += 15
macro('vd', {
2019-07-08 15:54:19 +02:00
from: points.tip1Bottom,
to: points.tip1Top
2019-08-03 15:03:33 +02:00
})
2019-07-08 15:54:19 +02:00
}
2019-08-03 15:03:33 +02:00
macro('hd', {
2019-07-08 15:54:19 +02:00
from: points.transitionBottomRight,
to: points.tip2Bottom,
y: baseY
2019-08-03 15:03:33 +02:00
})
baseY += 15
macro('hd', {
2019-07-08 15:54:19 +02:00
from: points.bandBottomRight,
to: points.tip2Bottom,
y: baseY
2019-08-03 15:03:33 +02:00
})
baseY += 15
macro('hd', {
2019-07-08 15:54:19 +02:00
from: points.bandBottomLeft,
to: points.tip2Bottom,
y: baseY
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2019-07-08 15:54:19 +02:00
from: points.bandBottomRight,
to: points.bandTopRight
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2019-07-08 15:54:19 +02:00
from: points.transitionBottomRight,
to: points.transitionTopRight
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2019-07-08 15:54:19 +02:00
from: points.tip2Bottom,
to: points.tip2Top,
x: points.tip.x + 15 + sa
2019-08-03 15:03:33 +02:00
})
if (options.endStyle !== 'straight') {
macro('hd', {
2019-07-08 15:54:19 +02:00
from: points.tip2Bottom,
to: points.tip,
y: points.tip2Bottom.y + 15 + sa
2019-08-03 15:03:33 +02:00
})
2019-07-08 11:54:47 +02:00
}
}
}
2019-08-03 15:03:33 +02:00
return part
2019-07-08 11:54:47 +02:00
}