MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / buildMotionPathObjectCode

Function buildMotionPathObjectCode

packages/parsers/src/gsapParser.ts:2716–2771  ·  view source on GitHub ↗
(config: {
  waypoints: Array<{ x: number; y: number }>;
  segments: ArcPathSegment[];
  autoRotate: boolean | number;
})

Source from the content-addressed store, hash-verified

2714}
2715
2716function buildMotionPathObjectCode(config: {
2717 waypoints: Array<{ x: number; y: number }>;
2718 segments: ArcPathSegment[];
2719 autoRotate: boolean | number;
2720}): string {
2721 const { waypoints, segments, autoRotate } = config;
2722 const hasExplicitControlPoints = segments.some((s) => s.cp1 && s.cp2);
2723 // The simple `path` array supports only one scalar curviness for the whole
2724 // path, so per-segment curviness must use the cubic form (curviness baked into
2725 // each segment's control points). Without this, the simple branch serializes
2726 // only segments[0].curviness and silently drops every other segment's curve.
2727 const curvinessVaries = segments.some(
2728 (s) => (s.curviness ?? 1) !== (segments[0]?.curviness ?? 1),
2729 );
2730
2731 let pathEntries: string[];
2732 if ((hasExplicitControlPoints || curvinessVaries) && waypoints.length >= 2) {
2733 // type: "cubic" — interleave control points: [anchor, cp1, cp2, anchor, ...]
2734 pathEntries = [`{x: ${waypoints[0]!.x}, y: ${waypoints[0]!.y}}`];
2735 for (let i = 0; i < segments.length; i++) {
2736 const seg = segments[i]!;
2737 const nextWp = waypoints[i + 1]!;
2738 if (seg.cp1 && seg.cp2) {
2739 pathEntries.push(`{x: ${seg.cp1.x}, y: ${seg.cp1.y}}`);
2740 pathEntries.push(`{x: ${seg.cp2.x}, y: ${seg.cp2.y}}`);
2741 } else {
2742 // Auto-generate simple midpoint control points from curviness
2743 const wp = waypoints[i]!;
2744 const dx = nextWp.x - wp.x;
2745 const dy = nextWp.y - wp.y;
2746 const c = seg.curviness ?? 1;
2747 pathEntries.push(
2748 `{x: ${wp.x + dx * 0.33}, y: ${wp.y + dy * 0.33 - c * Math.abs(dx) * 0.25}}`,
2749 );
2750 pathEntries.push(
2751 `{x: ${wp.x + dx * 0.66}, y: ${wp.y + dy * 0.66 - c * Math.abs(dx) * 0.25}}`,
2752 );
2753 }
2754 pathEntries.push(`{x: ${nextWp.x}, y: ${nextWp.y}}`);
2755 }
2756 const pathStr = pathEntries.join(", ");
2757 const parts = [`path: [${pathStr}]`, `type: "cubic"`];
2758 if (autoRotate === true) parts.push("autoRotate: true");
2759 else if (typeof autoRotate === "number") parts.push(`autoRotate: ${autoRotate}`);
2760 return `{ ${parts.join(", ")} }`;
2761 }
2762
2763 // Simple waypoint array with curviness
2764 pathEntries = waypoints.map((wp) => `{x: ${wp.x}, y: ${wp.y}}`);
2765 const curviness = segments[0]?.curviness ?? 1;
2766 const parts = [`path: [${pathEntries.join(", ")}]`];
2767 if (curviness !== 1) parts.push(`curviness: ${curviness}`);
2768 if (autoRotate === true) parts.push("autoRotate: true");
2769 else if (typeof autoRotate === "number") parts.push(`autoRotate: ${autoRotate}`);
2770 return `{ ${parts.join(", ")} }`;
2771}
2772
2773export function setArcPathInScript(

Callers 7

enableArcPathFunction · 0.70
updateArcSegmentInScriptFunction · 0.70
setArcPathInScriptFunction · 0.70
updateArcSegmentInScriptFunction · 0.70
writeMotionPathValueFunction · 0.70
addMotionPathToScriptFunction · 0.70

Calls 1

absMethod · 0.80

Tested by

no test coverage detected