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

251 lines
7 KiB
JavaScript
Raw Normal View History

2018-12-21 18:19:21 +01:00
export const calculateReduction = function(part) {
let { store, measurements, options } = part.shorthand();
2018-12-22 17:30:12 +01:00
if (store.get("reduction") === true) return;
2018-12-21 18:19:21 +01:00
2018-12-22 17:30:12 +01:00
let chest = measurements.chestCircumference * (1 + options.chestEase);
let waist = measurements.naturalWaist * (1 + options.waistEase);
let hips = measurements.hipsCircumference * (1 + options.hipsEase);
2018-12-21 18:19:21 +01:00
let waistReduction = chest - waist;
let hipsReduction = chest - hips;
// If your waist > chest, this pattern is not going to work for you as-is.
if (waistReduction < 0) waistReduction = 0;
if (hipsReduction < 0) hipsReduction = 0;
store.set("waistReduction", waistReduction);
store.set("hipsReduction", hipsReduction);
store.set("reduction", true);
2018-12-22 17:30:12 +01:00
};
2018-12-21 18:19:21 +01:00
2018-12-23 12:13:37 +01:00
export const addButtons = function(
part,
origin = "cfNeck",
snippet = "button"
) {
2018-12-22 17:30:12 +01:00
let { points, options, snippets, Snippet } = part.shorthand();
let len = points.cfNeck.dist(points.cfHips) * (1 - options.buttonFreeLength);
for (let i = 1; i <= options.buttons; i++) {
2018-12-23 12:13:37 +01:00
points["button" + i] = points[origin].shift(
2018-12-22 17:30:12 +01:00
-90,
(len / options.buttons) * i
);
2018-12-23 12:13:37 +01:00
snippets[snippet + i] = new Snippet(snippet, points["button" + i]);
2018-12-22 17:30:12 +01:00
}
if (options.extraTopButton === "yes")
2018-12-23 12:13:37 +01:00
snippets["top" + snippet] = new Snippet(
snippet,
points[origin].shift(-90, len / options.buttons / 2)
2018-12-22 17:30:12 +01:00
);
};
2018-12-23 12:13:37 +01:00
2018-12-23 13:57:40 +01:00
export const addButtonHoles = (part, origin) =>
addButtons(part, origin, "buttonhole");
2018-12-27 13:08:30 +01:00
export const draftBarrelCuff = part => {
let { store, points, measurements, options, Point } = part.shorthand();
let height = measurements.shoulderToWrist * options.cuffLength;
let width =
measurements.wristCircumference *
2018-12-27 16:42:27 +01:00
(1 + options.cuffEase + options.cuffOverlap);
2018-12-27 13:08:30 +01:00
store.set("cuffHeight", height);
points.topLeft = new Point(0, 0);
points.topRight = new Point(width, 0);
points.bottomLeft = new Point(0, height);
points.bottomRight = new Point(width, height);
return part;
};
export const decorateBarrelCuff = part => {
let {
macro,
snippets,
Snippet,
points,
measurements,
options,
Point
} = part.shorthand();
// Title
points.title = new Point(points.bottomRight.x / 2, points.bottomRight.y / 2);
macro("title", {
nr: 10,
title: "cuff",
at: points.title,
scale: 0.8
});
// Button and buttonhole
let margin = measurements.wristCircumference * options.cuffOverlap;
points.buttonLineTop = points.topRight.shift(180, margin / 2);
points.buttonLineBottom = points.bottomRight.shift(180, margin / 2);
points.buttonholeLineTop = points.topLeft.shift(0, margin / 2);
points.buttonholeLineBottom = points.bottomLeft.shift(0, margin / 2);
for (let i = 1; i <= options.cuffButtonRows; i++) {
points["button" + i] = points.buttonLineTop.shiftFractionTowards(
points.buttonLineBottom,
(1 / (options.cuffButtonRows + 1)) * i
);
snippets["button" + i] = new Snippet("button", points["button" + i]);
points["buttonhole" + i] = new Point(
points.buttonholeLineTop.x,
points["button" + i].y
);
snippets["buttonhole" + i] = new Snippet(
"buttonhole",
points["buttonhole" + i]
).attr("data-rotate", 90);
if (options.barrelcuffNarrowButton === "yes") {
points["narrowButton" + i] = points["button" + i].shift(180, margin);
snippets["narrowButton" + i] = new Snippet(
"button",
points["narrowButton" + i]
);
}
}
return part;
};
export const draftFrenchCuff = part => {
let { store, points, measurements, options, Point } = part.shorthand();
let margin = measurements.wristCircumference * options.cuffOverlap;
let height = measurements.shoulderToWrist * options.cuffLength;
let width =
measurements.wristCircumference *
(1 + options.cuffEase + options.cuffOverlap + options.cuffDrape) +
margin / 2;
store.set("cuffHeight", height);
points.topLeft = new Point(0, 0);
points.topRight = new Point(width, 0);
points.midLeft = new Point(0, height);
points.midRight = new Point(width, height);
points.bottomLeft = new Point(0, height * 2);
points.bottomRight = new Point(width, height * 2);
return part;
};
export const decorateFrenchCuff = part => {
let {
macro,
snippets,
Snippet,
points,
measurements,
options,
Point
} = part.shorthand();
// Title
points.title = new Point(points.bottomRight.x / 2, points.bottomRight.y / 2);
macro("title", {
nr: 10,
title: "cuff",
at: points.title,
scale: 0.8
});
// Buttonholes
let margin = measurements.wristCircumference * options.cuffOverlap;
points.buttonLineTop = points.topRight.shift(180, margin * 0.75);
points.buttonLineBottom = points.bottomRight.shift(180, margin * 0.75);
points.buttonholeLineTop = points.topLeft.shift(0, margin * 0.75);
points.buttonholeLineBottom = points.bottomLeft.shift(0, margin * 0.75);
points.button1 = points.buttonLineTop.shiftFractionTowards(
points.buttonLineBottom,
0.2
);
points.button2 = points.buttonLineTop.shiftFractionTowards(
points.buttonLineBottom,
0.8
);
points.button3 = points.buttonholeLineTop.shiftFractionTowards(
points.buttonholeLineBottom,
0.2
);
points.button4 = points.buttonholeLineTop.shiftFractionTowards(
points.buttonholeLineBottom,
0.8
);
snippets.buttonhole1 = new Snippet("buttonhole", points.button1).attr(
"data-rotate",
90
);
snippets.buttonhole2 = new Snippet("buttonhole", points.button2).attr(
"data-rotate",
90
);
snippets.buttonhole3 = new Snippet("buttonhole", points.button3).attr(
"data-rotate",
90
);
snippets.buttonhole4 = new Snippet("buttonhole", points.button4).attr(
"data-rotate",
90
);
return part;
};
2018-12-27 13:42:55 +01:00
export const paperlessBarrelCuff = part => {
2018-12-27 14:16:28 +01:00
let { sa, macro, points, options } = part.shorthand();
2018-12-27 13:42:55 +01:00
macro("hd", {
from: points.buttonhole1,
to: points.button1,
y: points.bottomLeft.y + 15 + sa
});
macro("hd", {
from: points.bottomLeft,
to: points.bottomRight,
y: points.bottomLeft.y + 30 + sa
});
macro("vd", {
from: points.bottomLeft,
to: points.topLeft.shift(0, 40),
x: points.bottomLeft.x - 15 - sa
});
2018-12-27 14:16:28 +01:00
if (options.barrelcuffNarrowButton === "yes") {
macro("hd", {
from: points.narrowButton1,
to: points.button1,
y: points.topRight.y - 15 - sa
});
}
if (options.cuffButtonRows === 2) {
macro("vd", {
from: points.button2,
to: points.button1,
x: points.topRight.x + 15 + sa
});
}
2018-12-27 13:42:55 +01:00
return part;
};
export const paperlessFrenchCuff = part => {
let { sa, macro, points } = part.shorthand();
macro("hd", {
from: points.button4,
to: points.button2,
y: points.bottomLeft.y + 15 + sa
});
macro("hd", {
from: points.midLeft,
to: points.midRight,
y: points.bottomLeft.y + 30 + sa
});
macro("vd", {
from: points.button2,
to: points.button1,
x: points.topRight.x + 15 + sa
});
macro("vd", {
from: points.bottomRight.shift(180, 40),
to: points.topRight.shift(180, 40),
x: points.topRight.x + 30 + sa
});
return part;
};