1
0
Fork 0

chore(bob): Better comment style

This commit is contained in:
joostdecock 2023-09-28 15:23:28 +02:00
parent cc642a4024
commit 8bb84beeaa

View file

@ -24,12 +24,16 @@ export const bib = {
units, units,
part, part,
}) => { }) => {
// Head size /*
* Head size
*/
const head = (`head` in measurements ? measurements.head : 360) * options.headSize const head = (`head` in measurements ? measurements.head : 360) * options.headSize
// Construct the neck opening /*
* Construct the neck opening
*/
const target = (head * options.neckRatio) / 4
let tweak = 1 let tweak = 1
let target = (head * options.neckRatio) / 4
let delta let delta
do { do {
points.right = new Point((tweak * head) / 10, 0) points.right = new Point((tweak * head) / 10, 0)
@ -58,7 +62,9 @@ export const bib = {
points.topCp1 = points.bottomCp2.flipY() points.topCp1 = points.bottomCp2.flipY()
points.topCp2 = points.bottomCp1.flipY() points.topCp2 = points.bottomCp1.flipY()
// Construct the outline /*
* Construct the outline
*/
let width = head * options.widthRatio let width = head * options.widthRatio
let length = head * options.lengthRatio let length = head * options.lengthRatio
@ -76,14 +82,18 @@ export const bib = {
points.edgeTopLeftCp = points.edgeTop.shiftFractionTowards(points.topLeft, 0.5) points.edgeTopLeftCp = points.edgeTop.shiftFractionTowards(points.topLeft, 0.5)
points.edgeTopRightCp = points.edgeTopLeftCp.flipX() points.edgeTopRightCp = points.edgeTopLeftCp.flipX()
// Round the end of the straps /*
* Round the end of the straps
*/
let strap = points.edgeTop.dy(points.top) let strap = points.edgeTop.dy(points.top)
points.tipRight = points.edgeTop.translate(strap / 2, strap / 2) points.tipRight = points.edgeTop.translate(strap / 2, strap / 2)
points.tipRightTop = new Point(points.tipRight.x, points.edgeTop.y) points.tipRightTop = new Point(points.tipRight.x, points.edgeTop.y)
points.tipRightBottom = new Point(points.tipRight.x, points.top.y) points.tipRightBottom = new Point(points.tipRight.x, points.top.y)
// Macros will return the auto-generated IDs /*
* Macros will return the auto-generated IDs
*/
const ids1 = { const ids1 = {
tipRightTop: macro('round', { tipRightTop: macro('round', {
id: 'tipRightTop', id: 'tipRightTop',
@ -98,13 +108,19 @@ export const bib = {
via: points.tipRightBottom, via: points.tipRightBottom,
}), }),
} }
// Create points from them with easy names
/*
* Create points from them with easy names
*/
for (const side in ids1) { for (const side in ids1) {
for (const id of ['start', 'cp1', 'cp2', 'end']) { for (const id of ['start', 'cp1', 'cp2', 'end']) {
points[`${side}${utils.capitalize(id)}`] = points[ids1[side].points[id]].copy() points[`${side}${utils.capitalize(id)}`] = points[ids1[side].points[id]].copy()
} }
} }
// Rotate straps so they don't overlap
/*
* Rotate straps so they don't overlap
*/
let rotateThese = [ let rotateThese = [
'edgeTopLeftCp', 'edgeTopLeftCp',
'edgeTop', 'edgeTop',
@ -127,10 +143,14 @@ export const bib = {
for (let p of rotateThese) points[p] = points[p].rotate(1, points.edgeLeft) for (let p of rotateThese) points[p] = points[p].rotate(1, points.edgeLeft)
} }
// Add points to anchor snaps on /*
* Add points to anchor snaps on
*/
points.snapLeft = points.top.shiftFractionTowards(points.edgeTop, 0.5) points.snapLeft = points.top.shiftFractionTowards(points.edgeTop, 0.5)
// Mirror points to the other side /*
* Mirror points to the other side
*/
points.edgeTopRightCp = points.edgeTopLeftCp.flipX() points.edgeTopRightCp = points.edgeTopLeftCp.flipX()
points.topCp1 = points.topCp2.flipX() points.topCp1 = points.topCp2.flipX()
points.tipLeftTopStart = points.tipRightTopStart.flipX() points.tipLeftTopStart = points.tipRightTopStart.flipX()
@ -143,9 +163,12 @@ export const bib = {
points.tipLeftBottomEnd = points.tipRightBottomEnd.flipX() points.tipLeftBottomEnd = points.tipRightBottomEnd.flipX()
points.snapRight = points.snapLeft.flipX() points.snapRight = points.snapLeft.flipX()
// Round the bottom of the bib /*
// Radius is fixed, but you could use an option for it) * Round the bottom of the bib
// Macros will return the auto-generated IDs * Radius is fixed, but you could use an option for it)
*
* Macros will return the auto-generated IDs
*/
const ids2 = { const ids2 = {
bottomLeft: macro('round', { bottomLeft: macro('round', {
id: 'bottomLeft', id: 'bottomLeft',
@ -162,13 +185,18 @@ export const bib = {
radius: points.bottomRight.x / 4, radius: points.bottomRight.x / 4,
}), }),
} }
// Create points from them with easy names /*
* Create points from them with easy names
*/
for (const side in ids2) { for (const side in ids2) {
for (const id of ['start', 'cp1', 'cp2', 'end']) { for (const id of ['start', 'cp1', 'cp2', 'end']) {
points[`${side}${utils.capitalize(id)}`] = points[ids2[side].points[id]].copy() points[`${side}${utils.capitalize(id)}`] = points[ids2[side].points[id]].copy()
} }
} }
// Construct the path
/*
* Construct the path
*/
paths.seam = new Path() paths.seam = new Path()
.move(points.edgeLeft) .move(points.edgeLeft)
.line(points.bottomLeftStart) .line(points.bottomLeftStart)
@ -190,10 +218,14 @@ export const bib = {
.attr('class', 'fabric') .attr('class', 'fabric')
/* /*
* Annotations *
* Annotations
*
*/ */
// Let the user know about the bias tape and fabric requirements /*
* Let the user know about the bias tape and fabric requirements
*/
store.flag.note({ store.flag.note({
msg: 'bob:biasTapeLength', msg: 'bob:biasTapeLength',
replace: { replace: {
@ -201,14 +233,20 @@ export const bib = {
}, },
}) })
// Cut list /*
* Cut list
*/
store.cutlist.addCut({ cut: 1, from: 'fabric' }) store.cutlist.addCut({ cut: 1, from: 'fabric' })
// Add the snaps /*
* Add the snaps
*/
snippets.snapStud = new Snippet('snap-stud', points.snapLeft) snippets.snapStud = new Snippet('snap-stud', points.snapLeft)
snippets.snapSocket = new Snippet('snap-socket', points.snapRight).attr('opacity', 0.5) snippets.snapSocket = new Snippet('snap-socket', points.snapRight).attr('opacity', 0.5)
// Add the bias tape /*
* Add the bias tape
*/
if (complete) if (complete)
paths.bias = paths.seam paths.bias = paths.seam
.offset(-5) .offset(-5)
@ -216,7 +254,9 @@ export const bib = {
.attr('data-text', 'bob:finishWithBiasTape') .attr('data-text', 'bob:finishWithBiasTape')
.attr('data-text-class', 'center fill-note') .attr('data-text-class', 'center fill-note')
// Add the title /*
* Add the title
*/
points.title = points.bottom.shift(-90, 45) points.title = points.bottom.shift(-90, 45)
macro('title', { macro('title', {
at: points.title, at: points.title,
@ -226,15 +266,21 @@ export const bib = {
scale: 0.8, scale: 0.8,
}) })
// Add the scalebox /*
* Add the scalebox
*/
points.scalebox = points.title.shift(-90, 65) points.scalebox = points.title.shift(-90, 65)
macro('scalebox', { at: points.scalebox }) macro('scalebox', { at: points.scalebox })
// Add the logo /*
* Add the logo
*/
points.logo = new Point(0, 0) points.logo = new Point(0, 0)
snippets.logo = new Snippet('logo', points.logo) snippets.logo = new Snippet('logo', points.logo)
// Add dimensions /*
* Add dimensions
*/
macro('hd', { macro('hd', {
id: 'wFull', id: 'wFull',
from: points.bottomLeftStart, from: points.bottomLeftStart,