2021-10-17 18:26:00 +02:00
|
|
|
---
|
2022-10-01 22:20:43 +02:00
|
|
|
title: utils.stretchToScale()
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-10-01 22:20:43 +02:00
|
|
|
The `utils.stretchToScale()` function calculates the scale for a given amount of
|
|
|
|
stretch.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
|
|
|
float utils.stretchToScale(float stretch)
|
|
|
|
```
|
|
|
|
|
2022-10-01 22:20:43 +02:00
|
|
|
## Notes
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
The way people measure stretch intuitively is different from the way we handle stretch in code.
|
|
|
|
|
2022-12-29 19:36:27 -08:00
|
|
|
When people say fabric has _25% stretch_ they mean that 10 cm of fabric can
|
|
|
|
stretch to 12.5 cm.
|
|
|
|
In code that means we would need to scale non-stretch lengths by 80%
|
|
|
|
to get the correct lengths to use in patterns with 25% stretch fabric.
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-12-29 19:36:27 -08:00
|
|
|
Pattern designers need a way to calculate the scaling factor to use for
|
|
|
|
their pattern part lengths, given a fabric stretch percentage.
|
2022-10-01 22:20:43 +02:00
|
|
|
This function does that by returning:
|
2021-08-25 16:09:31 +02:00
|
|
|
|
|
|
|
```js
|
2022-10-01 23:13:39 +02:00
|
|
|
1 / (1 + parseFloat(stretch))
|
2021-08-25 16:09:31 +02:00
|
|
|
```
|