0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-12 16:08:50 -05:00

add window global, stub require and handle bad values in test tools

This commit is contained in:
liabru 2020-03-09 21:05:05 +00:00
parent 3fd674d8f4
commit 497ac802fc
2 changed files with 6 additions and 2 deletions

View file

@ -4,6 +4,7 @@
const stubBrowserFeatures = M => {
const noop = () => ({ collisionFilter: {}, mouse: {} });
M.Common._requireGlobal = name => global[name];
M.Render.create = () => ({ options: {}, bounds: { min: { x: 0, y: 0 }, max: { x: 800, y: 600 }}});
M.Render.run = M.Render.lookAt = noop;
M.Runner.create = M.Runner.run = noop;
@ -30,7 +31,7 @@ const runExample = options => {
const consoleOriginal = global.console;
global.console = { log: () => {} };
global.document = {};
global.document = global.window = { addEventListener: () => {} };
global.decomp = decomp;
global.Matter = Matter;
@ -76,6 +77,7 @@ const runExample = options => {
}
global.console = consoleOriginal;
global.window = undefined;
global.document = undefined;
global.decomp = undefined;
global.Matter = undefined;

View file

@ -118,7 +118,9 @@ const worldCaptureIntrinsicBase = (obj, depth=0) => {
};
const similarity = (a, b) => {
const distance = Math.sqrt(a.reduce((sum, _val, i) => sum + Math.pow(a[i] - b[i], 2), 0));
const distance = Math.sqrt(a.reduce(
(sum, _val, i) => sum + Math.pow((a[i] || 0) - (b[i] || 0), 2), 0)
);
return 1 / (1 + (distance / a.length));
};