2021-10-17 18:26:00 +02:00
|
|
|
---
|
2022-09-27 18:24:35 +02:00
|
|
|
title: Path.length()
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-27 18:24:35 +02:00
|
|
|
The `Path.length()` method returns the length of the path.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
2024-02-10 15:40:41 +01:00
|
|
|
float path.length(bool withMoves = false)
|
2021-08-25 16:09:31 +02:00
|
|
|
```
|
|
|
|
|
2022-09-27 18:24:35 +02:00
|
|
|
## Example
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-27 18:24:35 +02:00
|
|
|
<Example caption="Example of the Path.length() method">
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
2024-02-10 15:40:41 +01:00
|
|
|
({ Point, points, Path, paths, units, part }) => {
|
2022-09-27 18:24:35 +02:00
|
|
|
|
2024-02-10 15:40:41 +01:00
|
|
|
points.A1 = new Point(0, 0)
|
|
|
|
points.A2 = new Point(160, 0)
|
|
|
|
points.B1 = new Point(0, 10)
|
|
|
|
points.B2 = new Point(160, 10)
|
|
|
|
points.C1 = new Point(0, 20)
|
|
|
|
points.C2 = new Point(160, 20)
|
2022-12-30 07:38:49 -08:00
|
|
|
|
2024-02-10 15:40:41 +01:00
|
|
|
paths.path1 = new Path()
|
|
|
|
.move(points.A1)
|
|
|
|
.line(points.A2)
|
|
|
|
.move(points.B1)
|
|
|
|
.line(points.B2)
|
|
|
|
.move(points.C1)
|
|
|
|
.line(points.C2)
|
|
|
|
.setClass("various")
|
2022-12-30 07:38:49 -08:00
|
|
|
|
2024-02-10 15:40:41 +01:00
|
|
|
points.label1 = new Point(25, 8).addText('Total length = ' + units(paths.path1.length()))
|
|
|
|
points.label2 = new Point(25, 18).addText('Total length with moves = ' + units(paths.path1.length(true)))
|
2022-12-30 07:38:49 -08:00
|
|
|
|
2022-09-27 18:24:35 +02:00
|
|
|
|
|
|
|
return part
|
|
|
|
}
|
2021-08-25 16:09:31 +02:00
|
|
|
```
|
2022-09-27 18:24:35 +02:00
|
|
|
</Example>
|
2024-02-10 15:40:41 +01:00
|
|
|
|
|
|
|
## Notes
|
|
|
|
|
|
|
|
By default, `Path.length()` will measure the combined length of all drawing operations in the Path, but skip
|
|
|
|
over gaps in the path (caused by move operations).
|
|
|
|
If you want the full length of the Path, including move operations, pass `true` to `Path.length()`.
|
|
|
|
|