🎥 Make videos programmatically with React
document
Jonny Burger41e3aa6487c5
diff --git a/packages/docs/docs/paths/simplify-instructions.md b/packages/docs/docs/paths/simplify-instructions.mdnew file mode 100644index 0000000000..b12f2acb73--- /dev/null+++ b/packages/docs/docs/paths/simplify-instructions.md@@ -0,0 +1,33 @@+---+title: simplifyInstructions()+crumb: "@remotion/paths"+---++_Part of the [`@remotion/paths`](/docs/paths) package. Available from v3.3.40_++Takes an array of [`Instruction`](/docs/paths/parse-path)'s and reduces them so the path only consists of `M`, `L`, `C`, `Q` and `Z` instructions.+This is useful if you want to manually edit a path and want to make sure it's as simple as possible.++Note that this may result in a longer path.++```ts twoslash+import { simplifyInstructions } from "@remotion/paths";++const simplified = simplifyInstructions([+ { type: "m", dx: 10, dy: 10 },+ { type: "h", dx: 100 },+]);++/*+ [+ {type: 'M', x: 10, y: 10},+ {type: 'L', x: 110, y: 10},+ ]+*/+```++## See also++- [`@remotion/paths`](/docs/paths)+- [`parsePath()`](/docs/paths/parse-path)+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/paths/src/simplify-instructions.ts)diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 693394e67e..fbcacf7eab 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -264,9 +264,10 @@ module.exports = {"paths/translate-path","paths/get-bounding-box","paths/extend-viewbox",- "paths/get-parts","paths/parse-path","paths/serialize-instructions",+ "paths/simplify-instructions",+ "paths/get-parts",],},{diff --git a/packages/paths/src/index.ts b/packages/paths/src/index.tsindex 70f944df74..1b08f64c07 100644--- a/packages/paths/src/index.ts+++ b/packages/paths/src/index.ts@@ -6,11 +6,18 @@ export {getParts} from './get-parts';export {getPointAtLength} from './get-point-at-length';export {getSubpaths} from './get-subpaths';export {getTangentAtLength} from './get-tangent-at-length';-export {BoundingBox, Instruction, Part} from './helpers/types';+export {+ AbsoluteInstruction,+ BoundingBox,+ Instruction,+ Part,+ ReducedInstruction,+} from './helpers/types';export {interpolatePath} from './interpolate-path';export {normalizePath} from './normalize-path';export {parsePath} from './parse-path';export {resetPath} from './reset-path';export {reversePath} from './reverse-path';export {serializeInstructions} from './serialize-instructions';+export {simplifyInstructions} from './simplify-instructions';export {translatePath} from './translate-path';diff --git a/packages/paths/src/test/simplify-instructions.test.ts b/packages/paths/src/test/simplify-instructions.test.tsnew file mode 100644index 0000000000..f570f34ca2--- /dev/null+++ b/packages/paths/src/test/simplify-instructions.test.ts@@ -0,0 +1,59 @@+import {expect, test} from 'vitest';+import {simplifyInstructions} from '..';++test('Should simplify simple instructions', () => {+ const simplified = simplifyInstructions([+ {type: 'm', dx: 10, dy: 10},+ {type: 'h', dx: 100},+ ]);++ expect(simplified).toEqual([+ {type: 'M', x: 10, y: 10},+ {type: 'L', x: 110, y: 10},+ ]);+});++test('Should reduce A instructions', () => {+ const simplified = simplifyInstructions([+ {+ type: 'A',+ largeArcFlag: true,+ sweepFlag: true,+ rx: 100,+ ry: 100,+ xAxisRotation: 100,+ x: 100,+ y: 100,+ },+ ]);++ expect(simplified).toEqual([+ {+ type: 'C',+ cp1x: 0,+ cp1y: -55.22847498307934,+ cp2x: 44.77152501692067,+ cp2y: -99.99999999999996,+ x: 100,+ y: -99.99999999999997,+ },+ {+ type: 'C',+ cp1x: 155.2284749830793,+ cp1y: -99.99999999999997,+ cp2x: 199.99999999999997,+ cp2y: -55.228474983079316,+ x: 200,+ y: 1.0658141036401503e-14,+ },+ {+ type: 'C',+ cp1x: 200,+ cp1y: 55.22847498307934,+ cp2x: 155.22847498307934,+ cp2y: 100,+ x: 100.00000000000001,+ y: 100,+ },+ ]);+});