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

226 lines
6.5 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
} = part.shorthand();
if (options.bowStyle === "square") options.tipWidth = options.knotWidth;
for (let option of [
"ribbonWidth",
"bandLength",
"tipWidth",
"knotWidth",
"bowLength",
"collarEase"
])
store.set(option, measurements.neckCircumference * options[option]);
// For easy access
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");
// Points
2019-07-08 15:54:19 +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-07-08 15:54:19 +02:00
points.transitionBottomRight = new Point(band + transition, knot / 2);
points.transitionTopRight = points.transitionBottomRight.flipY();
2019-07-08 11:54:47 +02:00
2019-07-08 15:54:19 +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
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 15:54:19 +02:00
points.grainlineStart = new Point(0, 0);
points.titleAnchor = new Point(points.tip1Top.x, 0);
// Paths
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") {
paths.cap = new Path()
.move(points.tip2Bottom)
.line(points.tip)
.line(points.tip2Top);
} else {
points.roundBottom = new Point(points.tip.x, points.tip2Bottom.y);
points.roundTop = points.roundBottom.flipY();
macro("round", {
from: points.tip2Bottom,
to: points.tip,
via: points.roundBottom,
prefix: "bottom"
});
macro("round", {
from: points.tip,
to: points.tip2Top,
via: points.roundTop,
prefix: "top"
});
paths.cap = paths.bottomRounded.join(paths.topRounded);
}
paths.cap.render = false;
2019-07-08 11:54:47 +02:00
if (options.bowStyle === "diamond" || options.bowStyle === "butterfly") {
const cpl = options.bowStyle === "diamond" ? bow / 10 : bow / 4;
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-07-08 15:54:19 +02:00
points.transitionTopRightCp1 = points.transitionBottomRightCp2.flipY();
2019-07-08 11:54:47 +02:00
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 15:54:19 +02:00
paths.seam = new Path()
.move(points.bandTopLeft)
.line(points.bandBottomLeft)
.line(points.bandBottomRight)
.line(points.transitionBottomRight)
.curve(
points.transitionBottomRightCp2,
points.tip1BottomCp1,
points.tip1Bottom
)
.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)
.curve(
points.tip1TopCp2,
points.transitionTopRightCp1,
points.transitionTopRight
)
.line(points.bandTopRight)
.line(points.bandTopLeft)
.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)
.close();
2019-07-08 11:54:47 +02:00
}
2019-07-08 15:54:19 +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) {
if (sa) paths.sa = paths.seam.offset(sa).attr("class", "fabric sa");
2019-07-08 11:54:47 +02:00
macro("grainline", {
2019-07-08 15:54:19 +02:00
from: points.grainlineStart,
to: points.tip
2019-07-08 11:54:47 +02:00
});
2019-07-08 15:54:19 +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) {
let baseY = points.tip2Bottom.y + 15 + sa;
if (options.bowStyle === "butterfly" || options.bowStyle === "diamond") {
macro("hd", {
from: points.knotBottom,
to: points.tip2Bottom,
y: baseY
});
baseY += 15;
macro("hd", {
from: points.tip1Bottom,
to: points.tip2Bottom,
y: baseY
});
baseY += 15;
macro("vd", {
from: points.tip1Bottom,
to: points.tip1Top
});
}
2019-07-08 11:54:47 +02:00
macro("hd", {
2019-07-08 15:54:19 +02:00
from: points.transitionBottomRight,
to: points.tip2Bottom,
y: baseY
2019-07-08 11:54:47 +02:00
});
2019-07-08 15:54:19 +02:00
baseY += 15;
2019-07-08 11:54:47 +02:00
macro("hd", {
2019-07-08 15:54:19 +02:00
from: points.bandBottomRight,
to: points.tip2Bottom,
y: baseY
2019-07-08 11:54:47 +02:00
});
2019-07-08 15:54:19 +02:00
baseY += 15;
2019-07-08 11:54:47 +02:00
macro("hd", {
2019-07-08 15:54:19 +02:00
from: points.bandBottomLeft,
to: points.tip2Bottom,
y: baseY
2019-07-08 11:54:47 +02:00
});
macro("vd", {
2019-07-08 15:54:19 +02:00
from: points.bandBottomRight,
to: points.bandTopRight
2019-07-08 11:54:47 +02:00
});
macro("vd", {
2019-07-08 15:54:19 +02:00
from: points.transitionBottomRight,
to: points.transitionTopRight
2019-07-08 11:54:47 +02:00
});
2019-07-08 15:54:19 +02:00
macro("vd", {
from: points.tip2Bottom,
to: points.tip2Top,
x: points.tip.x + 15 + sa
});
if (options.endStyle !== "straight") {
macro("hd", {
from: points.tip2Bottom,
to: points.tip,
y: points.tip2Bottom.y + 15 + sa
2019-07-08 11:54:47 +02:00
});
}
}
}
return part;
}