为什么在物质中需要这个字符.js

Why is this character required in matter.js?

本文关键字:字符 js 为什么      更新时间:2023-09-26

我正在尝试将物质.js移植到另一种语言。Javascript不是我最强的语言。

此函数应该将包含由空格(可选逗号(分隔的有序 x y 对的字符串解析为特定对象:

 * @method fromPath
 * @param {string} path
 * @param {body} body
 * @return {vertices} vertices
 */
Vertices.fromPath = function(path, body) {
    var pathPattern = /L?'s*(['-'d'.e]+)['s,]*(['-'d'.e]+)*/ig,
        points = [];
    path.replace(pathPattern, function(match, x, y) {
        points.push({ x: parseFloat(x), y: parseFloat(y) });
    });
    return Vertices.create(points, body);
};

稍后,会调用此函数,将以下字符串传递给 Vertices.fromPath:

vertices: Vertices.fromPath('L 0 0 L ' + width + ' 0 L ' + width + ' ' + height + ' L 0 ' + height)

其中widthheight是数字。L角色的目的是什么?我认为该方法应该将逗号或空格分隔的 x,y 对拆分为数字,所以我无法弄清楚L字符的相关性。

谁能开导我?

L是一个"Line To"命令。请参考 SVG 路径语法(MDN,规范(,这很重要.js可以接受作为路径规范。