import * as I from 'immutable'; import {compose} from '@avocado/core'; import {Rectangle, Vector} from '@avocado/math'; import {EventEmitter} from '@avocado/mixins'; const decorate = compose( EventEmitter, Vector.Mixin('position', 'x', 'y', { default: [0, 0], track: true, }), ); class BodyBase { constructor(shape) { this.force = [0, 0]; this.impulse = [0, 0]; this.contacts = I.Set(); this.shape = shape; } get aabb() { return Rectangle.translated(this.shape.aabb, this.position); } applyForce(vector) { this.force = Vector.add(this.force, vector); } applyImpulse(vector) { this.impulse = Vector.add(this.impulse, vector); } } export class Body extends decorate(BodyBase) {}