(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "three"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("three")); } else { var mod = { exports: {} }; factory(mod.exports, global.three); global.Capsule = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _three) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.Capsule = void 0; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } var _v1 = new _three.Vector3(); var _v2 = new _three.Vector3(); var _v3 = new _three.Vector3(); var EPS = 1e-10; var Capsule = /*#__PURE__*/function () { function Capsule() { var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new _three.Vector3(0, 0, 0); var end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _three.Vector3(0, 1, 0); var radius = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; _classCallCheck(this, Capsule); this.start = start; this.end = end; this.radius = radius; } _createClass(Capsule, [{ key: "clone", value: function clone() { return new Capsule(this.start.clone(), this.end.clone(), this.radius); } }, { key: "set", value: function set(start, end, radius) { this.start.copy(start); this.end.copy(end); this.radius = radius; } }, { key: "copy", value: function copy(capsule) { this.start.copy(capsule.start); this.end.copy(capsule.end); this.radius = capsule.radius; } }, { key: "getCenter", value: function getCenter(target) { return target.copy(this.end).add(this.start).multiplyScalar(0.5); } }, { key: "translate", value: function translate(v) { this.start.add(v); this.end.add(v); } }, { key: "checkAABBAxis", value: function checkAABBAxis(p1x, p1y, p2x, p2y, minx, maxx, miny, maxy, radius) { return (minx - p1x < radius || minx - p2x < radius) && (p1x - maxx < radius || p2x - maxx < radius) && (miny - p1y < radius || miny - p2y < radius) && (p1y - maxy < radius || p2y - maxy < radius); } }, { key: "intersectsBox", value: function intersectsBox(box) { return this.checkAABBAxis(this.start.x, this.start.y, this.end.x, this.end.y, box.min.x, box.max.x, box.min.y, box.max.y, this.radius) && this.checkAABBAxis(this.start.x, this.start.z, this.end.x, this.end.z, box.min.x, box.max.x, box.min.z, box.max.z, this.radius) && this.checkAABBAxis(this.start.y, this.start.z, this.end.y, this.end.z, box.min.y, box.max.y, box.min.z, box.max.z, this.radius); } }, { key: "lineLineMinimumPoints", value: function lineLineMinimumPoints(line1, line2) { var r = _v1.copy(line1.end).sub(line1.start); var s = _v2.copy(line2.end).sub(line2.start); var w = _v3.copy(line2.start).sub(line1.start); var a = r.dot(s), b = r.dot(r), c = s.dot(s), d = s.dot(w), e = r.dot(w); var t1, t2; var divisor = b * c - a * a; if (Math.abs(divisor) < EPS) { var d1 = -d / c; var d2 = (a - d) / c; if (Math.abs(d1 - 0.5) < Math.abs(d2 - 0.5)) { t1 = 0; t2 = d1; } else { t1 = 1; t2 = d2; } } else { t1 = (d * a + e * c) / divisor; t2 = (t1 * a - d) / c; } t2 = Math.max(0, Math.min(1, t2)); t1 = Math.max(0, Math.min(1, t1)); var point1 = r.multiplyScalar(t1).add(line1.start); var point2 = s.multiplyScalar(t2).add(line2.start); return [point1, point2]; } }]); return Capsule; }(); _exports.Capsule = Capsule; });