Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. class AABB {
  2. constructor(x, y, halfLength) {
  3. this.x = x;
  4. this.y = y;
  5. this.halfLength = halfLength;
  6. }
  7. containsball(ball) {
  8. if ((ball.x + ball.r >= this.x - this.halfLength) &&
  9. (ball.x - ball.r <= this.x + this.halfLength) &&
  10. (ball.y + ball.r >= this.y - this.halfLength) &&
  11. (ball.y - ball.r <= this.y + this.halfLength)) {
  12. return true;
  13. }
  14. return false;
  15. }
  16. intersectsAABB(otherAABB) {
  17. if (Math.abs(this.x - otherAABB.x) < this.halfLength + otherAABB.halfLength &&
  18. Math.abs(this.y - otherAABB.y) < this.halfLength + otherAABB.halfLength) {
  19. return true;
  20. }
  21. return false;
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement