Skip to content

🎥 Make videos programmatically with React

fix some tests

Jonny Burgerf538bf1de0ef
diff --git a/packages/docs/docs/paths/translate-path.md b/packages/docs/docs/paths/translate-path.md
index 19d8b4c747..f95a499f6d 100644
--- a/packages/docs/docs/paths/translate-path.md
+++ b/packages/docs/docs/paths/translate-path.md
@@ -31,7 +31,7 @@ console.log(translatedPath); // "M 50 50 L 150 50"
import { translatePath } from "@remotion/paths";
const translatedPath = translatePath("M10 10 L15 15", 10, 10);
-console.log(translatedPath); // "M 20,20 L 25,25"
+console.log(translatedPath); // "M 20 20 L 25 25"
```
```tsx twoslash title='translate-x-and-y.ts'
@@ -42,7 +42,7 @@ const translatedPath = translatePath(
10,
20
);
-console.log(translatedPath); // "M 45,70 a 25,25,0,1,1,50,0 a 25,25,0,1,1,-50,0"
+console.log(translatedPath); // "M 45 70 a 25 25 0 1 1 50 0 a 25, 5 0 1 1 -50 0"
```
The function will throw if the path is invalid:
diff --git a/packages/paths/src/get-bounding-box.ts b/packages/paths/src/get-bounding-box.ts
index 2e2ff2b662..132eafe321 100644
--- a/packages/paths/src/get-bounding-box.ts
+++ b/packages/paths/src/get-bounding-box.ts
@@ -1,6 +1,6 @@
import type {BoundingBox} from './helpers/types';
+import {unarc} from './helpers/unarc';
import {normalizePath} from './normalize-path';
-import {unarc} from './unarc';
import {unshort} from './unshort';
type minMax = [min: number, max: number];
diff --git a/packages/paths/src/helpers/iterate.ts b/packages/paths/src/helpers/iterate.ts
index b66eea2c46..97c18d1d89 100644
--- a/packages/paths/src/helpers/iterate.ts
+++ b/packages/paths/src/helpers/iterate.ts
@@ -1,13 +1,16 @@
import type {Instruction} from './parse';
-export const iterateOverSegments = (
- segments: Instruction[],
+export const iterateOverSegments = ({
+ segments,
+ iterate,
+}: {
+ segments: Instruction[];
iterate: (options: {
segment: Instruction;
x: number;
y: number;
- }) => Instruction[]
-): Instruction[] => {
+ }) => Instruction[];
+}): Instruction[] => {
let x = 0;
let y = 0;
diff --git a/packages/paths/src/helpers/unarc.ts b/packages/paths/src/helpers/unarc.ts
index af12082f35..d81ca4dd04 100644
--- a/packages/paths/src/helpers/unarc.ts
+++ b/packages/paths/src/helpers/unarc.ts
@@ -1,6 +1,6 @@
-import {iterateOverSegments} from './helpers/iterate';
-import type {Instruction} from './helpers/parse';
-import {parsePath} from './helpers/parse';
+import {iterateOverSegments} from './iterate';
+import type {Instruction} from './parse';
+import {parsePath} from './parse';
const TAU = Math.PI * 2;
@@ -124,33 +124,38 @@ export const unarc = (d: string) => {
const x = 0;
const y = 0;
- return iterateOverSegments(segments, ({segment}) => {
- const nextX = segment[6];
- const nextY = segment[7];
- const new_segments = a2c({
- x1: x,
- y1: y,
- x2: nextX,
- y2: nextY,
- fa: segment[4],
- fs: segment[5],
- rx: segment[1],
- ry: segment[2],
- phi: segment[3],
- });
-
- // Degenerated arcs can be ignored by renderer, but should not be dropped
- // to avoid collisions with `S A S` and so on. Replace with empty line.
- if (new_segments.length === 0) {
- return [['L', segment[6], segment[7]]];
- }
-
- const result: Instruction[] = [];
-
- new_segments.forEach((_s) => {
- result.push(['C', _s[2], _s[3], _s[4], _s[5], _s[6], _s[7]]);
- });
- return result;
+ return iterateOverSegments({
+ segments,
+ iterate: ({segment}) => {
+ if (segment[0] !== 'A') {
+ return [segment];
+ }
+
+ const nextX = segment[6];
+ const nextY = segment[7];
+ const new_segments = a2c({
+ x1: x,
+ y1: y,
+ x2: nextX,
+ y2: nextY,
+ fa: segment[4],
+ fs: segment[5],
+ rx: segment[1],
+ ry: segment[2],
+ phi: segment[3],
+ });
+
+ // Degenerated arcs can be ignored by renderer, but should not be dropped
+ // to avoid collisions with `S A S` and so on. Replace with empty line.
+ if (new_segments.length === 0) {
+ return [['L', segment[6], segment[7]]];
+ }
+
+ const result = new_segments.map((_s) => {
+ return ['C', _s[2], _s[3], _s[4], _s[5], _s[6], _s[7]] as Instruction;
+ });
+ return result;
+ },
});
};
diff --git a/packages/paths/src/test/translate-path.test.ts b/packages/paths/src/test/translate-path.test.ts
index fa3426e854..59f00373a5 100644
--- a/packages/paths/src/test/translate-path.test.ts
+++ b/packages/paths/src/test/translate-path.test.ts
@@ -4,13 +4,13 @@ import {translatePath} from '../translate-path';
test('Should be able to translate simple path, update x', () => {
const path = translatePath('M10 10 L15 15', 10, 0);
- expect(path).toEqual('M 20,10 L 25,15');
+ expect(path).toEqual('M 20 10 L 25 15');
});
test('Should be able to translate simple path, update x and y', () => {
const path = translatePath('M10 10 L15 15', 10, 10);
- expect(path).toEqual('M 20,20 L 25,25');
+ expect(path).toEqual('M 20 20 L 25 25');
});
test('Should be able to translate circle path, update x', () => {
@@ -20,7 +20,7 @@ test('Should be able to translate circle path, update x', () => {
0
);
- expect(path).toEqual('M 45,50 a 25,25,0,1,1,50,0 a 25,25,0,1,1,-50,0');
+ expect(path).toEqual('M 45 50 a 25 25 0 1 1 50 0 a 25 25 0 1 1 -50 0');
});
test('Should be able to translate circle path, update x and y', () => {
@@ -30,13 +30,13 @@ test('Should be able to translate circle path, update x and y', () => {
20
);
- expect(path).toEqual('M 45,70 a 25,25,0,1,1,50,0 a 25,25,0,1,1,-50,0');
+ expect(path).toEqual('M 45 70 a 25 25 0 1 1 50 0 a 25 25 0 1 1 -50 0');
});
test('Should be able to translate example path, update x', () => {
const path = translatePath('M 50 50 L 150 50', 10, 0);
- expect(path).toEqual('M 60,50 L 160,50');
+ expect(path).toEqual('M 60 50 L 160 50');
});
test('Translation should throw error', () => {