1
0
Fork 0
freesewing/packages/bruce/src/init.js

58 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-12-19 12:14:48 +01:00
export default function init(part) {
2019-08-03 15:03:33 +02:00
let { store, options, measurements, utils } = part.shorthand()
2018-09-04 16:51:39 +02:00
// Don't run this every time, except when sampling
store.setIfUnset('init', false)
if (store.get('init') !== true || part.context.settings.sample) {
2018-09-06 18:34:42 +02:00
/* Set vertical scale to 1 (no stretch) */
2019-08-03 15:03:33 +02:00
store.set('yScale', 1)
2018-09-06 18:34:42 +02:00
const hipsToUpperLeg = measurements.waistToUpperLeg - measurements.waistToHips
2018-09-06 18:34:42 +02:00
/* Store rise, backRise and legBonus as absolute values */
store.set('rise', hipsToUpperLeg * options.rise * store.get('yScale'))
store.set('backRise', hipsToUpperLeg * options.backRise * store.get('yScale'))
2019-08-03 15:03:33 +02:00
store.set('sideRise', store.get('backRise') * 0.75)
store.set('frontRise', store.get('backRise') * 0.25)
store.set('legBonus', hipsToUpperLeg * options.legBonus * store.get('yScale'))
2018-09-06 18:34:42 +02:00
/* Set horizontal scale based on stretch */
2019-08-03 15:03:33 +02:00
store.set('xScale', utils.stretchToScale(options.stretch))
store.set('xScaleLegs', utils.stretchToScale(options.legStretch))
2018-09-06 18:34:42 +02:00
/* Ratio of parts at the hips*/
store.set('hips', measurements.hips * store.get('xScale'))
2019-08-03 15:03:33 +02:00
store.set('hipsFront', store.get('hips') * options.hipRatioFront)
let hipRatioSide = (1 - (options.hipRatioFront + options.hipRatioBack)) / 2
store.set('hipsSide', store.get('hips') * hipRatioSide)
store.set('hipsBack', store.get('hips') * options.hipRatioBack)
2018-09-06 18:34:42 +02:00
/* Ratio of parts at the legs*/
store.set('leg', measurements.upperLeg * store.get('xScaleLegs'))
2019-08-03 15:03:33 +02:00
store.set('legInset', store.get('leg') * options.legRatioInset)
let legRatioSide = 1 - options.legRatioInset - options.legRatioBack
store.set('legSide', store.get('leg') * legRatioSide)
store.set('legBack', store.get('leg') * options.legRatioBack)
2018-09-06 18:34:42 +02:00
/* Gusset */
store.set('gusset', measurements.hips * options.gussetRatio)
2019-08-03 15:03:33 +02:00
store.set('gussetInsetRatio', options.gussetInsetRatio)
2018-09-06 18:34:42 +02:00
/* Length helper */
store.set('length', hipsToUpperLeg * store.get('yScale'))
store.set('riseLength', hipsToUpperLeg + store.get('rise'))
2019-08-03 15:03:33 +02:00
store.set('fullLength', store.get('riseLength') + store.get('legBonus') * store.get('yScale'))
2018-09-06 18:34:42 +02:00
/* Height ratio front/inset */
2019-08-03 15:03:33 +02:00
store.set(
'heightInset',
store.get('riseLength') * options.heightRatioInset +
store.get('legBonus') * store.get('yScale')
)
store.set('heightFront', store.get('riseLength') * (1 - options.heightRatioInset))
2018-09-06 18:34:42 +02:00
/* Absolute amount to raise the back */
2019-08-03 15:03:33 +02:00
store.set('init', true)
2018-09-06 18:34:42 +02:00
}
2018-09-04 16:51:39 +02:00
}