Skip to content

🎥 Make videos programmatically with React

document reversePath

Jonny Burgerc033ba38017e
diff --git a/packages/docs/docs/paths/get-point-at-length.md b/packages/docs/docs/paths/get-point-at-length.md
index fd24cbf2f8..34d48f42ab 100644
--- a/packages/docs/docs/paths/get-point-at-length.md
+++ b/packages/docs/docs/paths/get-point-at-length.md
@@ -7,13 +7,13 @@ _Part of the [`@remotion/paths`](/docs/paths) package._
Gets the coordinates of a point which is on an SVG path.
The first argument is an SVG path, the second one is the at which length the point should be sampled. It must be between `0` and the return value of [`getLength()`](/docs/paths/get-length).
-A number is returned if the path is valid:
+An object containing `x` and `y` is returned if the path is valid:
```tsx twoslash
import { getPointAtLength } from "@remotion/paths";
const point = getPointAtLength("M 0 0 L 100 0", 50);
-console.log(length); // { x: 50, y: 0 }
+console.log(point); // { x: 50, y: 0 }
```
The function will throw if the path is invalid:
diff --git a/packages/docs/docs/paths/reverse-path.md b/packages/docs/docs/paths/reverse-path.md
new file mode 100644
index 0000000000..e6a9fb7a10
--- /dev/null
+++ b/packages/docs/docs/paths/reverse-path.md
@@ -0,0 +1,22 @@
+---
+title: reversePath()
+---
+
+_Part of the [`@remotion/paths`](/docs/paths) package._
+
+Reverses a path so the end and start are switched.
+
+```tsx twoslash
+import { getLength } from "@remotion/paths";
+
+const reversedPath = getLength("M 0 0 L 100 0");
+console.log(reversedPath); // "L 100 0 M 0 0"
+```
+
+The function will throw if the path is invalid:
+
+```tsx twoslash
+import { getLength } from "@remotion/paths";
+// ---cut---
+getLength("remotion"); // Error: Malformed path data: ...
+```
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 7d0edf4ba9..b0047f06eb 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -286,6 +286,7 @@ module.exports = {
"paths/get-length",
"paths/get-parts",
"paths/get-point-at-length",
+ "paths/reverse-path",
],
},
{
diff --git a/packages/paths/src/get-reversed-path.ts b/packages/paths/src/reverse-path.ts
similarity index 100%
rename from packages/paths/src/get-reversed-path.ts
rename to packages/paths/src/reverse-path.ts
diff --git a/packages/paths/src/test/get-parts.test.ts b/packages/paths/src/test/get-parts.test.ts
index d4e325c443..401a5eec81 100644
--- a/packages/paths/src/test/get-parts.test.ts
+++ b/packages/paths/src/test/get-parts.test.ts
@@ -9,6 +9,4 @@ test('Should be able to get parts of a path', () => {
expect(parts[0].length).toEqual(100);
expect(parts[1].length).toEqual(100);
expect(parts[0].getPointAtLength(100).x).toEqual(100);
-
- console.log(parts[0].getTangentAtLength(50));
});
diff --git a/packages/paths/src/test/reverse-path.test.ts b/packages/paths/src/test/reverse-path.test.ts
new file mode 100644
index 0000000000..876267badb
--- /dev/null
+++ b/packages/paths/src/test/reverse-path.test.ts
@@ -0,0 +1,9 @@
+import {expect, test} from 'vitest';
+import {reversePath} from '../reverse-path';
+
+test('Should be able to reverse a path', () => {
+ const reversedPath = reversePath(`
+ M 0 0 L 100 0
+ `);
+ expect(reversedPath).toEqual('M 100 0 L 0 0');
+});