![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/libs/absol-full/dist/js/ |
Upload File : |
/*** module: node_modules/absol/src/Math/SegmentLine.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _Vec = _interopRequireDefault(require("./Vec2")); /** * * @param {Vec2} start * @param {Vec2}end * @constructor */ function SegmentLine(start, end) { this.start = start; this.end = end; } SegmentLine.prototype.length = function () { return this.start.dist(this.end); }; /** * * @param t * @returns {Vec2} */ SegmentLine.prototype.pointAt = function (t) { return this.start.add(this.end.sub(this.start).mult(t)); }; /** * * @param {Vec2} point * @returns {number} */ SegmentLine.prototype.nearestParamToPoint = function (point) { var v = this.end.sub(this.start); var w = point.sub(this.start); var c1 = w.dot(v); if (c1 <= 0) { return 0; } var c2 = v.dot(v); if (c2 <= c1) { return 1; } return c1 / c2; }; /** * * @param {Vec2} point * @returns {Vec2} */ SegmentLine.prototype.nearestPointToPoint = function (point) { return this.pointAt(this.nearestParamToPoint(point)); }; /** * * @param {SegmentLine} sgm * @returns {Vec2} */ SegmentLine.prototype.intersect = function (sgm) { var x1 = this.start.x; var y1 = this.start.y; var x2 = this.end.x; var y2 = this.end.y; var x3 = sgm.start.x; var y3 = sgm.start.y; var x4 = sgm.end.x; var y4 = sgm.end.y; var d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); if (d === 0) { return null; } var xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d; var yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d; return new _Vec.default(xi, yi); }; /** * * @param {SegmentLine} sgm * @returns {boolean} */ SegmentLine.prototype.isIntersectWithSegment = function (sgm) { return this.intersect(sgm) !== null; }; /** * @param {Vec2} point */ SegmentLine.prototype.orthogonalProjectionPoint = function (point) { var v = this.end.sub(this.start); var w = point.sub(this.start); var c1 = w.dot(v); var c2 = v.dot(v); if (c2 === 0) return this.start; return this.start.add(v.mult(c1 / c2)); }; SegmentLine.prototype.midpoint = function () { return this.pointAt(0.5); }; SegmentLine.prototype.clone = function () { return new SegmentLine(this.start.clone(), this.end.clone()); }; var _default = SegmentLine; exports.default = _default;