Skip to content

🎥 Make videos programmatically with React

finally fixed the issue and cover with more test

Antoine Caron4edb68b27678
diff --git a/packages/shapes/src/test/make-rect.test.ts b/packages/shapes/src/test/make-rect.test.ts
index c57170b7d3..9503b1a21f 100644
--- a/packages/shapes/src/test/make-rect.test.ts
+++ b/packages/shapes/src/test/make-rect.test.ts
@@ -26,7 +26,7 @@ test('Should handle rectangle path with radius', () => {
expect(rect).toEqual({
height: 100,
width: 100,
- path: 'M 20 0 L 80 0 a 20 20 0 0 1 20 20 L 100 80 a 20 20 0 0 1 -20 20 L 20 100 a 20 20 0 0 1 -20 -20 L 0 20 a 20 20 0 0 1 20 -20 Z',
+ path: 'M 60 0 L 80 0 a 20 20 0 0 1 20 20 L 100 80 a 20 20 0 0 1 -20 20 L 20 100 a 20 20 0 0 1 -20 -20 L 0 20 a 20 20 0 0 1 20 -20 Z',
transformOrigin: '50 50',
instructions: expect.any(Array),
});
diff --git a/packages/shapes/src/test/make-triangle.test.ts b/packages/shapes/src/test/make-triangle.test.ts
index 0416642032..a751113302 100644
--- a/packages/shapes/src/test/make-triangle.test.ts
+++ b/packages/shapes/src/test/make-triangle.test.ts
@@ -1,4 +1,4 @@
-import {expect, test} from 'vitest';
+import {describe, expect, test} from 'vitest';
import {makeTriangle} from '../utils/make-triangle';
test('Should be able to make a triangle path', () => {
@@ -22,34 +22,70 @@ test('Should be able to make a triangle path', () => {
});
});
-test('Should handle triangle path with radius', () => {
- const rightTriangle = makeTriangle({
- length: 100,
- direction: 'right',
- cornerRadius: 60,
+describe('with radius', () => {
+ test.only('should handle direction right', () => {
+ const triangle = makeTriangle({
+ length: 100,
+ direction: 'right',
+ cornerRadius: 60,
+ });
+
+ expect(triangle).toEqual({
+ height: 100,
+ path: 'M 0 40 L 0 40 C 0 100 0 100 51.96152422706631 70 L 34.64101615137755 80 C 86.60254037844386 50 86.60254037844386 50 34.64101615137755 20 L 51.96152422706631 30 C 0 0 0 0 0 60 Z',
+ transformOrigin: '28.867513459481287 50',
+ instructions: expect.any(Array),
+ width: 86.60254037844386,
+ });
});
- expect(rightTriangle).toEqual({
- height: 100,
- path: 'M 0 40 L 0 40 C 0 100 0 100 51.96152422706631 70 L 34.64101615137755 80 C 86.60254037844386 50 86.60254037844386 50 34.64101615137755 20 L 51.96152422706631 30 C 0 0 0 0 0 60 Z',
- transformOrigin: '28.867513459481287 50',
- instructions: expect.any(Array),
- width: 86.60254037844386,
+ test('should handle direction up', () => {
+ const triangle = makeTriangle({
+ length: 100,
+ direction: 'up',
+ cornerRadius: 60,
+ });
+
+ expect(triangle).toEqual({
+ height: 86.60254037844386,
+ instructions: expect.any(Array),
+ path: 'M 30 34.64101615137755 L 30 34.64101615137755 C 0 86.60254037844386 0 86.60254037844386 60 86.60254037844386 L 40 86.60254037844386 C 100 86.60254037844386 100 86.60254037844386 70 34.64101615137755 L 80 51.96152422706631 C 50 0 50 0 20 51.96152422706631 Z',
+ transformOrigin: '50 28.867513459481287',
+ width: 100,
+ });
});
-});
-test('Should handle triangle path with radius with direction up', () => {
- const upTriangle = makeTriangle({
- length: 100,
- direction: 'up',
- cornerRadius: 60,
+ test('should handle direction bottom', () => {
+ const triangle = makeTriangle({
+ length: 100,
+ direction: 'down',
+ cornerRadius: 60,
+ });
+
+ expect(triangle).toEqual({
+ height: 86.60254037844386,
+ instructions: expect.any(Array),
+ path: 'M 40 0 L 40 0 C 100 0 100 0 70 51.96152422706631 L 80 34.64101615137755 C 50 86.60254037844386 50 86.60254037844386 20 34.64101615137755 L 30 51.96152422706631 C 0 0 0 0 60 0 Z',
+ transformOrigin: '50 57.735026918962575',
+ width: 100,
+ });
});
- expect(upTriangle).toEqual({
- height: 86.60254037844386,
- instructions: expect.any(Array),
- path: 'M 30 34.64101615137755 L 30 34.64101615137755 C 0 86.60254037844386 0 86.60254037844386 60 86.60254037844386 L 40 86.60254037844386 C 100 86.60254037844386 100 86.60254037844386 70 34.64101615137755 L 80 51.96152422706631 C 50 0 50 0 20 51.96152422706631 Z',
- transformOrigin: '50 57.735026918962575',
- width: 100,
+ test('should handle direction left', () => {
+ const triangle = makeTriangle({
+ length: 100,
+ direction: 'left',
+ cornerRadius: 60,
+ });
+
+ expect(triangle).toEqual({
+ height: 100,
+ instructions: expect.any(Array),
+ path: 'M 86.60254037844386 40 L 86.60254037844386 40 C 86.60254037844386 100 86.60254037844386 100 34.64101615137755 70 L 51.96152422706631 80 C 0 50 0 50 51.96152422706631 20 L 34.64101615137755 30 C 86.60254037844386 0 86.60254037844386 0 86.60254037844386 60 Z',
+ transformOrigin: '57.735026918962575 50',
+ width: 86.60254037844386,
+ });
});
-});
+})
+
+
diff --git a/packages/shapes/src/utils/join-points.ts b/packages/shapes/src/utils/join-points.ts
index 8611605f47..ea3762153a 100644
--- a/packages/shapes/src/utils/join-points.ts
+++ b/packages/shapes/src/utils/join-points.ts
@@ -40,6 +40,8 @@ export const joinPoints = (
(x + prevPoint[0]) / 2,
(y + prevPoint[1]) / 2,
];
+ const prevVector = [x - prevPoint[0], y - prevPoint[1]] as const;
+ const nextVector = [nextPoint[0] - x, nextPoint[1] - y] as const;
if (i === 0) {
if (edgeRoundness !== null) {
@@ -52,18 +54,28 @@ export const joinPoints = (
];
}
- const shorten = shortenVector(nextPoint, cornerRadius)
+ if (cornerRadius !== 0) {
+ const computeRadius = shortenVector(nextVector, cornerRadius);
+
+ return [
+ {
+ type: 'M',
+ x: computeRadius[0],
+ y: computeRadius[1],
+ }
+ ]
+
+ }
+
return [
{
type: 'M',
- x: shorten[0],
- y: shorten[1],
+ x,
+ y,
},
];
}
- const prevVector = [x - prevPoint[0], y - prevPoint[1]] as const;
- const nextVector = [nextPoint[0] - x, nextPoint[1] - y] as const;
if (cornerRadius && edgeRoundness !== null) {
throw new Error(