From e55122da445dd0147f86b18465d0b1c7e5a55f4d Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Sun, 28 Aug 2022 16:49:21 +0200 Subject: [PATCH] chore(albert): Ported to v3 --- designs/albert/build.mjs | 2 +- designs/albert/config/index.js | 29 --- designs/albert/package.json | 2 +- designs/albert/src/front.js | 185 ------------------- designs/albert/src/front.mjs | 202 +++++++++++++++++++++ designs/albert/src/{index.js => index.mjs} | 38 ++-- designs/albert/src/pocket.js | 85 --------- designs/albert/src/pocket.mjs | 93 ++++++++++ designs/albert/src/strap.js | 131 ------------- designs/albert/src/strap.mjs | 144 +++++++++++++++ designs/albert/tests/shared.test.mjs | 21 +-- 11 files changed, 473 insertions(+), 459 deletions(-) delete mode 100644 designs/albert/config/index.js delete mode 100644 designs/albert/src/front.js create mode 100644 designs/albert/src/front.mjs rename designs/albert/src/{index.js => index.mjs} (79%) delete mode 100644 designs/albert/src/pocket.js create mode 100644 designs/albert/src/pocket.mjs delete mode 100644 designs/albert/src/strap.js create mode 100644 designs/albert/src/strap.mjs diff --git a/designs/albert/build.mjs b/designs/albert/build.mjs index 9d1da1994da..0f283af1c6d 100644 --- a/designs/albert/build.mjs +++ b/designs/albert/build.mjs @@ -14,7 +14,7 @@ const banner = `/** const options = { banner: { js: banner }, bundle: true, - entryPoints: ['src/index.js'], + entryPoints: ['src/index.mjs'], format: 'esm', outfile: 'dist/index.mjs', external: ["@freesewing"], diff --git a/designs/albert/config/index.js b/designs/albert/config/index.js deleted file mode 100644 index f2d9f26268e..00000000000 --- a/designs/albert/config/index.js +++ /dev/null @@ -1,29 +0,0 @@ -import pkg from '../package.json' assert { type: 'json' } -const { version } = pkg - -export default { - version, - name: 'albert', - design: 'Wouter Van Wageningen', - code: 'Wouter Van Wageningen', - department: 'accessories', - type: 'pattern', - difficulty: 2, - optionGroups: { - fit: ['backOpening', 'chestDepth'], - style: ['lengthBonus', 'bibLength', 'bibWidth', 'strapWidth'], - }, - measurements: ['chest', 'waist', 'hips', 'hpsToWaistBack', 'waistToKnee'], - dependencies: {}, - inject: {}, - hide: [], - parts: ['front', 'strap', 'pocket'], - options: { - backOpening: { pct: 10, min: 0, max: 25 }, - lengthBonus: { pct: 0, min: -20, max: 25 }, - chestDepth: { pct: 22, min: 15, max: 90 }, - bibLength: { pct: 75, min: 0, max: 90 }, - bibWidth: { pct: 100, min: 50, max: 125 }, - strapWidth: { pct: 60, min: 20, max: 100 }, - }, -} diff --git a/designs/albert/package.json b/designs/albert/package.json index df026dab323..1030aa5f889 100644 --- a/designs/albert/package.json +++ b/designs/albert/package.json @@ -38,7 +38,7 @@ "vbuild": "VERBOSE=1 node --experimental-json-modules build.mjs", "lab": "cd ../../sites/lab && yarn start", "tips": "node ../../scripts/help.mjs", - "prettier": "npx prettier --write 'src/*.js' 'config/*.js'", + "prettier": "npx prettier --write 'src/*.mjs' 'tests/*.mjs'", "testci": "npx mocha tests/*.test.mjs --reporter ../../tests/reporters/terse.js", "cibuild_step5": "node --experimental-json-modules build.mjs" }, diff --git a/designs/albert/src/front.js b/designs/albert/src/front.js deleted file mode 100644 index 35d6a8d6bc5..00000000000 --- a/designs/albert/src/front.js +++ /dev/null @@ -1,185 +0,0 @@ -export default function (part) { - let { - options, - measurements, - Point, - Path, - points, - paths, - Snippet, - snippets, - complete, - sa, - paperless, - macro, - } = part.shorthand() - - let chestWidth = measurements.chest / 4 - let bibWidth = chestWidth * options.bibWidth - let bibLength = measurements.hpsToWaistBack * options.bibLength - let apronLength = - measurements.hpsToWaistBack * options.bibLength + - measurements.waistToKnee * (1 + options.lengthBonus) - /* - let apronWidth = - Math.max(measurements.hips, measurements.waist) * - (1 - options.backOpening) - */ - let apronWidth = measurements.waist * (1 - options.backOpening) - let strapWidth = (measurements.hpsToWaistBack * options.strapWidth) / 8 - let hemWidth = 3 * sa - let pocketSize = apronLength / 4 - - points.topLeft = new Point(0, 0) - points.topLeftHem = points.topLeft.shift(270, hemWidth) - points.bottomLeftHem = points.topLeftHem.shift(270, apronLength) - points.waistLeft = points.topLeftHem.shift(270, bibLength) - points.bottomLeft = points.bottomLeftHem.shift(270, hemWidth) - points.topRight = points.topLeft.shift(0, bibWidth / 2) - points.topRightHem = points.topLeftHem.shift(0, bibWidth / 2) - points.bottomRightHem = points.bottomLeftHem.shift(0, apronWidth / 2) - points.bottomRight = points.bottomLeft.shift(0, apronWidth / 2) - points.topRightBack = points.bottomRightHem.shift(90, apronLength - bibLength) - points.topRightBackCPfront = points.topRightBack.shift(180, (apronWidth - bibWidth) / 2 / 1.5) - points.topRightCPdown = points.topRightHem.shift( - 270, - (measurements.hpsToWaistBack * options.bibLength) / 4 - ) - - points.topCOF = points.topLeft.shift(270, apronLength / 5) - points.bottomCOF = points.bottomLeft.shift(90, apronLength / 5) - - points.pocketLeftTop = points.waistLeft.shift(270, hemWidth) - points.pocketRightTop = points.pocketLeftTop.shift(0, pocketSize) - points.pocketLeftBottom = points.pocketLeftTop.shift(270, pocketSize) - points.pocketRightBottom = points.pocketLeftBottom.shift(0, pocketSize) - - points.crossBoxTo1 = new Point(points.topRightHem.x - strapWidth, points.topRightHem.y + hemWidth) - points.crossBoxTo2 = new Point( - points.topRightBack.x - strapWidth, - points.topRightBack.y + hemWidth - ) - - paths.rightHem = new Path() - .move(points.bottomRight) - .line(points.topRightBack) - .curve(points.topRightBackCPfront, points.topRightCPdown, points.topRightHem) - .line(points.topRight) - .attr('class', 'various dashed') - .attr('data-text', 'narrow hem') - .attr('data-text-class', 'text-xs center') - - paths.pocket = new Path() - .move(points.pocketLeftBottom) - .line(points.pocketLeftTop) - .line(points.pocketRightTop) - .line(points.pocketRightBottom) - .line(points.pocketLeftBottom) - .attr('class', 'lining dotted stroke-sm') - .attr('data-text', 'pocket') - .attr('data-text-class', 'text-xs center') - - paths.right = paths.rightHem.offset(sa) - - paths.seam = new Path() - .move(points.bottomLeft) - .join(paths.right) - .line(points.topLeft) - .close() - .attr('class', 'fabric') - - paths.complete = paths.seam.clone().line(points.bottomLeft).close() - - paths.topHem = new Path() - .move(points.topLeftHem) - .line(points.topRightHem.shift(0, sa)) - .attr('class', 'various dashed') - .attr('data-text', 'hem') - .attr('data-text-class', 'text-xs center') - paths.bottomHem = new Path() - .move(points.bottomLeftHem) - .line(points.bottomRightHem.shift(0, sa)) - .attr('class', 'various dashed') - .attr('data-text', 'hem') - .attr('data-text-class', 'text-xs center') - - // Complete? - if (complete) { - points.logo = points.topRightBack.shiftFractionTowards(points.pocketRightBottom, 0.5) - snippets.logo = new Snippet('logo', points.logo) - points.title = points.logo.shift(-90, 100) - macro('title', { - nr: 1, - at: points.title, - title: 'Front', - }) - - points.scaleboxAnchor = points.pocketLeftBottom.shiftFractionTowards(points.bottomRight, 0.5) - macro('scalebox', { at: points.scaleboxAnchor }) - - macro('crossBox', { - from: points.topRightHem, - to: points.crossBoxTo1, - }) - macro('crossBox', { - from: points.topRightBack, - to: points.crossBoxTo2, - text: 'attachment', - }) - - if (sa) { - paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa') - } - - macro('cutonfold', { - from: points.topCOF, - to: points.bottomCOF, - }) - } - - // Paperless? - if (paperless) { - macro('hd', { - from: points.bottomLeft, - to: points.bottomRight, - y: points.bottomLeft.y + sa + 15, - }) - macro('hd', { - from: points.topLeft, - to: points.topRight, - y: points.topLeft.y - sa - 15, - }) - macro('vd', { - from: points.bottomLeft, - to: points.topLeft, - x: points.topLeft.x - sa - 15, - }) - macro('vd', { - from: points.bottomRight, - to: points.topRightBack, - x: points.topRightBack.x + sa + 15, - }) - macro('vd', { - from: points.topRightBack, - to: points.topRight, - x: points.topRightBack.x + sa + 15, - }) - macro('vd', { - from: points.topLeft, - to: points.topLeftHem, - x: points.topLeftHem.x + sa + 15, - }) - macro('vd', { - from: points.topLeftHem, - to: points.bottomLeftHem, - x: points.topLeftHem.x + sa + 15, - }) - macro('vd', { - from: points.bottomLeftHem, - to: points.bottomLeft, - x: points.bottomLeftHem.x + sa + 15, - }) - } - - return part -} diff --git a/designs/albert/src/front.mjs b/designs/albert/src/front.mjs new file mode 100644 index 00000000000..630640a96c1 --- /dev/null +++ b/designs/albert/src/front.mjs @@ -0,0 +1,202 @@ +export const bibLength = { pct: 75, min: 0, max: 90, menu: 'style' } +export const lengthBonus = { pct: 0, min: -20, max: 25, menu: 'style' } +export const backOpening = { pct: 10, min: 0, max: 25, menu: 'fit' } +export const bibWidth = { pct: 100, min: 50, max: 125, menu: 'style' } +export const strapWidth = { pct: 60, min: 20, max: 100, menu: 'style' } + +export const front = { + name: 'albert.front', + measurements: [ 'chest', 'hpsToWaistBack', 'waist', 'waistToKnee' ], + options: { + backOpening, + bibWidth, + strapWidth, + bibLength, + lengthBonus, + }, + draft: function (part) { + const { + options, + measurements, + Point, + Path, + points, + paths, + Snippet, + snippets, + complete, + sa, + paperless, + macro, + } = part.shorthand() + + let chestWidth = measurements.chest / 4 + let bibWidth = chestWidth * options.bibWidth + let bibLength = measurements.hpsToWaistBack * options.bibLength + let apronLength = + measurements.hpsToWaistBack * options.bibLength + + measurements.waistToKnee * (1 + options.lengthBonus) + /* + let apronWidth = + Math.max(measurements.hips, measurements.waist) * + (1 - options.backOpening) + */ + let apronWidth = measurements.waist * (1 - options.backOpening) + let strapWidth = (measurements.hpsToWaistBack * options.strapWidth) / 8 + let hemWidth = 3 * sa + let pocketSize = apronLength / 4 + + points.topLeft = new Point(0, 0) + points.topLeftHem = points.topLeft.shift(270, hemWidth) + points.bottomLeftHem = points.topLeftHem.shift(270, apronLength) + points.waistLeft = points.topLeftHem.shift(270, bibLength) + points.bottomLeft = points.bottomLeftHem.shift(270, hemWidth) + points.topRight = points.topLeft.shift(0, bibWidth / 2) + points.topRightHem = points.topLeftHem.shift(0, bibWidth / 2) + points.bottomRightHem = points.bottomLeftHem.shift(0, apronWidth / 2) + points.bottomRight = points.bottomLeft.shift(0, apronWidth / 2) + points.topRightBack = points.bottomRightHem.shift(90, apronLength - bibLength) + points.topRightBackCPfront = points.topRightBack.shift(180, (apronWidth - bibWidth) / 2 / 1.5) + points.topRightCPdown = points.topRightHem.shift( + 270, + (measurements.hpsToWaistBack * options.bibLength) / 4 + ) + + points.topCOF = points.topLeft.shift(270, apronLength / 5) + points.bottomCOF = points.bottomLeft.shift(90, apronLength / 5) + + points.pocketLeftTop = points.waistLeft.shift(270, hemWidth) + points.pocketRightTop = points.pocketLeftTop.shift(0, pocketSize) + points.pocketLeftBottom = points.pocketLeftTop.shift(270, pocketSize) + points.pocketRightBottom = points.pocketLeftBottom.shift(0, pocketSize) + + points.crossBoxTo1 = new Point(points.topRightHem.x - strapWidth, points.topRightHem.y + hemWidth) + points.crossBoxTo2 = new Point( + points.topRightBack.x - strapWidth, + points.topRightBack.y + hemWidth + ) + + paths.rightHem = new Path() + .move(points.bottomRight) + .line(points.topRightBack) + .curve(points.topRightBackCPfront, points.topRightCPdown, points.topRightHem) + .line(points.topRight) + .attr('class', 'various dashed') + .attr('data-text', 'narrow hem') + .attr('data-text-class', 'text-xs center') + + paths.pocket = new Path() + .move(points.pocketLeftBottom) + .line(points.pocketLeftTop) + .line(points.pocketRightTop) + .line(points.pocketRightBottom) + .line(points.pocketLeftBottom) + .attr('class', 'lining dotted stroke-sm') + .attr('data-text', 'pocket') + .attr('data-text-class', 'text-xs center') + + paths.right = paths.rightHem.offset(sa) + + paths.seam = new Path() + .move(points.bottomLeft) + .join(paths.right) + .line(points.topLeft) + .close() + .attr('class', 'fabric') + + paths.complete = paths.seam.clone().line(points.bottomLeft).close() + + paths.topHem = new Path() + .move(points.topLeftHem) + .line(points.topRightHem.shift(0, sa)) + .attr('class', 'various dashed') + .attr('data-text', 'hem') + .attr('data-text-class', 'text-xs center') + paths.bottomHem = new Path() + .move(points.bottomLeftHem) + .line(points.bottomRightHem.shift(0, sa)) + .attr('class', 'various dashed') + .attr('data-text', 'hem') + .attr('data-text-class', 'text-xs center') + + // Complete? + if (complete) { + points.logo = points.topRightBack.shiftFractionTowards(points.pocketRightBottom, 0.5) + snippets.logo = new Snippet('logo', points.logo) + points.title = points.logo.shift(-90, 100) + macro('title', { + nr: 1, + at: points.title, + title: 'Front', + }) + + points.scaleboxAnchor = points.pocketLeftBottom.shiftFractionTowards(points.bottomRight, 0.5) + macro('scalebox', { at: points.scaleboxAnchor }) + + macro('crossBox', { + from: points.topRightHem, + to: points.crossBoxTo1, + }) + macro('crossBox', { + from: points.topRightBack, + to: points.crossBoxTo2, + text: 'attachment', + }) + + if (sa) { + paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa') + } + + macro('cutonfold', { + from: points.topCOF, + to: points.bottomCOF, + }) + } + + // Paperless? + if (paperless) { + macro('hd', { + from: points.bottomLeft, + to: points.bottomRight, + y: points.bottomLeft.y + sa + 15, + }) + macro('hd', { + from: points.topLeft, + to: points.topRight, + y: points.topLeft.y - sa - 15, + }) + macro('vd', { + from: points.bottomLeft, + to: points.topLeft, + x: points.topLeft.x - sa - 15, + }) + macro('vd', { + from: points.bottomRight, + to: points.topRightBack, + x: points.topRightBack.x + sa + 15, + }) + macro('vd', { + from: points.topRightBack, + to: points.topRight, + x: points.topRightBack.x + sa + 15, + }) + macro('vd', { + from: points.topLeft, + to: points.topLeftHem, + x: points.topLeftHem.x + sa + 15, + }) + macro('vd', { + from: points.topLeftHem, + to: points.bottomLeftHem, + x: points.topLeftHem.x + sa + 15, + }) + macro('vd', { + from: points.bottomLeftHem, + to: points.bottomLeft, + x: points.bottomLeftHem.x + sa + 15, + }) + } + + return part + } +} diff --git a/designs/albert/src/index.js b/designs/albert/src/index.mjs similarity index 79% rename from designs/albert/src/index.js rename to designs/albert/src/index.mjs index a53fec5f6c6..67783fb1875 100644 --- a/designs/albert/src/index.js +++ b/designs/albert/src/index.mjs @@ -1,13 +1,18 @@ -import freesewing from '@freesewing/core' -import plugins from '@freesewing/plugin-bundle' -import config from '../config' -import draftFront from './front' -import draftStrap from './strap' -import draftPocket from './pocket' +// FreeSewing Design constructor +import { Design } from '@freesewing/core' +// FreeSewing Plugins +import { pluginBundle } from '@freesewing/plugin-bundle' +// Design parts +import { front } from './front.mjs' +import { pocket } from './pocket.mjs' +import { strap } from './strap.mjs' +// Get name & version from package.json +import { name, version } from '../package.json' +// crossbox macro const crossBox = { name: 'crossbox', - version: config.version, + version, macros: { crossBox: function (so) { let id = this.getId() @@ -62,16 +67,17 @@ const crossBox = { }, } -// Create new design -const Albert = new freesewing.Design(config, [plugins, crossBox]) -// Attach the draft methods to the prototype -Albert.prototype.draftFront = draftFront -Albert.prototype.draftStrap = draftStrap -Albert.prototype.draftPocket = draftPocket +// Setup our new design +const Albert = new Design({ + name, + version, + parts: [ front, pocket, strap ], + plugins: [ pluginBundle, crossBox ] +}) // Named exports -export { config, Albert } +export { front, pocket, strap, Albert } + + -// Default export -export default Albert diff --git a/designs/albert/src/pocket.js b/designs/albert/src/pocket.js deleted file mode 100644 index 71a3c849041..00000000000 --- a/designs/albert/src/pocket.js +++ /dev/null @@ -1,85 +0,0 @@ -export default function (part) { - let { - options, - measurements, - Point, - Path, - points, - paths, - Snippet, - snippets, - complete, - sa, - paperless, - macro, - } = part.shorthand() - - let apronLength = - measurements.hpsToWaistBack * options.bibLength + - measurements.waistToKnee * (1 + options.lengthBonus) - let pocketSize = apronLength / 4 - let hemWidth = 3 * sa - - points.topLeft = new Point(0, 0) - points.topRight = new Point(pocketSize, 0) - points.topLeftHem = points.topLeft.shift(270, hemWidth) - points.topRightHem = points.topRight.shift(270, hemWidth) - points.bottomLeft = points.topLeftHem.shift(270, pocketSize) - points.bottomRight = points.topRightHem.shift(270, pocketSize) - - points.topCOF = points.topLeft.shift(270, pocketSize / 5) - points.bottomCOF = points.bottomLeft.shift(90, pocketSize / 5) - - paths.seam = new Path() - .move(points.bottomLeft) - .line(points.bottomRight) - .line(points.topRight) - .line(points.topLeft) - .close() - .attr('class', 'fabric') - - paths.all = paths.seam.clone().line(points.bottomLeft).close().attr('class', 'fabric') - - paths.topHem = new Path() - .move(points.topLeftHem) - .line(points.topRightHem.shift(0, sa)) - .attr('class', 'various dashed') - .attr('data-text', 'hem') - .attr('data-text-class', 'text-xs center') - - macro('cutonfold', { - from: points.topCOF, - to: points.bottomCOF, - }) - - // Complete? - if (complete) { - points.logo = points.topLeft.shiftFractionTowards(points.bottomRight, 0.5) - snippets.logo = new Snippet('logo', points.logo) - points.title = points.logo.shift(-90, 45) - macro('title', { - nr: 3, - at: points.title, - title: 'Pocket', - }) - if (sa) { - paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa') - } - } - - // Paperless? - if (paperless) { - macro('hd', { - from: points.bottomLeft, - to: points.bottomRight, - y: points.bottomLeft.y + sa + 15, - }) - macro('vd', { - from: points.bottomLeft, - to: points.topLeft, - x: points.topLeft.x - sa - 15, - }) - } - - return part -} diff --git a/designs/albert/src/pocket.mjs b/designs/albert/src/pocket.mjs new file mode 100644 index 00000000000..9b95c0754a5 --- /dev/null +++ b/designs/albert/src/pocket.mjs @@ -0,0 +1,93 @@ +import { bibLength, lengthBonus } from './front.mjs' + +export const pocket = { + name: 'albert.pocket', + measurements: [ 'hpsToWaistBack', 'waistToKnee' ], + options: { bibLength, lengthBonus }, + draft: function (part) { + const { + options, + measurements, + Point, + Path, + points, + paths, + Snippet, + snippets, + complete, + sa, + paperless, + macro, + } = part.shorthand() + + let apronLength = + measurements.hpsToWaistBack * options.bibLength + + measurements.waistToKnee * (1 + options.lengthBonus) + let pocketSize = apronLength / 4 + let hemWidth = 3 * sa + + points.topLeft = new Point(0, 0) + points.topRight = new Point(pocketSize, 0) + points.topLeftHem = points.topLeft.shift(270, hemWidth) + points.topRightHem = points.topRight.shift(270, hemWidth) + points.bottomLeft = points.topLeftHem.shift(270, pocketSize) + points.bottomRight = points.topRightHem.shift(270, pocketSize) + + points.topCOF = points.topLeft.shift(270, pocketSize / 5) + points.bottomCOF = points.bottomLeft.shift(90, pocketSize / 5) + + paths.seam = new Path() + .move(points.bottomLeft) + .line(points.bottomRight) + .line(points.topRight) + .line(points.topLeft) + .close() + .attr('class', 'fabric') + + paths.all = paths.seam.clone().line(points.bottomLeft).close().attr('class', 'fabric') + + paths.topHem = new Path() + .move(points.topLeftHem) + .line(points.topRightHem.shift(0, sa)) + .attr('class', 'various dashed') + .attr('data-text', 'hem') + .attr('data-text-class', 'text-xs center') + + macro('cutonfold', { + from: points.topCOF, + to: points.bottomCOF, + }) + + // Complete? + if (complete) { + points.logo = points.topLeft.shiftFractionTowards(points.bottomRight, 0.5) + snippets.logo = new Snippet('logo', points.logo) + points.title = points.logo.shift(-90, 45) + macro('title', { + nr: 3, + at: points.title, + title: 'Pocket', + }) + if (sa) { + paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa') + } + } + + // Paperless? + if (paperless) { + macro('hd', { + from: points.bottomLeft, + to: points.bottomRight, + y: points.bottomLeft.y + sa + 15, + }) + macro('vd', { + from: points.bottomLeft, + to: points.topLeft, + x: points.topLeft.x - sa - 15, + }) + } + + return part + } +} + diff --git a/designs/albert/src/strap.js b/designs/albert/src/strap.js deleted file mode 100644 index c998edc130e..00000000000 --- a/designs/albert/src/strap.js +++ /dev/null @@ -1,131 +0,0 @@ -export default function (part) { - let { - options, - measurements, - Point, - Path, - points, - paths, - Snippet, - snippets, - complete, - sa, - paperless, - macro, - } = part.shorthand() - - let chestWidth = measurements.chest / 4 - let bibWidth = chestWidth * options.bibWidth - /* - let apronWidth = - Math.max(measurements.hips, measurements.waist) * - (1 - options.backOpening) - */ - let apronWidth = measurements.waist * (1 - options.backOpening) - let backOpening = apronWidth - Math.max(measurements.hips, measurements.waist) - let hemWidth = 3 * sa - - let hSpan = backOpening / 2 + bibWidth / 2 - let vSpan = - measurements.hpsToWaistBack + - measurements.hpsToWaistBack - - measurements.hpsToWaistBack * options.bibLength - - let strapWidth = (measurements.hpsToWaistBack * options.strapWidth) / 8 - let strapLength = - Math.sqrt(hSpan * hSpan + vSpan * vSpan) + measurements.chest * options.chestDepth - /* - console.log('chestWidth ' + chestWidth) - console.log('backOpening ' + backOpening) - console.log('hSpan ' + hSpan) - console.log('vSpan ' + vSpan) - console.log('strapLength ' + strapLength) - */ - points.topLeft = new Point(0, 0) - points.topLeftHem = points.topLeft.shift(270, hemWidth) - points.topMiddle = new Point(strapWidth, 0) - points.topMiddleHem = new Point(strapWidth, hemWidth) - points.topRight = new Point(strapWidth * 2, 0) - points.bottomLeftHem = new Point(0, strapLength + hemWidth) - points.bottomLeft = new Point(0, strapLength + hemWidth * 2) - points.bottomMiddleHem = new Point(strapWidth, strapLength + hemWidth) - points.bottomMiddle = new Point(strapWidth, strapLength + hemWidth * 2) - points.bottomRight = new Point(strapWidth * 2, strapLength + hemWidth * 2) - - paths.seam = new Path() - .move(points.topLeft) - .line(points.bottomLeft) - .line(points.bottomRight) - .line(points.topRight) - .line(points.topLeft) - .close() - .attr('class', 'fabric') - - paths.topHem = new Path() - .move(points.topLeftHem) - .line(points.topMiddleHem) - .attr('class', 'various dashed') - .attr('data-text', 'attach') - .attr('data-text-class', 'text-xs center') - paths.bottomHem = new Path() - .move(points.bottomLeftHem) - .line(points.bottomMiddleHem) - .attr('class', 'various dashed') - .attr('data-text', 'attach') - .attr('data-text-class', 'text-xs center') - - paths.fold = new Path() - .move(points.topMiddle) - .line(points.bottomMiddle) - .attr('class', 'various dashed') - .attr('data-text', 'fold') - .attr('data-text-class', 'text-xs center') - - // Complete? - if (complete) { - points.logo = points.topLeft.shiftFractionTowards(points.bottomRight, 0.5) - snippets.logo = new Snippet('logo', points.logo).attr('data-scale', 0.5) - points.title = points.logo.shift(-90, 50) - macro('title', { - nr: 2, - at: points.title, - title: 'Strap', - }) - macro('crossBox', { from: points.topLeft, to: points.topMiddleHem }) - macro('crossBox', { from: points.bottomLeftHem, to: points.bottomMiddle }) - if (sa) { - paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa') - } - } - - // Paperless? - if (paperless) { - macro('hd', { - from: points.bottomLeft, - to: points.bottomRight, - y: points.bottomLeft.y + sa + 15, - }) - macro('vd', { - from: points.bottomLeft, - to: points.topLeft, - x: points.topLeft.x - sa - 15, - }) - macro('vd', { - from: points.topMiddle, - to: points.topMiddleHem, - x: points.topMiddleHem.x + sa + 15, - }) - macro('vd', { - from: points.topMiddleHem, - to: points.bottomMiddleHem, - x: points.topMiddleHem.x + sa + 15, - }) - macro('vd', { - from: points.bottomMiddleHem, - to: points.bottomMiddle, - x: points.bottomMiddleHem.x + sa + 15, - }) - } - - return part -} diff --git a/designs/albert/src/strap.mjs b/designs/albert/src/strap.mjs new file mode 100644 index 00000000000..fecca062713 --- /dev/null +++ b/designs/albert/src/strap.mjs @@ -0,0 +1,144 @@ +import { backOpening, bibWidth, bibLength, strapWidth } from './front.mjs' + +export const strap = { + name: 'albert.strap', + measurements: [ 'chest', 'waist', 'hips', 'hpsToWaistBack' ], + options: { + backOpening, + bibWidth, + bibLength, + strapWidth, + chestDepth: { pct: 22, min: 15, max: 90, menu: 'fit' }, + }, + draft: function (part) { + const { + options, + measurements, + Point, + Path, + points, + paths, + Snippet, + snippets, + complete, + sa, + paperless, + macro, + } = part.shorthand() + + let chestWidth = measurements.chest / 4 + let bibWidth = chestWidth * options.bibWidth + /* + let apronWidth = + Math.max(measurements.hips, measurements.waist) * + (1 - options.backOpening) + */ + let apronWidth = measurements.waist * (1 - options.backOpening) + let backOpening = apronWidth - Math.max(measurements.hips, measurements.waist) + let hemWidth = 3 * sa + + let hSpan = backOpening / 2 + bibWidth / 2 + let vSpan = + measurements.hpsToWaistBack + + measurements.hpsToWaistBack - + measurements.hpsToWaistBack * options.bibLength + + let strapWidth = (measurements.hpsToWaistBack * options.strapWidth) / 8 + let strapLength = + Math.sqrt(hSpan * hSpan + vSpan * vSpan) + measurements.chest * options.chestDepth + /* + console.log('chestWidth ' + chestWidth) + console.log('backOpening ' + backOpening) + console.log('hSpan ' + hSpan) + console.log('vSpan ' + vSpan) + console.log('strapLength ' + strapLength) + */ + points.topLeft = new Point(0, 0) + points.topLeftHem = points.topLeft.shift(270, hemWidth) + points.topMiddle = new Point(strapWidth, 0) + points.topMiddleHem = new Point(strapWidth, hemWidth) + points.topRight = new Point(strapWidth * 2, 0) + points.bottomLeftHem = new Point(0, strapLength + hemWidth) + points.bottomLeft = new Point(0, strapLength + hemWidth * 2) + points.bottomMiddleHem = new Point(strapWidth, strapLength + hemWidth) + points.bottomMiddle = new Point(strapWidth, strapLength + hemWidth * 2) + points.bottomRight = new Point(strapWidth * 2, strapLength + hemWidth * 2) + + paths.seam = new Path() + .move(points.topLeft) + .line(points.bottomLeft) + .line(points.bottomRight) + .line(points.topRight) + .line(points.topLeft) + .close() + .attr('class', 'fabric') + + paths.topHem = new Path() + .move(points.topLeftHem) + .line(points.topMiddleHem) + .attr('class', 'various dashed') + .attr('data-text', 'attach') + .attr('data-text-class', 'text-xs center') + paths.bottomHem = new Path() + .move(points.bottomLeftHem) + .line(points.bottomMiddleHem) + .attr('class', 'various dashed') + .attr('data-text', 'attach') + .attr('data-text-class', 'text-xs center') + + paths.fold = new Path() + .move(points.topMiddle) + .line(points.bottomMiddle) + .attr('class', 'various dashed') + .attr('data-text', 'fold') + .attr('data-text-class', 'text-xs center') + + // Complete? + if (complete) { + points.logo = points.topLeft.shiftFractionTowards(points.bottomRight, 0.5) + snippets.logo = new Snippet('logo', points.logo).attr('data-scale', 0.5) + points.title = points.logo.shift(-90, 50) + macro('title', { + nr: 2, + at: points.title, + title: 'Strap', + }) + macro('crossBox', { from: points.topLeft, to: points.topMiddleHem }) + macro('crossBox', { from: points.bottomLeftHem, to: points.bottomMiddle }) + if (sa) { + paths.sa = paths.seam.offset(sa).attr('class', 'fabric sa') + } + } + + // Paperless? + if (paperless) { + macro('hd', { + from: points.bottomLeft, + to: points.bottomRight, + y: points.bottomLeft.y + sa + 15, + }) + macro('vd', { + from: points.bottomLeft, + to: points.topLeft, + x: points.topLeft.x - sa - 15, + }) + macro('vd', { + from: points.topMiddle, + to: points.topMiddleHem, + x: points.topMiddleHem.x + sa + 15, + }) + macro('vd', { + from: points.topMiddleHem, + to: points.bottomMiddleHem, + x: points.topMiddleHem.x + sa + 15, + }) + macro('vd', { + from: points.bottomMiddleHem, + to: points.bottomMiddle, + x: points.bottomMiddleHem.x + sa + 15, + }) + } + + return part + } +} diff --git a/designs/albert/tests/shared.test.mjs b/designs/albert/tests/shared.test.mjs index a06c42ac812..dce00c36519 100644 --- a/designs/albert/tests/shared.test.mjs +++ b/designs/albert/tests/shared.test.mjs @@ -1,17 +1,16 @@ -// This file is auto-generated. -// Changes you make will be overwritten. -import Pattern from './dist/index.mjs' +// This file is auto-generated | Any changes you make will be overwritten. +import { Albert } from './dist/index.mjs' // Shared tests -import { testPatternConfig } from '../../../tests/patterns/config.mjs' -import { testPatternDrafting } from '../../../tests/patterns/drafting.mjs' -import { testPatternSampling } from '../../../tests/patterns/sampling.mjs' +import { testPatternConfig } from '../../../tests/designs/config.mjs' +import { testPatternDrafting } from '../../../tests/designs/drafting.mjs' +import { testPatternSampling } from '../../../tests/designs/sampling.mjs' // Test config -testPatternConfig("albert", new Pattern()) +testPatternConfig(Albert) -// Test drafting -testPatternDrafting("albert", Pattern) +// Test drafting - Change the second parameter to `true` to log errors +testPatternDrafting(Albert, false) -// Test sampling -testPatternSampling( "albert", Pattern) +// Test sampling - Change the second parameter to `true` to log errors +testPatternSampling(Albert, false)