javascript - 为什么 Matter.js 中需要这个字符?

标签 javascript physics-engine matter.js

我正在尝试将 Matter.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)

其中宽度高度是数字。 L 字符的用途是什么?我认为该方法应该将逗号或空格分隔的 x,y 对拆分为数字,因此我无法弄清楚 L 字符的相关性。

有人可以启发我吗?

最佳答案

L 是“线路至”命令。请参阅 SVG 路径语法( MDNspec ),matter.js 可以接受该语法作为路径规范。

关于javascript - 为什么 Matter.js 中需要这个字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35430805/

相关文章:

javascript - 加载图像以离线显示

c++ - 在 opengl 中将多边形或立方体表示为集合粒子

javascript - 如何使 matter.js 的最小示例工作?

javascript - 在 Matter.js 中禁用特定对象的重力

javascript - 二维软体 : Gelly and moldable?

javascript - 仅在 Javascript forEach/map 之后执行代码

javascript - 如何从列表中删除重复项

javascript - Bootstrap 开关检查检查状态始终返回 false

physics - 逼真的两足骨骼物理模拟

javascript - 物体在低速时不遵守反射定律