1
0
Fork 0

chore(markdown): Updated utils docs for v3

This commit is contained in:
Joost De Cock 2022-10-01 22:20:43 +02:00
parent acf1b72c4c
commit bc3b0cd770
23 changed files with 782 additions and 622 deletions

View file

@ -1,7 +1,13 @@
---
title: pointOnBeam()
title: utils.pointOnBeam()
---
The `utils.pointOnBeam()` function returns `true` if the point `check` lies on
the endless line that goes through `point1` and `point2`.
## Signature
```js
bool utils.pointOnBeam(
Point point1,
@ -11,73 +17,64 @@ bool utils.pointOnBeam(
)
```
Returns `true` if the point `check` lies on the endless line that goes through `point1` and `point2`.
The fourth parameter controls the precision. Lower numbers make the check less precise.
<Note>
## Example
###### Tweak precision only when needed
<Example caption="A Utils.pointOnBeam() example">
```js
({ Point, points, Path, paths, Snippet, snippets, getId, utils, part }) => {
Typically, you don't need to worry about precision. But occasionally, you may get
unexpected results because of floating point errors, rounding errors, or
points.from1 = new Point(10, 10)
points.to1 = new Point(90, 60)
points.from2 = new Point(10, 30)
points.to2 = new Point(90, 80)
points.b1 = new Point(170, 110)
points.b2 = new Point(170, 130)
const scatter = []
for (let i = 1; i < 36; i++) {
for (let j = 1; j < 27; j++) {
scatter.push(new Point(i * 10, j * 10))
}
}
let snippet
for (let point of scatter) {
if (utils.pointOnBeam(points.from1, points.to1, point)) snippet = "notch"
else snippet = "bnotch"
snippets[getId()] = new Snippet(snippet, point)
if (utils.pointOnBeam(points.from2, points.to2, point, 0.01)) {
snippet = "notch"
} else snippet = "bnotch"
snippets[getId()] = new Snippet(snippet, point)
}
paths.line1 = new Path()
.move(points.from1)
.line(points.to1)
.addClass("fabric stroke-lg")
paths.lne1 = new Path()
.move(points.to1)
.line(points.b1)
.addClass("fabric dashed")
paths.line2 = new Path()
.move(points.from2)
.line(points.to2)
.addClass("fabric stroke-lg")
paths.lne2 = new Path()
.move(points.to2)
.line(points.b2)
.addClass("fabric dashed")
return part
}
```
</Example>
## Notes
Typically, you don't need to worry about precision. But occasionally, you may
get unexpected results because of floating point errors, rounding errors, or
cubic bezier juggling.
When that happens, you can lower the precision so you get what you expect.
</Note>
<Example part="utils_pointonbeam">
A Utils.pointOnBeam() example
</Example>
```js
let {
Point,
points,
Path,
paths,
Snippet,
snippets,
utils
} = part.shorthand();
points.from1 = new Point(10, 10);
points.to1 = new Point(90, 60);
points.from2 = new Point(10, 30);
points.to2 = new Point(90, 80);
points.b1 = new Point(170, 110);
points.b2 = new Point(170, 130);
let scatter = [];
for (let i = 1; i < 36; i++) {
for (let j = 1; j < 27; j++) {
scatter.push(new Point(i * 10, j * 10));
}
}
let snippet;
for (let point of scatter) {
if (utils.pointOnBeam(points.from1, points.to1, point)) snippet = "notch";
else snippet = "bnotch";
snippets[part.getId()] = new Snippet(snippet, point);
if (utils.pointOnBeam(points.from2, points.to2, point, 0.01)) {
snippet = "notch";
} else snippet = "bnotch";
snippets[part.getId()] = new Snippet(snippet, point);
}
paths.line1 = new Path()
.move(points.from1)
.line(points.to1)
.attr("class", "fabric stroke-lg");
paths.lne1 = new Path()
.move(points.to1)
.line(points.b1)
.attr("class", "fabric dashed");
paths.line2 = new Path()
.move(points.from2)
.line(points.to2)
.attr("class", "fabric stroke-lg");
paths.lne2 = new Path()
.move(points.to2)
.line(points.b2)
.attr("class", "fabric dashed");
```