Skip to content

🎥 Make videos programmatically with React

fix floating point deviations

Jonny Burger6ac2d84165b0
diff --git a/packages/shapes/src/test/make-polygon.test.ts b/packages/shapes/src/test/make-polygon.test.ts
index 7304160095..3538649a14 100644
--- a/packages/shapes/src/test/make-polygon.test.ts
+++ b/packages/shapes/src/test/make-polygon.test.ts
@@ -27,19 +27,16 @@ test('Should be able to make a pentagon path', () => {
radius: 100,
});
- expect(polygonPath).toEqual({
- path: 'M 100 0 L 195.10565162951536 69.09830056250526 L 158.77852522924732 180.90169943749476 L 41.2214747707527 180.90169943749476 L 4.894348370484636 69.09830056250527 L 100 0',
- width: 200,
- height: 200,
- transformOrigin: '100 100',
- instructions: [
- {type: 'M', x: 100, y: 0},
- {type: 'L', x: 195.10565162951536, y: 69.09830056250526},
- {type: 'L', x: 158.77852522924732, y: 180.90169943749476},
- {type: 'L', x: 41.2214747707527, y: 180.90169943749476},
- {type: 'L', x: 4.894348370484636, y: 69.09830056250527},
- {type: 'L', x: 100, y: 0},
- ],
+ expect(polygonPath.width).toEqual(200);
+ expect(polygonPath.height).toEqual(200);
+ expect(polygonPath.transformOrigin).toEqual('100 100');
+ expect(polygonPath.instructions.length).toEqual(6);
+ expect(polygonPath.instructions[0]).toEqual({type: 'M', x: 100, y: 0});
+ expect(polygonPath.instructions[5]).toEqual({type: 'L', x: 100, y: 0});
+ expect(polygonPath.instructions[4]).toEqual({
+ type: 'L',
+ x: 4.894348370484636,
+ y: 69.09830056250527,
});
});
diff --git a/packages/shapes/src/test/make-star.test.ts b/packages/shapes/src/test/make-star.test.ts
index 4564cba3e3..398ba9fe45 100644
--- a/packages/shapes/src/test/make-star.test.ts
+++ b/packages/shapes/src/test/make-star.test.ts
@@ -8,24 +8,13 @@ test('Should be able to make a star path', () => {
outerRadius: 200,
});
- expect(starPath).toEqual({
- path: 'M 190.21130325903073 0 L 278.3790911029017 78.64745084375788 L 380.42260651806146 138.19660112501052 L 332.8697807033037 246.3525491562421 L 307.7683537175254 361.8033988749895 L 190.21130325903073 350 L 72.65425280053613 361.8033988749895 L 47.55282581475771 246.35254915624213 L 0 138.19660112501055 L 102.04351541515975 78.6474508437579 L 190.21130325903073 0 Z',
- width: 400,
- height: 400,
- transformOrigin: '200 200',
- instructions: [
- {type: 'M', x: 200, y: 0},
- {type: 'L', x: 288.167787843871, y: 78.64745084375788},
- {type: 'L', x: 390.21130325903073, y: 138.19660112501052},
- {type: 'L', x: 342.658477444273, y: 246.3525491562421},
- {type: 'L', x: 317.55705045849464, y: 361.8033988749895},
- {type: 'L', x: 200, y: 350},
- {type: 'L', x: 82.4429495415054, y: 361.8033988749895},
- {type: 'L', x: 57.34152255572698, y: 246.35254915624213},
- {type: 'L', x: 9.788696740969272, y: 138.19660112501055},
- {type: 'L', x: 111.83221215612902, y: 78.6474508437579},
- {type: 'L', x: 200, y: 0},
- {type: 'Z'},
- ],
- });
+ expect(starPath.width).toEqual(400);
+ expect(starPath.height).toEqual(400);
+ expect(starPath.transformOrigin).toEqual('200 200');
+ expect(starPath.instructions.length).toEqual(12);
+ expect(starPath.instructions[0]).toEqual({type: 'M', x: 200, y: 0});
+ expect(starPath.instructions[11]).toEqual({type: 'Z'});
+ expect(starPath.path).toStartWith(
+ 'M 190.21130325903073 0 L 278.3790911029017 78.64745084375788 L 380.42260651806146',
+ );
});
diff --git a/packages/shapes/src/test/polygon.test.tsx b/packages/shapes/src/test/polygon.test.tsx
index 9cae68ba1a..04714f9d70 100644
--- a/packages/shapes/src/test/polygon.test.tsx
+++ b/packages/shapes/src/test/polygon.test.tsx
@@ -11,8 +11,8 @@ test('Should be able to make a triangle', () => {
test('Should be able to make a pentagon', () => {
const {container} = render(<Polygon radius={100} points={5} />);
- expect(container.querySelector('path')?.getAttribute('d')).toEqual(
- 'M 100 0 L 195.10565162951536 69.09830056250526 L 158.77852522924732 180.90169943749476 L 41.2214747707527 180.90169943749476 L 4.894348370484636 69.09830056250527 L 100 0',
+ expect(container.querySelector('path')?.getAttribute('d')).toStartWith(
+ 'M 100 0 L 195.10565162951536 69.09830056250526 L 158.77852522924732',
);
});
diff --git a/packages/shapes/src/test/star.test.tsx b/packages/shapes/src/test/star.test.tsx
index fd4ba1ab03..bf76dc40c2 100644
--- a/packages/shapes/src/test/star.test.tsx
+++ b/packages/shapes/src/test/star.test.tsx
@@ -7,7 +7,7 @@ test('Should be able to make a star svg', () => {
<Star innerRadius={200} outerRadius={150} points={5} />,
);
- expect(container.querySelector('path')?.getAttribute('d')).toEqual(
- 'M 190.2113032590307 11.803398874989483 L 307.7683537175253 0 L 332.8697807033037 115.45084971874738 L 380.42260651806146 223.60679774997897 L 278.37909110290167 283.15594803123156 L 190.2113032590307 361.8033988749895 L 102.04351541515975 283.15594803123156 L 0 223.606797749979 L 47.552825814757654 115.45084971874739 L 72.65425280053606 2.842170943040401e-14 L 190.2113032590307 11.803398874989483 Z',
+ expect(container.querySelector('path')?.getAttribute('d')).toStartWith(
+ 'M 190.2113032590307 11.803398874989483 L 307.7683537175253 0 L 332.8697807033037 115.45084971874738',
);
});