🎥 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.mdindex 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 twoslashimport { 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.mdnew file mode 100644index 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.jsindex 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.tssimilarity index 100%rename from packages/paths/src/get-reversed-path.tsrename to packages/paths/src/reverse-path.tsdiff --git a/packages/paths/src/test/get-parts.test.ts b/packages/paths/src/test/get-parts.test.tsindex 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.tsnew file mode 100644index 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');+});