1
0
Fork 0
freesewing/sites/dev/docs/reference/api/utils/splitcurve/readme.mdx
Joost De Cock ab3204f9f1 chore: Port FreeSewing.dev to docusaurus
The replaces the NextJS site powering FreeSewing.dev with a Docusaurus
setup. It's part of my efforts to simplify FreeSewing's setup so we can
focus on our core value proposition.
2024-09-28 13:13:48 +02:00

80 lines
1.4 KiB
Text

---
title: utils.splitCurve()
---
The `utils.splitCurve()` function splits a curve defined by 4 points `start`,
`cp1`, `cp2`, and `end` on the point `split` and returns an array holding both
halves.
## Signature
```js
array utils.splitCurve(
Point start,
Point cp1,
Point cp2,
Point end,
Point check,
)
```
## Example
<Example caption="A Utils.splitCurve() example">
```js
({ Point, points, Path, paths, utils, part }) => {
points.start = new Point(10, 10)
points.cp1 = new Point(100, 80)
points.cp2 = new Point(100, 0)
points.end = new Point(10, 50)
paths.example = new Path()
.move(points.start)
.curve(points.cp1, points.cp2, points.end)
.addClass('dotted stroke-xs')
points.split = paths.example.shiftFractionAlong(0.4)
const halves = utils.splitCurve(
points.start,
points.cp1,
points.cp2,
points.end,
points.split
)
for (let i=0; i<2; i++) {
const { start, cp1, cp2, end } = halves[i]
paths[`segment${i}`] = new Path()
.move(start)
.curve(cp1, cp2, end)
.addClass('stroke-xl')
.attr('style', 'stroke-opacity: 0.5;')
}
paths.segment0.addClass('note')
paths.segment1.addClass('lining')
return part
}
```
</Example>
## Notes
The returned object has this signature:
```js
[
{
start: Point,
cp1: Point,
cp2: Point,
end: Point,
},
{
start: Point,
cp1: Point,
cp2: Point,
end: Point,
},
]