Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AABB {
- constructor(x, y, halfLength) {
- this.x = x;
- this.y = y;
- this.halfLength = halfLength;
- }
- containsball(ball) {
- if ((ball.x + ball.r >= this.x - this.halfLength) &&
- (ball.x - ball.r <= this.x + this.halfLength) &&
- (ball.y + ball.r >= this.y - this.halfLength) &&
- (ball.y - ball.r <= this.y + this.halfLength)) {
- return true;
- }
- return false;
- }
- intersectsAABB(otherAABB) {
- if (Math.abs(this.x - otherAABB.x) < this.halfLength + otherAABB.halfLength &&
- Math.abs(this.y - otherAABB.y) < this.halfLength + otherAABB.halfLength) {
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement