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

55 lines
2.4 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
2019-08-03 15:03:33 +02:00
if (store.get('init') !== true) {
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
/* Store rise, backRise and legBonus as absolute values */
2019-08-03 15:03:33 +02:00
store.set('rise', measurements.hipsToUpperLeg * options.rise * store.get('yScale'))
store.set('backRise', measurements.hipsToUpperLeg * options.backRise * store.get('yScale'))
store.set('sideRise', store.get('backRise') * 0.75)
store.set('frontRise', store.get('backRise') * 0.25)
store.set('legBonus', measurements.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*/
2019-08-03 15:03:33 +02:00
store.set('hips', measurements.hipsCircumference * store.get('xScale'))
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*/
2019-08-03 15:03:33 +02:00
store.set('leg', measurements.upperLegCircumference * store.get('xScaleLegs'))
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 */
2019-08-03 15:03:33 +02:00
store.set('gusset', measurements.hipsCircumference * options.gussetRatio)
store.set('gussetInsetRatio', options.gussetInsetRatio)
2018-09-06 18:34:42 +02:00
/* Length helper */
2019-08-03 15:03:33 +02:00
store.set('length', measurements.hipsToUpperLeg * store.get('yScale'))
store.set('riseLength', measurements.hipsToUpperLeg + store.get('rise'))
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
}