Skip to content

🎥 Make videos programmatically with React

add properties

Jonny Burger559222a3ed3b
diff --git a/packages/paths/src/helpers/arc.ts b/packages/paths/src/helpers/arc.ts
index e3c39aac26..c2b5f827eb 100644
--- a/packages/paths/src/helpers/arc.ts
+++ b/packages/paths/src/helpers/arc.ts
@@ -307,6 +307,7 @@ export const makeArc = ({
getPointAtLength,
getTangentAtLength,
getTotalLength,
+ type: 'arc',
};
};
diff --git a/packages/paths/src/helpers/bezier.ts b/packages/paths/src/helpers/bezier.ts
index e75c724c38..9da755e20b 100644
--- a/packages/paths/src/helpers/bezier.ts
+++ b/packages/paths/src/helpers/bezier.ts
@@ -1,6 +1,6 @@
// Copied from: https://github.com/rveciana/svg-path-properties
-import type {Point} from './types';
+import type {Point, Properties} from './types';
import {
cubicDerivative,
@@ -30,7 +30,10 @@ export const makeBezier = ({
cy: number;
dx: number | null;
dy: number | null;
-}) => {
+}): Properties & {
+ getC: () => Point;
+ getD: () => Point;
+} => {
let d: Point;
let getArcLength: (xs: number[], ys: number[], t: number) => number;
let getPoint: (xs: number[], ys: number[], t: number) => Point;
@@ -85,26 +88,6 @@ export const makeBezier = ({
return tangent;
};
- const getPropertiesAtLength = (len: number) => {
- const xs = [a.x, b.x, c.x, d.x];
- const xy = [a.y, b.y, c.y, d.y];
- const t = t2length(len, len, (i) => getArcLength(xs, xy, i));
-
- const derivative = getDerivative(xs, xy, t);
- const mdl = Math.sqrt(
- derivative.x * derivative.x + derivative.y * derivative.y,
- );
- let tangent: Point;
- if (mdl > 0) {
- tangent = {x: derivative.x / mdl, y: derivative.y / mdl};
- } else {
- tangent = {x: 0, y: 0};
- }
-
- const point = getPoint(xs, xy, t);
- return {x: point.x, y: point.y, tangentX: tangent.x, tangentY: tangent.y};
- };
-
const getC = () => {
return c;
};
@@ -115,10 +98,10 @@ export const makeBezier = ({
return {
getPointAtLength,
- getPropertiesAtLength,
getTangentAtLength,
getTotalLength,
getC,
getD,
+ type: 'bezier',
};
};
diff --git a/packages/paths/src/helpers/linear.ts b/packages/paths/src/helpers/linear.ts
index fd11082cd8..12fa563258 100644
--- a/packages/paths/src/helpers/linear.ts
+++ b/packages/paths/src/helpers/linear.ts
@@ -1,5 +1,5 @@
// Copied from: https://github.com/rveciana/svg-path-properties
-import type {Point, PointProperties} from './types';
+import type {Point, Properties} from './types';
export const makeLinearPosition = ({
x0,
@@ -11,7 +11,7 @@ export const makeLinearPosition = ({
x1: number;
y0: number;
y1: number;
-}) => {
+}): Properties => {
const getTotalLength = () => {
return Math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2);
};
@@ -31,15 +31,10 @@ export const makeLinearPosition = ({
return {x: (x1 - x0) / module, y: (y1 - y0) / module};
};
- const getPropertiesAtLength = (): PointProperties => {
- const tangent = getTangentAtLength();
- return {tangentX: tangent.x, tangentY: tangent.y};
- };
-
return {
getTotalLength,
getPointAtLength,
getTangentAtLength,
- getPropertiesAtLength,
+ type: 'linear',
};
};
diff --git a/packages/paths/src/helpers/types.ts b/packages/paths/src/helpers/types.ts
index bef5e6a24c..9cc5ff8049 100644
--- a/packages/paths/src/helpers/types.ts
+++ b/packages/paths/src/helpers/types.ts
@@ -4,6 +4,7 @@ export interface Properties {
getTotalLength(): number;
getPointAtLength(pos: number): Point;
getTangentAtLength(pos: number): Point;
+ type: string;
}
export interface Part {