translatePath()
属于 @remotion/paths 软件包的一部分.
🌐 Part of the @remotion/paths package.
通过给定的 x 和 y 坐标平移路径。
🌐 Translates the path by the given x and y coordinates.
参数
🌐 Arguments
该函数接受三个参数:
🌐 The function takes three arguments:
path,原始的 SVG 路径。x,水平平移的量。y垂直平移的量。
返回值
🌐 Return value
返回一个新的 string,如果路径有效则包含该路径:
🌐 Returns a new string containing a path if it is valid:
translate-x.tsimport {translatePath } from "@remotion/paths"; consttranslatedPath =translatePath ("M 50 50 L 150 50", 10, 0);console .log (translatedPath ); // "M 50 50 L 150 50"
translate-y.tsimport {translatePath } from "@remotion/paths"; consttranslatedPath =translatePath ("M10 10 L15 15", 10, 10);console .log (translatedPath ); // "M 20 20 L 25 25"
translate-x-and-y.tsimport {translatePath } from "@remotion/paths"; consttranslatedPath =translatePath ( "M 35,50 a 25,25,0,1,1,50,0 a 25,25,0,1,1,-50,0", 10, 20 );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:
translatePath ("remotion", 10, 0); // Malformed path data: "m" ...鸣谢
🌐 Credits
源代码主要来自 translate-svg-path 和 serialize-svg-path。
🌐 Source code stems mostly from translate-svg-path and serialize-svg-path.
另请参阅
🌐 See also