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:
parent
3fd674d8f4
commit
497ac802fc
2 changed files with 6 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue