UNPKG

aabb-tree

Version:

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

40 lines (39 loc) 1.43 kB
"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 Cylinder { constructor(referencePoint, radius, depth) { this.referencePoint = referencePoint; this.radius = radius; this.depth = depth; this.radiusSquared = radius * radius; } GetAABB() { const minX = this.referencePoint.X - this.radius; const maxX = this.referencePoint.X + this.radius; const minY = this.referencePoint.Y - this.radius; const maxY = this.referencePoint.Y + this.radius; const minZ = this.referencePoint.Z - this.depth; return new AABB_1.default(minX, minY, minZ, maxX, maxY, this.referencePoint.Z); } ContainsPoint(point) { if (point.Z > this.referencePoint.Z || point.Z < this.referencePoint.Z - this.depth) { return false; } const distSquared = Math.pow(point.X - this.referencePoint.X, 2) + Math.pow(point.Y - this.referencePoint.Y, 2); return distSquared < this.radiusSquared; } get ReferencePoint() { return this.referencePoint; } get Radius() { return this.radius; } get Depth() { return this.depth; } } exports.default = Cylinder;