UNPKG

aabb-tree

Version:

Basic implementation of the AABB-Tree (Axis Aligned Box Bounding Tree)

26 lines (25 loc) 928 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const AABB_1 = __importDefault(require("../AABB")); class Circle { constructor(center, radius) { this.center = center; this.radius = radius; const minX = this.center.X - this.radius; const minY = this.center.Y - this.radius; const maxX = this.center.X + this.radius; const maxY = this.center.Y + this.radius; this.AABB = new AABB_1.default(minX, minY, null, maxX, maxY, null); } GetAABB() { return this.AABB; } ContainsPoint(point) { const distSquared = Math.pow(point.X - this.center.X, 2) + Math.pow(point.Y - this.center.Y, 2); return distSquared < Math.pow(this.radius, 2); } } exports.default = Circle;