UNPKG

@turbox3d/math

Version:

Large-scale graphics application math library

90 lines 2.6 kB
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import { Vector3 } from './Vector3'; import { MathUtils } from '../MathUtils'; var _startP = new Vector3(); var _startEnd = new Vector3(); var Line3 = /*#__PURE__*/function () { function Line3(start, end) { _classCallCheck(this, Line3); this.start = start !== undefined ? start : new Vector3(); this.end = end !== undefined ? end : new Vector3(); } return _createClass(Line3, [{ key: "set", value: function set(start, end) { this.start.copy(start); this.end.copy(end); return this; } }, { key: "clone", value: function clone() { return new Line3().copy(this); } }, { key: "copy", value: function copy(line) { this.start.copy(line.start); this.end.copy(line.end); return this; } }, { key: "getCenter", value: function getCenter(target) { return target.addVectors(this.start, this.end).multiplyScalar(0.5); } }, { key: "delta", value: function delta(target) { return target.subVectors(this.end, this.start); } }, { key: "distanceSq", value: function distanceSq() { return this.start.distanceToSquared(this.end); } }, { key: "distance", value: function distance() { return this.start.distanceTo(this.end); } }, { key: "at", value: function at(t, target) { return this.delta(target).multiplyScalar(t).add(this.start); } }, { key: "closestPointToPointParameter", value: function closestPointToPointParameter(point, clampToLine) { _startP.subVectors(point, this.start); _startEnd.subVectors(this.end, this.start); var startEnd2 = _startEnd.dot(_startEnd); var startEndStartP = _startEnd.dot(_startP); var t = startEndStartP / startEnd2; if (clampToLine) { t = MathUtils.clamp(t, 0, 1); } return t; } }, { key: "closestPointToPoint", value: function closestPointToPoint(point, clampToLine, target) { var t = this.closestPointToPointParameter(point, clampToLine); return this.delta(target).multiplyScalar(t).add(this.start); } }, { key: "applyMatrix4", value: function applyMatrix4(matrix) { this.start.applyMatrix4(matrix); this.end.applyMatrix4(matrix); return this; } }, { key: "equals", value: function equals(line) { return line.start.equals(this.start) && line.end.equals(this.end); } }]); }(); export { Line3 };