chore(markdown): Updated utils docs for v3
This commit is contained in:
parent
acf1b72c4c
commit
bc3b0cd770
23 changed files with 782 additions and 622 deletions
|
@ -1,7 +1,12 @@
|
|||
---
|
||||
title: curveIntersectsX()
|
||||
title: utils.curveIntersectsX()
|
||||
---
|
||||
|
||||
The `utils.curveIntersectsX()` function finds the point(s) where a curve
|
||||
intersects a given X-value.
|
||||
|
||||
## Signature
|
||||
|
||||
```js
|
||||
array | Point | false utils.curveIntersectsX(
|
||||
Point start,
|
||||
|
@ -11,61 +16,60 @@ array | Point | false utils.curveIntersectsX(
|
|||
float x)
|
||||
```
|
||||
|
||||
Finds the point(s) where a curve intersects a given X-value.
|
||||
|
||||
This is a low-level variant
|
||||
of [`Path.intersectsX()`](/reference/api/path/intersectsx).
|
||||
Instead of a path, you describe a single curve by passing the four
|
||||
points that describes it.
|
||||
|
||||
This returns `false` if no intersections are found,
|
||||
a [Point](/reference/api/point) object if
|
||||
a single intersection is found, and an array
|
||||
of [Point](/reference/api/point) objects if
|
||||
multiple intersections are found.
|
||||
|
||||
<Example part="utils_curveintersectsx">A Utils.curveIntersectX() example</Example>
|
||||
## Example
|
||||
|
||||
<Example caption="A Utils.curveIntersectX() example">
|
||||
```js
|
||||
let {
|
||||
Point,
|
||||
points,
|
||||
Path,
|
||||
paths,
|
||||
utils,
|
||||
snippets,
|
||||
Snippet
|
||||
} = part.shorthand();
|
||||
({ Point, points, Path, paths, Snippet, snippets, utils, part }) => {
|
||||
|
||||
points.start = new Point(10, 15);
|
||||
points.cp1 = new Point(80, 10);
|
||||
points.cp2 = new Point(-50, 80);
|
||||
points.end = new Point(110, 70);
|
||||
points.start = new Point(10, 15)
|
||||
points.cp1 = new Point(80, 10)
|
||||
points.cp2 = new Point(-50, 80)
|
||||
points.end = new Point(110, 70)
|
||||
|
||||
paths.curve = new Path()
|
||||
.move(points.start)
|
||||
.curve(points.cp1, points.cp2, points.end)
|
||||
|
||||
for (let x of [30, 40]) {
|
||||
points["from" + x] = new Point(x, 10)
|
||||
points["to" + x] = new Point(x, 80)
|
||||
paths["line" + x] = new Path()
|
||||
.move(points["from" + x])
|
||||
.line(points["to" + x])
|
||||
.addClass("lining dashed")
|
||||
}
|
||||
|
||||
snippets.i40 = new Snippet(
|
||||
"notch",
|
||||
utils.curveIntersectsX(points.start, points.cp1, points.cp2, points.end, 40)
|
||||
)
|
||||
|
||||
for (let p of utils.curveIntersectsX(
|
||||
points.start,
|
||||
points.cp1,
|
||||
points.cp2,
|
||||
points.end,
|
||||
30
|
||||
))
|
||||
snippets[p.y] = new Snippet("notch", p)
|
||||
|
||||
paths.curve = new Path()
|
||||
.move(points.start)
|
||||
.curve(points.cp1, points.cp2, points.end);
|
||||
|
||||
for (let x of [30, 40]) {
|
||||
points["from" + x] = new Point(x, 10);
|
||||
points["to" + x] = new Point(x, 80);
|
||||
paths["line" + x] = new Path()
|
||||
.move(points["from" + x])
|
||||
.line(points["to" + x])
|
||||
.attr("class", "lining dashed");
|
||||
return part
|
||||
}
|
||||
|
||||
snippets.i40 = new Snippet(
|
||||
"notch",
|
||||
utils.curveIntersectsX(points.start, points.cp1, points.cp2, points.end, 40)
|
||||
);
|
||||
|
||||
for (let p of utils.curveIntersectsX(
|
||||
points.start,
|
||||
points.cp1,
|
||||
points.cp2,
|
||||
points.end,
|
||||
30
|
||||
))
|
||||
snippets[p.y] = new Snippet("notch", p);
|
||||
```
|
||||
</Example>
|
||||
|
||||
|
||||
## Notes
|
||||
|
||||
This is a low-level (and faster) variant
|
||||
of [`Path.intersectsX()`](/reference/api/path/intersectsx).
|
||||
Instead of a path, you describe a single curve by passing the four
|
||||
points that describes it.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue