refactor: use equalsClose for position juggling

This commit is contained in:
cha0s 2019-03-24 04:03:15 -05:00
parent 957b4c8a15
commit 92f4f4a2d1
2 changed files with 7 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import {compose, virtualize} from '@avocado/core';
import {Vector} from '@avocado/math';
const decorate = compose(
virtualize([
@ -25,6 +26,9 @@ class AbstractWorldBase {
tick(elapsed) {
// Propagate position updates.
for (const entity of this.entities.values()) {
if (Vector.equalsClose(entity.position, entity.body.position)) {
continue;
}
entity.position = entity.body.position;
}
}

View File

@ -65,6 +65,9 @@ export class Body extends AbstractBody {
}
set position(position) {
if (Vector.equalsClose(this.position, position)) {
return;
}
MatterBody.setPosition(this.matterBody, {
x: position[0],
y: position[1],