1
0
Fork 0
freesewing/packages/simon/src/collar.js

174 lines
5.2 KiB
JavaScript
Raw Normal View History

export default (part) => {
2018-12-27 15:04:32 +01:00
let {
measurements,
utils,
sa,
Point,
points,
Path,
paths,
complete,
paperless,
macro,
2021-04-24 10:16:31 +02:00
options,
2019-08-03 15:03:33 +02:00
} = part.shorthand()
2018-12-24 15:53:34 +01:00
const draft = function (tweak = 1) {
let length = measurements.neck * (1 + options.collarEase - options.collarGap) * tweak
2019-08-03 15:03:33 +02:00
let width = options.collarStandWidth * (1 + options.collarRoll)
2018-12-24 15:53:34 +01:00
// Draft right side
2019-08-03 15:03:33 +02:00
points.topMid = new Point(0, 0)
points.bottomMid = new Point(0, width)
points.bottomMidCp1 = points.bottomMid.shift(0, length * 0.35)
points.rightBottomEdge = new Point(length / 2, width + length * options.collarBend)
points.rightTopHinge = points.topMid.shift(0, length * 0.25)
points.rightTopEdgeDirection = points.rightTopHinge.shift(options.collarFlare, 10)
points.rightBottomEdgeDirection = points.rightBottomEdge.shift(options.collarAngle, 10)
2018-12-24 15:53:34 +01:00
points.rightTopEdge = utils.beamsIntersect(
points.rightTopHinge,
points.rightTopEdgeDirection,
points.rightBottomEdge,
points.rightBottomEdgeDirection
2019-08-03 15:03:33 +02:00
)
points.rightTopHingeCp1 = points.rightTopHinge.shift(0, length * 0.1)
2018-12-24 15:53:34 +01:00
// Draft left side
2019-08-03 15:03:33 +02:00
points.leftTopHinge = points.rightTopHinge.flipX()
points.bottomMidCp2 = points.bottomMidCp1.flipX()
points.leftTopHingeCp2 = points.rightTopHingeCp1.flipX()
points.leftTopEdge = points.rightTopEdge.flipX()
points.leftBottomEdge = points.rightBottomEdge.flipX()
2018-12-24 15:53:34 +01:00
let len = new Path()
.move(points.leftBottomEdge)
._curve(points.bottomMidCp2, points.bottomMid)
2019-08-03 15:03:33 +02:00
.length()
2018-12-24 15:53:34 +01:00
return len * 2 - measurements.neck * (1 + options.collarEase - options.collarGap)
2019-08-03 15:03:33 +02:00
}
2018-12-24 15:53:34 +01:00
2019-08-03 15:03:33 +02:00
let delta, tweak, run
tweak = 1
run = 1
2018-12-24 15:53:34 +01:00
do {
2019-08-03 15:03:33 +02:00
delta = draft(tweak)
tweak = tweak * (1 - delta / 1000)
run++
} while (Math.abs(delta) > 1 && run < 20)
2018-12-24 15:53:34 +01:00
paths.seam = new Path()
.move(points.bottomMid)
.curve_(points.bottomMidCp1, points.rightBottomEdge)
.line(points.rightTopEdge)
._curve(points.rightTopHingeCp1, points.rightTopHinge)
.line(points.topMid)
.line(points.leftTopHinge)
.curve_(points.leftTopHingeCp2, points.leftTopEdge)
.line(points.leftBottomEdge)
._curve(points.bottomMidCp2, points.bottomMid)
.close()
2019-08-03 15:03:33 +02:00
.attr('class', 'fabric')
2018-12-24 15:53:34 +01:00
// Complete pattern?
if (complete) {
// Draw undercollar line
2019-08-03 15:03:33 +02:00
let uc = points.topMid.dist(points.bottomMid) * 0.05
points.ucTopMid = points.topMid.shift(-90, uc)
points.ucRightTopHinge = points.rightTopHinge.shift(-90, uc)
points.ucRightTopHingeCp1 = points.rightTopHingeCp1.shift(-90, uc)
points.ucLeftTopHinge = points.ucRightTopHinge.flipX()
points.ucLeftTopHingeCp2 = points.ucRightTopHingeCp1.flipX()
2018-12-24 15:53:34 +01:00
paths.underCollar = new Path()
.move(points.rightTopEdge)
._curve(points.ucRightTopHingeCp1, points.ucRightTopHinge)
.line(points.ucLeftTopHinge)
.curve_(points.ucLeftTopHingeCp2, points.leftTopEdge)
2019-08-03 15:03:33 +02:00
.attr('class', 'dotted')
.attr('data-text', 'cutUndercollarSlightlySmaller')
.attr('data-text-class', 'center')
2018-12-24 15:53:34 +01:00
// Helplines
paths.help = new Path().move(points.topMid).line(points.bottomMid).attr('class', 'dotted')
2018-12-24 15:53:34 +01:00
// Grainline
2019-08-03 15:03:33 +02:00
macro('grainline', {
2018-12-24 15:53:34 +01:00
from: points.bottomMidCp2.shift(90, 10),
2021-04-24 10:16:31 +02:00
to: points.bottomMidCp1.shift(90, 10),
2019-08-03 15:03:33 +02:00
})
2018-12-24 15:53:34 +01:00
// Title
2019-08-03 15:03:33 +02:00
points.title = new Point(20, points.bottomMid.y / 2)
macro('title', {
2018-12-24 15:53:34 +01:00
at: points.title,
nr: '7 + 8',
2019-08-03 15:03:33 +02:00
title: 'collarAndUndercollar',
2018-12-24 15:53:34 +01:00
scale: 0.6,
2021-04-24 10:16:31 +02:00
append: true,
2019-08-03 15:03:33 +02:00
})
2018-12-24 15:53:34 +01:00
// Indicate collar stand side
paths.collarStandLeft = new Path()
.move(points.leftBottomEdge)
._curve(points.bottomMidCp2, points.bottomMid)
2019-08-03 15:03:33 +02:00
.attr('data-text', 'sideOfTheCollarStand')
.attr('data-text-class', 'center')
2018-12-24 15:53:34 +01:00
paths.collarStandRight = new Path()
.move(points.bottomMid)
.curve_(points.bottomMidCp1, points.rightBottomEdge)
2019-08-03 15:03:33 +02:00
.attr('data-text', 'sideOfTheCollarStand')
.attr('data-text-class', 'center')
2018-12-24 15:53:34 +01:00
// Notches
2019-08-03 15:03:33 +02:00
macro('sprinkle', {
snippet: 'notch',
2021-04-24 10:16:31 +02:00
on: ['bottomMid', 'rightBottomEdge', 'leftBottomEdge', 'rightTopEdge', 'leftTopEdge'],
2019-08-03 15:03:33 +02:00
})
2018-12-24 15:53:34 +01:00
if (sa) {
2019-08-03 15:03:33 +02:00
paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa')
paths.saUndercollar = paths.underCollar.offset(sa).attr('class', 'dotted')
2018-12-24 15:53:34 +01:00
}
}
// Paperless?
if (paperless) {
2019-08-03 15:03:33 +02:00
macro('vd', {
2018-12-27 14:43:36 +01:00
from: points.bottomMid,
to: points.topMid,
2021-04-24 10:16:31 +02:00
x: points.rightTopEdge.x + 15 + sa,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2018-12-27 14:43:36 +01:00
from: points.bottomMid,
to: points.rightTopEdge,
2021-04-24 10:16:31 +02:00
x: points.rightTopEdge.x + 30 + sa,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2018-12-27 14:43:36 +01:00
from: points.rightBottomEdge,
to: points.topMid,
2021-04-24 10:16:31 +02:00
x: points.rightTopEdge.x + 45 + sa,
2019-08-03 15:03:33 +02:00
})
macro('vd', {
2018-12-27 14:43:36 +01:00
from: points.rightBottomEdge,
to: points.rightTopEdge,
2021-04-24 10:16:31 +02:00
x: points.rightTopEdge.x + 60 + sa,
2019-08-03 15:03:33 +02:00
})
macro('hd', {
2018-12-27 14:43:36 +01:00
from: points.leftTopHinge,
to: points.rightTopHinge,
2021-04-24 10:16:31 +02:00
y: points.leftTopEdge.y - 15 - sa,
2019-08-03 15:03:33 +02:00
})
macro('hd', {
2018-12-27 14:43:36 +01:00
from: points.leftTopEdge,
to: points.rightTopEdge,
2021-04-24 10:16:31 +02:00
y: points.leftTopEdge.y - 30 - sa,
2019-08-03 15:03:33 +02:00
})
macro('hd', {
2018-12-27 14:43:36 +01:00
from: points.leftBottomEdge,
to: points.rightBottomEdge,
2021-04-24 10:16:31 +02:00
y: points.leftBottomEdge.y + 15 + sa,
2019-08-03 15:03:33 +02:00
})
2018-12-24 15:53:34 +01:00
}
2019-08-03 15:03:33 +02:00
return part
}