/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
'use strict';

/******************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */

var extendStatics = function(d, b) {
  extendStatics = Object.setPrototypeOf ||
      ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
      function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  return extendStatics(d, b);
};

function __extends(d, b) {
  if (typeof b !== "function" && b !== null)
      throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  extendStatics(d, b);
  function __() { this.constructor = d; }
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}

exports.__assign = function() {
  exports.__assign = Object.assign || function __assign(t) {
      for (var s, i = 1, n = arguments.length; i < n; i++) {
          s = arguments[i];
          for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
      return t;
  };
  return exports.__assign.apply(this, arguments);
};

function __awaiter(thisArg, _arguments, P, generator) {
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  return new (P || (P = Promise))(function (resolve, reject) {
      function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
      function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
      function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
      step((generator = generator.apply(thisArg, _arguments || [])).next());
  });
}

function __generator(thisArg, body) {
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
  return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  function verb(n) { return function (v) { return step([n, v]); }; }
  function step(op) {
      if (f) throw new TypeError("Generator is already executing.");
      while (g && (g = 0, op[0] && (_ = 0)), _) try {
          if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
          if (y = 0, t) op = [op[0] & 2, t.value];
          switch (op[0]) {
              case 0: case 1: t = op; break;
              case 4: _.label++; return { value: op[1], done: false };
              case 5: _.label++; y = op[1]; op = [0]; continue;
              case 7: op = _.ops.pop(); _.trys.pop(); continue;
              default:
                  if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                  if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                  if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                  if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                  if (t[2]) _.ops.pop();
                  _.trys.pop(); continue;
          }
          op = body.call(thisArg, _);
      } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
      if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  }
}

function __values(o) {
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  if (m) return m.call(o);
  if (o && typeof o.length === "number") return {
      next: function () {
          if (o && i >= o.length) o = void 0;
          return { value: o && o[i++], done: !o };
      }
  };
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}

function __read(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m) return o;
  var i = m.call(o), r, ar = [], e;
  try {
      while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  }
  catch (error) { e = { error: error }; }
  finally {
      try {
          if (r && !r.done && (m = i["return"])) m.call(i);
      }
      finally { if (e) throw e.error; }
  }
  return ar;
}

function __spreadArray(to, from, pack) {
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
      if (ar || !(i in from)) {
          if (!ar) ar = Array.prototype.slice.call(from, 0, i);
          ar[i] = from[i];
      }
  }
  return to.concat(ar || Array.prototype.slice.call(from));
}

function __asyncValues(o) {
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  var m = o[Symbol.asyncIterator], i;
  return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}

typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
  var e = new Error(message);
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};

/**
 * Clamps the given value between `min` and `max`.
 *
 * @param value The value to clamp.
 * @param min The min possible value.
 * @param max The max possible value.
 * @returns `value` or a value clamped to `min` or `max`.
 */
function clamp(value, min, max) {
    return Math.max(min, Math.min(max, value));
}
/**
 * Linear interpolates a value between `a` and `b` by `t`. If `t` is 0, then the
 * result will be `a`. If `t` is 1, then the result will be `b`. `t` will be
 * clamped to a value between 0 and 1.
 *
 * @param a The start value.
 * @param b The end value.
 * @param t The interpolation value between 0 and 1.
 * @returns The interpolated value between `a` and `b`.
 */
function lerp$2(a, b, t) {
    t = clamp(t, 0, 1);
    return t * (b - a) + a;
}

/**
 * Returns a new `Point` with the given horizontal and vertical position.
 */
function create$d(x, y) {
    if (x === void 0) { x = 0; }
    if (y === void 0) { y = 0; }
    return { x: x, y: y };
}
/**
 * Converts a polar coordinate (length and angle) into a Cartesian coordinate.
 */
function polar(length, radians) {
    var x = Math.cos(radians) * length;
    var y = Math.sin(radians) * length;
    return create$d(x, y);
}
/**
 * Returns the distance between two points.
 */
function distance$2(a, b) {
    var delta = subtract$1(a, b);
    return Math.sqrt(delta.x * delta.x + delta.y * delta.y);
}
/**
 * Returns a new `Point` where `b` is subtracted from `a`.
 */
function subtract$1(a, b) {
    return { x: a.x - b.x, y: a.y - b.y };
}
/**
 * Returns a new `Point` where `b` is added to `a`.
 */
function add$1(a, b) {
    return { x: a.x + b.x, y: a.y + b.y };
}
/**
 * Returns `true` if the `x` and `y` positions of `a` and `b` are equal.
 */
function isEqual$3(a, b) {
    return a.x === b.x && a.y === b.y;
}
/**
 * Performs a linear interpolation between `a` and `b` and returns the result.
 * The value of `t` is clamped between `[0, 1]`.
 *
 * @param a The start value.
 * @param b The end value.
 * @param t A value between 0 and 1.
 * @returns A point between `a` and `b`.
 */
function lerp$1(a, b, t) {
    return {
        x: lerp$2(a.x, b.x, t),
        y: lerp$2(a.y, b.y, t),
    };
}
/**
 * Returns a new `Point` where `x` and `y` are inverted.
 */
function negate$1(pt) {
    return create$d(-pt.x, -pt.y);
}
/**
 * Returns a new `Point` where `x` and `y` are multiplied by the given scale
 * factors.
 */
function scale$5(pt, scaleX, scaleY) {
    return {
        x: pt.x * scaleX,
        y: pt.y * scaleY,
    };
}
/**
 * Returns a new `Point` where `x` and `y` are multiplied by the given scale
 * factor.
 */
function scaleProportional(pt, scale) {
    return {
        x: pt.x * scale,
        y: pt.y * scale,
    };
}
/**
 * Returns the magnitude of a point.
 */
function magnitude$2(pt) {
    return Math.sqrt(pt.x * pt.x + pt.y * pt.y);
}
/**
 * Transforms a vector into the corresponding normal (unit) vector.
 */
function normalizeVector(pt) {
    var magnitudeOfPoint = magnitude$2(pt);
    if (magnitudeOfPoint === 0) {
        return create$d(0, 0);
    }
    else {
        return scaleProportional(pt, 1 / magnitudeOfPoint);
    }
}
/**
 * Returns a new normal (unit) vector pointing between the two given points.
 */
function normalDirectionVector(ptA, ptB) {
    return normalizeVector(subtract$1(ptB, ptA));
}
/**
 * Returns a vector orthogonal to the vector between the two given points.
 */
function orthogonalVector(ptA, ptB) {
    var unitVectorBetweenPoints = normalDirectionVector(ptA, ptB);
    // Handle vectors that are parallel to the x or y axis
    if (unitVectorBetweenPoints.x === 0 || unitVectorBetweenPoints.y === 0) {
        return create$d(-1 * unitVectorBetweenPoints.y, unitVectorBetweenPoints.x);
    }
    if (Math.abs(unitVectorBetweenPoints.x) > Math.abs(unitVectorBetweenPoints.y)) {
        var vectorXValue = 1 - Math.pow(unitVectorBetweenPoints.x, 2);
        var vectorYValue = -1 * unitVectorBetweenPoints.x * unitVectorBetweenPoints.y;
        return normalizeVector(create$d(vectorXValue, vectorYValue));
    }
    else {
        var vectorXValue = -1 * unitVectorBetweenPoints.x * unitVectorBetweenPoints.y;
        var vectorYValue = 1 - Math.pow(unitVectorBetweenPoints.y, 2);
        return normalizeVector(create$d(vectorXValue, vectorYValue));
    }
}
/**
 * Parses a JSON string representation of a Point and returns an object.
 *
 * @param json A JSON string, either in the form `[x,y]` or `{"x": 0, "y": 0}`
 * @returns A parsed Point.
 */
function fromJson$5(json) {
    var obj = JSON.parse(json);
    if (Array.isArray(obj)) {
        var x = obj[0], y = obj[1];
        return create$d(x, y);
    }
    else {
        var x = obj.x, y = obj.y;
        return create$d(x, y);
    }
}

var point = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create$d,
  polar: polar,
  distance: distance$2,
  subtract: subtract$1,
  add: add$1,
  isEqual: isEqual$3,
  lerp: lerp$1,
  negate: negate$1,
  scale: scale$5,
  scaleProportional: scaleProportional,
  magnitude: magnitude$2,
  normalizeVector: normalizeVector,
  normalDirectionVector: normalDirectionVector,
  orthogonalVector: orthogonalVector,
  fromJson: fromJson$5
});

/**
 * Returns an `Angle` between two points, in radians.
 *
 * @param a The starting point.
 * @param b The ending point.
 * @returns An angle in radians.
 */
function fromPoints$1(a, b) {
    var delta = subtract$1(b, a);
    var theta = Math.atan2(delta.y, delta.x);
    return theta;
}
/**
 * Returns an `Angle` between two points, in degrees.
 *
 * An angle of 0 represents an upward vector, and increases in a clockwise
 * direction.
 *
 * @deprecated Use {@link fromPoints} instead.
 */
function fromPointsInDegrees(a, b) {
    var delta = subtract$1(b, a);
    var theta = Math.atan2(delta.y, delta.x);
    return normalize$2(toDegrees(theta) - 270);
}
/**
 * Normalizes the given angle, in degrees, to a number greater than or equal to 0 and less than 360.
 */
function normalize$2(degrees) {
    return (degrees + 3600) % 360;
}
/**
 * Normalizes the given angle, in radians, to a number greater than or equal to 0 and less than 2 PI.
 */
function normalizeRadians(radians) {
    return toRadians(normalize$2(toDegrees(radians)));
}
/**
 * Converts the given radians to degrees.
 */
function toDegrees(radians) {
    return radians * (180 / Math.PI);
}
/**
 * Converts the given degrees to radians.
 */
function toRadians(degrees) {
    return degrees * (Math.PI / 180);
}

var angle = /*#__PURE__*/Object.freeze({
  __proto__: null,
  fromPoints: fromPoints$1,
  fromPointsInDegrees: fromPointsInDegrees,
  normalize: normalize$2,
  normalizeRadians: normalizeRadians,
  toDegrees: toDegrees,
  toRadians: toRadians
});

/**
 * Creates a 4x4 matrix from a set of row-major components.
 */
function fromValues(
/* eslint-disable prettier/prettier */
m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
    /* eslint-disable prettier/prettier */
    return [
        m11, m21, m31, m41,
        m12, m22, m32, m42,
        m13, m23, m33, m43,
        m14, m24, m34, m44,
    ];
    /* eslint-enable prettier/prettier */
}
/**
 * Creates a `Matrix4` from an object representation.
 */
function fromObject(obj) {
    /* eslint-disable prettier/prettier */
    return fromValues(obj.m11, obj.m12, obj.m13, obj.m14, obj.m21, obj.m22, obj.m23, obj.m24, obj.m31, obj.m32, obj.m33, obj.m34, obj.m41, obj.m42, obj.m43, obj.m44);
    /* eslint-enable prettier/prettier */
}
/**
 * Returns a new [identity matrix](https://en.wikipedia.org/wiki/Identity_matrix).
 */
function makeIdentity() {
    return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
}
/**
 * Returns a matrix with all values as 0.
 */
function makeZero() {
    return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
/**
 * Creates a translation matrix.
 *
 * ```
 * 1, 0, 0, 0,
 * 0, 1, 0, 0,
 * 0, 0, 1, 0,
 * x, y, z, 1
 * ```
 *
 * @param translation A vector representing the translation components.
 * @returns A translation matrix.
 */
function makeTranslation(translation) {
    var x = translation.x, y = translation.y, z = translation.z;
    /* eslint-disable prettier/prettier */
    return [
        1, 0, 0, 0,
        0, 1, 0, 0,
        0, 0, 1, 0,
        x, y, z, 1,
    ];
    /* eslint-enable prettier/prettier */
}
/**
 * Creates a rotation matrix.
 *
 * ```
 * 1-2y²-2z²,    2xy-2zw,    2xz+2yw,    0,
 * 2xy+2zw,      1-2x²-2z²,  2yz-2xw,    0,
 * 2xz-2yw,      2yz+2xw,    1-2x²-2y²,  0,
 * 0,            0,          0,          1,
 * ```
 *
 * @param rotation A quaternion representing the rotation.
 * @see https://en.wikipedia.org/wiki/Rotation_matrix#Quaternion
 * @returns A rotation matrix.
 */
function makeRotation(rotation) {
    var x = rotation.x, y = rotation.y, z = rotation.z, w = rotation.w;
    var x2 = x + x, y2 = y + y, z2 = z + z;
    var xx = x * x2, xy = x * y2, xz = x * z2;
    var yy = y * y2, yz = y * z2, zz = z * z2;
    var wx = w * x2, wy = w * y2, wz = w * z2;
    /* eslint-disable prettier/prettier */
    return [
        1 - (yy + zz), xy + wz, xz - wy, 0,
        xy - wz, 1 - (xx + zz), yz + wx, 0,
        xz + wy, yz - wx, 1 - (xx + yy), 0,
        0, 0, 0, 1
    ];
    /* eslint-enable prettier/prettier */
}
/**
 * Creates a scale matrix.
 *
 * ```
 * x, 0, 0, 0,
 * 0, y, 0, 0,
 * 0, 0, z, 0,
 * 0, 0, 0, 1
 * ```
 *
 * @param scale A vector representing the different scale components.
 * @returns A scale matrix.
 */
function makeScale(scale) {
    var x = scale.x, y = scale.y, z = scale.z;
    /* eslint-disable prettier/prettier */
    return [
        x, 0, 0, 0,
        0, y, 0, 0,
        0, 0, z, 0,
        0, 0, 0, 1,
    ];
    /* eslint-enable prettier/prettier */
}
/**
 * Creates a matrix that has translation, rotation and scale applied to it.
 *
 * @param translation The translation applied to the matrix.
 * @param rotation The rotation applied to the matrix.
 * @param scale The scale applied to the matrix.
 * @returns A transformed matrix.
 */
function makeTRS(translation, rotation, scale) {
    var t = makeTranslation(translation);
    var r = makeRotation(rotation);
    var s = makeScale(scale);
    return multiply$2(multiply$2(t, r), s);
}
/**
 * Returns a matrix that has the basis components (upper left 3x3 matrix) set to
 * the following x, y, and z axis.
 *
 * ```
 * x.x  y.x  z.x  0
 * x.y  y.y  z.y  0
 * x.z  y.z  z.z  0
 * 0    0    0    0
 * ```
 *
 * @param x The x axis to set.
 * @param y The y axis to set.
 * @param z The z axis to set.
 * @returns A matrix with its basis components populated.
 */
function makeBasis(x, y, z) {
    /* eslint-disable prettier/prettier */
    return [
        x.x, x.y, x.z, 0,
        y.x, y.y, y.z, 0,
        z.x, z.y, z.z, 0,
        0, 0, 0, 1
    ];
    /* eslint-enable prettier/prettier */
}
/**
 * Creates a rotation matrix that is rotated around a given axis by the given
 * angle.
 *
 * @param axis The axis of rotation.
 * @param radians The angle of rotation.
 * @returns A rotation matrix.
 */
function makeRotationAxis(axis, radians) {
    var c = Math.cos(radians);
    var s = Math.sin(radians);
    var t = 1 - c;
    var x = axis.x, y = axis.y, z = axis.z;
    var tx = t * x;
    var ty = t * y;
    /* eslint-disable prettier/prettier */
    return [
        tx * x + c, tx * y + s * z, tx * z - s * y, 0,
        tx * y - s * z, ty * y + c, ty * z + s * x, 0,
        tx * z + s * y, ty * z - s * x, t * z * z + c, 0,
        0, 0, 0, 1
    ];
    /* eslint-enable prettier/prettier */
}
/**
 * Creates a matrix used for [perspective
 * projections](https://en.wikipedia.org/wiki/3D_projection#Perspective_projection).
 *
 * The viewing volume is frustum-shaped and defined by the six parameters. Left,
 * right, top, and bottom specify coordinates in the near clipping plane where
 * the frustum edges intersect it, and the near and far parameters define the
 * forward distances of the view volume. The resulting volume can be vertically
 * and horizontally asymmetrical around the center of the near plane.
 *
 * @param left The left coordinate at the near plane.
 * @param right The right coordinate at the near plane.
 * @param top The top coordinate at the near plane.
 * @param bottom The bottom coordinate at the near plane.
 * @param near The near distance.
 * @param far The far distance.
 * @returns A matrix representing a view frustum.
 */
function makeFrustum(left, right, top, bottom, near, far) {
    var x = (2 * near) / (right - left);
    var y = (2 * near) / (top - bottom);
    var a = (right + left) / (right - left);
    var b = (top + bottom) / (top - bottom);
    var c = -(far + near) / (far - near);
    var d = (-2 * far * near) / (far - near);
    /* eslint-disable prettier/prettier */
    return [
        x, 0, 0, 0,
        0, y, 0, 0,
        a, b, c, -1,
        0, 0, d, 0
    ];
    /* eslint-enable prettier/prettier */
}
/**
 * Creates a perspective projection matrix.
 *
 * Related to: gluPerspective. The viewing volume is frustum-shaped amd defined
 * by the four parameters. The fovy and aspect ratio are used to compute the
 * positions of the left, right, top, and bottom sides of the viewing volume in
 * the zNear plane. The fovy is the y field-of-view, the angle made by the top
 * and bottom sides of frustum if they were to intersect. The aspect ratio is
 * the width of the frustum divided by its height. Note that the resulting
 * volume is both vertically and horizontally symmetrical around the center of
 * the near plane.
 *
 * @param near The near Z value.
 * @param far The far Z value.
 * @param fovY The field of view.
 * @param aspect The aspect ratio.
 * @returns A matrix.
 */
function makePerspective(near, far, fovY, aspect) {
    var ymax = near * Math.tan(toRadians(fovY / 2.0));
    var xmax = ymax * aspect;
    var left = -xmax;
    var right = xmax;
    var top = ymax;
    var bottom = -ymax;
    return makeFrustum(left, right, top, bottom, near, far);
}
/**
 * Creates an orthographic projection matrix.
 *
 * Related to: gluOrtho. The viewing volume is cube-shaped and defined by
 * the six parameters. The left and right values represent the coordinates of
 * the vertical clipping planes, top and bottom values represent the coordinates
 * of the horizontal clipping planes, and near and far values represent the
 * coordinates of the depth clipping planes.
 *
 * @param left The coordinate of the left horizontal clipping plane.
 * @param right The coordinate of the right horizontal clipping plane.
 * @param bottom The coordinate of the bottom vertical clipping plane.
 * @param top The coordinate of the top vertical clipping plane.
 * @param near The coordinate of the near depth clipping plane.
 * @param far The coordinate of the far depth clipping plane.
 * @returns A matrix.
 */
function makeOrthographic(left, right, bottom, top, near, far) {
    var w = 1.0 / (right - left);
    var h = 1.0 / (top - bottom);
    var d = 1.0 / (far - near);
    var x = (right + left) * w;
    var y = (top + bottom) * h;
    var z = (far + near) * d;
    /* eslint-disable prettier/prettier */
    return [
        2 * w, 0, 0, -x,
        0, 2 * h, 0, -y,
        0, 0, -2 * d, -z,
        0, 0, 0, 1
    ];
    /* eslint-enable prettier/prettier */
}
/**
 * Matrix becomes a combination of an inverse translation and rotation.
 *
 * Related to: gluLookAt. This creates the inverse of makeLookAtMatrix. The
 * matrix will be an opposite translation from the 'eye' position, and it will
 * rotate things in the opposite direction of the eye-to-center orientation.
 * This is definitely confusing, but the main reason to use this transform is to
 * set up a view matrix for a camera that's looking at a certain point. To
 * achieve the effect of moving the camera somewhere and rotating it so that it
 * points at something, the rest of the world is moved in the opposite direction
 * and rotated in the opposite way around the camera. This way, you get the same
 * effect as moving the actual camera, but all the projection math can still be
 * done with the camera positioned at the origin (which makes it way simpler).
 *
 * @param position The position of the object.
 * @param lookAt The point which the object is looking at.
 * @param up The direction which the object considers up.
 * @returns A matrix.
 */
function makeLookAtView(position, lookAt, up) {
    var z = normalize(subtract(position, lookAt));
    var x = normalize(cross(up, z));
    var y = cross(z, x);
    var dotX = -dot$1(x, position);
    var dotY = -dot$1(y, position);
    var dotZ = -dot$1(z, position);
    /* eslint-disable prettier/prettier */
    return [
        x.x, y.x, z.x, 0,
        x.y, y.y, z.y, 0,
        x.z, y.z, z.z, 0,
        dotX, dotY, dotZ, 1,
    ];
    /* eslint-enable prettier/prettier */
}
/**
 * Matrix becomes a combination of translation and rotation.
 *
 * Matrix becomes a combination of a translation to the position of 'eye' and a
 * rotation matrix which orients an object to point towards 'center' along its
 * z-axis. Use this function if you want an object to look at a point from
 * another point in space.
 *
 * @param position The position of the object.
 * @param lookAt The point which the object is looking at.
 * @param up The direction which the object considers up.
 * @returns A matrix.
 */
function makeLookAt(position, lookAt, up) {
    var z = normalize(subtract(position, lookAt));
    var x = normalize(cross(up, z));
    var y = cross(z, x);
    /* eslint-disable prettier/prettier */
    return [
        x.x, x.y, x.z, 0,
        y.x, y.y, y.z, 0,
        z.x, z.y, z.z, 0,
        position.x, position.y, position.z, 1
    ];
    /* eslint-enable prettier/prettier */
}
/**
 * Returns the inverse of the given matrix. If the determinate of the matrix is
 * zero, then a zero matrix is returned.
 */
function invert(matrix) {
    var a00 = matrix[0], a01 = matrix[1], a02 = matrix[2], a03 = matrix[3];
    var a10 = matrix[4], a11 = matrix[5], a12 = matrix[6], a13 = matrix[7];
    var a20 = matrix[8], a21 = matrix[9], a22 = matrix[10], a23 = matrix[11];
    var a30 = matrix[12], a31 = matrix[13], a32 = matrix[14], a33 = matrix[15];
    var b00 = a00 * a11 - a01 * a10;
    var b01 = a00 * a12 - a02 * a10;
    var b02 = a00 * a13 - a03 * a10;
    var b03 = a01 * a12 - a02 * a11;
    var b04 = a01 * a13 - a03 * a11;
    var b05 = a02 * a13 - a03 * a12;
    var b06 = a20 * a31 - a21 * a30;
    var b07 = a20 * a32 - a22 * a30;
    var b08 = a20 * a33 - a23 * a30;
    var b09 = a21 * a32 - a22 * a31;
    var b10 = a21 * a33 - a23 * a31;
    var b11 = a22 * a33 - a23 * a32;
    // Calculate the determinant
    var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
    if (!det) {
        return makeZero();
    }
    det = 1.0 / det;
    return [
        (a11 * b11 - a12 * b10 + a13 * b09) * det,
        (a02 * b10 - a01 * b11 - a03 * b09) * det,
        (a31 * b05 - a32 * b04 + a33 * b03) * det,
        (a22 * b04 - a21 * b05 - a23 * b03) * det,
        (a12 * b08 - a10 * b11 - a13 * b07) * det,
        (a00 * b11 - a02 * b08 + a03 * b07) * det,
        (a32 * b02 - a30 * b05 - a33 * b01) * det,
        (a20 * b05 - a22 * b02 + a23 * b01) * det,
        (a10 * b10 - a11 * b08 + a13 * b06) * det,
        (a01 * b08 - a00 * b10 - a03 * b06) * det,
        (a30 * b04 - a31 * b02 + a33 * b00) * det,
        (a21 * b02 - a20 * b04 - a23 * b00) * det,
        (a11 * b07 - a10 * b09 - a12 * b06) * det,
        (a00 * b09 - a01 * b07 + a02 * b06) * det,
        (a31 * b01 - a30 * b03 - a32 * b00) * det,
        (a20 * b03 - a21 * b01 + a22 * b00) * det,
    ];
}
/**
 * Returns a rotation matrix looking from position towards target and oriented
 * by an up vector.
 *
 * @param m The matrix to transform.
 * @param position The point from which to look at target.
 * @param target The point to look at.
 * @param up The orientation.
 * @returns A rotation matrix.
 */
function lookAt(m, position, target, up) {
    var z = subtract(position, target);
    if (magnitudeSquared(z) === 0) {
        z = exports.__assign(exports.__assign({}, z), { z: 1 });
    }
    z = normalize(z);
    var x = cross(up, z);
    if (magnitudeSquared(x) === 0) {
        if (Math.abs(up.z) === 1) {
            z = exports.__assign(exports.__assign({}, z), { x: z.x + 0.0001 });
        }
        else {
            z = exports.__assign(exports.__assign({}, z), { z: z.z + 0.0001 });
        }
        z = normalize(z);
        x = cross(up, z);
    }
    x = normalize(x);
    var y = cross(z, x);
    var res = __spreadArray([], m, true);
    /* eslint-disable prettier/prettier */
    res[0] = x.x;
    res[4] = y.x;
    res[8] = z.x;
    res[1] = x.y;
    res[5] = y.y;
    res[9] = z.y;
    res[2] = x.z;
    res[6] = y.z;
    res[10] = z.z;
    /* eslint-enable prettier/prettier */
    return res;
}
/**
 * Returns a post-multiplied matrix.
 */
function multiply$2(a, b) {
    var ae = a;
    var be = b;
    var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
    var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
    var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
    var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
    var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
    var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
    var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
    var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
    var mat = makeIdentity();
    mat[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
    mat[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
    mat[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
    mat[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
    mat[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
    mat[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
    mat[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
    mat[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
    mat[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
    mat[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
    mat[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
    mat[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
    mat[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
    mat[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
    mat[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
    mat[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
    return mat;
}
/**
 * Returns the [transpose](https://en.wikipedia.org/wiki/Transpose) of the given
 * matrix.
 */
function transpose(matrix) {
    /* eslint-disable prettier/prettier */
    return [
        matrix[0], matrix[4], matrix[8], matrix[12],
        matrix[1], matrix[5], matrix[9], matrix[13],
        matrix[2], matrix[6], matrix[10], matrix[14],
        matrix[3], matrix[7], matrix[11], matrix[15],
    ];
    /* eslint-enable prettier/prettier */
}
/**
 * Multiplies the columns of a matrix by the given vector.
 */
function scale$4(matrix, scale) {
    var x = scale.x, y = scale.y, z = scale.z;
    var m = __spreadArray([], matrix, true);
    /* eslint-disable prettier/prettier */
    m[0] *= x;
    m[4] *= y;
    m[8] *= z;
    m[1] *= x;
    m[5] *= y;
    m[9] *= z;
    m[2] *= x;
    m[6] *= y;
    m[10] *= z;
    m[3] *= x;
    m[7] *= y;
    m[11] *= z;
    /* eslint-enable prettier/prettier */
    return m;
}
function position(matrix, other) {
    var m = __spreadArray([], matrix, true);
    m[12] = other[12];
    m[13] = other[13];
    m[14] = other[14];
    return m;
}
/**
 * Returns true if the matrix is an identity matrix.
 */
function isIdentity(matrix) {
    var identity = makeIdentity();
    return matrix.every(function (v, i) { return v === identity[i]; });
}
/**
 * Returns an object representation of a `Matrix4`.
 */
function toObject(m) {
    /* eslint-disable prettier/prettier */
    return {
        m11: m[0], m12: m[4], m13: m[8], m14: m[12],
        m21: m[1], m22: m[5], m23: m[9], m24: m[13],
        m31: m[2], m32: m[6], m33: m[10], m34: m[14],
        m41: m[3], m42: m[7], m43: m[11], m44: m[15],
    };
    /* eslint-enable prettier/prettier */
}
/**
 * A type guard to check if `obj` is of type `Matrix4`.
 */
function isType$2(obj) {
    return Array.isArray(obj) && obj.length === 16;
}

var matrix4 = /*#__PURE__*/Object.freeze({
  __proto__: null,
  fromValues: fromValues,
  fromObject: fromObject,
  makeIdentity: makeIdentity,
  makeZero: makeZero,
  makeTranslation: makeTranslation,
  makeRotation: makeRotation,
  makeScale: makeScale,
  makeTRS: makeTRS,
  makeBasis: makeBasis,
  makeRotationAxis: makeRotationAxis,
  makeFrustum: makeFrustum,
  makePerspective: makePerspective,
  makeOrthographic: makeOrthographic,
  makeLookAtView: makeLookAtView,
  makeLookAt: makeLookAt,
  invert: invert,
  lookAt: lookAt,
  multiply: multiply$2,
  transpose: transpose,
  scale: scale$4,
  position: position,
  isIdentity: isIdentity,
  toObject: toObject,
  isType: isType$2
});

/**
 * Creates a new set of Euler angles where each axis of rotation is defined by an angle,
 * in radians. If no value is given, then `{x: 0, y: 0, z: 0, order: 'xyz'}` is
 * returned.
 *
 * @param value The values to populate the Euler angles with.
 * @returns A set of Euler angles.
 */
function create$c(value) {
    var _a, _b, _c, _d;
    if (value === void 0) { value = {}; }
    return {
        x: (_a = value.x) !== null && _a !== void 0 ? _a : 0,
        y: (_b = value.y) !== null && _b !== void 0 ? _b : 0,
        z: (_c = value.z) !== null && _c !== void 0 ? _c : 0,
        order: (_d = value.order) !== null && _d !== void 0 ? _d : 'xyz',
    };
}
/**
 * Creates a new set of Euler angles where each axis of rotation is defined by an angle,
 * in degrees. If no value is given, then `{x: 0, y: 0, z: 0, order: 'xyz'}` is
 * returned.
 *
 * @param value The values to populate the Euler angles with.
 * @returns A set of Euler angles.
 */
function fromDegrees(value) {
    if (value === void 0) { value = {}; }
    var _a = value.x, x = _a === void 0 ? 0 : _a, _b = value.y, y = _b === void 0 ? 0 : _b, _c = value.z, z = _c === void 0 ? 0 : _c, order = value.order;
    return create$c({
        x: toRadians(x),
        y: toRadians(y),
        z: toRadians(z),
        order: order,
    });
}
/**
 * Creates a set of Euler angles from the rotation components of a 4x4 matrix. The
 * rotation components are represented by the upper 3x3 of the matrix.
 *
 * Note that there are two solutions for the Euler angle of the 2nd applied
 * rotation (i.e. y for xyz) because sin(theta) = sin(PI-theta).
 * The returned angle will always be the solution between -PI/2 and PI/2.
 *
 * @param matrix A pure rotation matrix, unscaled.
 * @param order The order that the rotations are applied.
 */
function fromRotationMatrix(matrix, order) {
    if (order === void 0) { order = 'xyz'; }
    var m = toObject(matrix);
    var x = 0, y = 0, z = 0;
    if (order === 'xyz') {
        y = Math.asin(clamp(m.m13, -1, 1));
        if (Math.abs(m.m13) < 0.9999999) {
            x = Math.atan2(-m.m23, m.m33);
            z = Math.atan2(-m.m12, m.m11);
        }
        else {
            x = Math.atan2(m.m32, m.m22);
            z = 0;
        }
    }
    else if (order === 'yxz') {
        x = Math.asin(-clamp(m.m23, -1, 1));
        if (Math.abs(m.m23) < 0.9999999) {
            y = Math.atan2(m.m13, m.m33);
            z = Math.atan2(m.m21, m.m22);
        }
        else {
            y = Math.atan2(-m.m31, m.m11);
            z = 0;
        }
    }
    else if (order === 'zxy') {
        x = Math.asin(clamp(m.m32, -1, 1));
        if (Math.abs(m.m32) < 0.9999999) {
            y = Math.atan2(-m.m31, m.m33);
            z = Math.atan2(-m.m12, m.m22);
        }
        else {
            y = 0;
            z = Math.atan2(m.m21, m.m11);
        }
    }
    else if (order === 'zyx') {
        y = Math.asin(-clamp(m.m31, -1, 1));
        if (Math.abs(m.m31) < 0.9999999) {
            x = Math.atan2(m.m32, m.m33);
            z = Math.atan2(m.m21, m.m11);
        }
        else {
            x = 0;
            z = Math.atan2(-m.m12, m.m22);
        }
    }
    else if (order === 'yzx') {
        z = Math.asin(clamp(m.m21, -1, 1));
        if (Math.abs(m.m21) < 0.9999999) {
            x = Math.atan2(-m.m23, m.m22);
            y = Math.atan2(-m.m31, m.m11);
        }
        else {
            x = 0;
            y = Math.atan2(m.m13, m.m33);
        }
    }
    else if (order === 'xzy') {
        z = Math.asin(-clamp(m.m12, -1, 1));
        if (Math.abs(m.m12) < 0.9999999) {
            x = Math.atan2(m.m32, m.m22);
            y = Math.atan2(m.m13, m.m11);
        }
        else {
            x = Math.atan2(-m.m23, m.m33);
            y = 0;
        }
    }
    return { x: x, y: y, z: z, order: order };
}
/**
 * Returns a set of Euler angles that was decoded from a JSON string. Supports either
 * extracting values from an array `[x, y, z, order]` or object `{x, y, z,
 * order}`.
 *
 * @param json A JSON object.
 * @returns A set of Euler angles.
 */
function fromJson$4(json) {
    var obj = JSON.parse(json);
    if (Array.isArray(obj)) {
        var x = obj[0], y = obj[1], z = obj[2], _a = obj[3], order = _a === void 0 ? 'xyz' : _a;
        return { x: x, y: y, z: z, order: order };
    }
    else {
        var x = obj.x, y = obj.y, z = obj.z, _b = obj.order, order = _b === void 0 ? 'xyz' : _b;
        return { x: x, y: y, z: z, order: order };
    }
}
/**
 * Type guard that checks if the given type is a set of Euler angles.
 */
function isType$1(obj) {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    var o = obj;
    return (o != null &&
        o.hasOwnProperty('x') &&
        o.hasOwnProperty('y') &&
        o.hasOwnProperty('z') &&
        o.hasOwnProperty('order'));
}

var euler = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create$c,
  fromDegrees: fromDegrees,
  fromRotationMatrix: fromRotationMatrix,
  fromJson: fromJson$4,
  isType: isType$1
});

/**
 * Returns a new quaternion. If `value` is undefined, then `{x: 0, y: 0, z: 0,
 * w: 1}` is returned.
 */
function create$b(value) {
    if (value === void 0) { value = {}; }
    return exports.__assign({ x: 0, y: 0, z: 0, w: 1 }, value);
}
/**
 * Parses a JSON string representation of a `Quaternion`.
 *
 * @param json A JSON string either in the form of `[x, y, z, w]` or `{"x": 0, "y": 0, "z": 0, "w": 0}`.
 * @returns A parsed `Quaternion`.
 */
function fromJson$3(json) {
    var obj = JSON.parse(json);
    if (Array.isArray(obj)) {
        var x = obj[0], y = obj[1], z = obj[2], w = obj[3];
        return create$b({ x: x, y: y, z: z, w: w });
    }
    else {
        return create$b(obj);
    }
}
/**
 * Returns a quaternion with that will have a magnitude of 1.
 */
function normalize$1(q) {
    return scale$3(1 / magnitude$1(q), q);
}
/**
 * Returns the magnitude of the provided quaternion.
 */
function magnitude$1(q) {
    return Math.sqrt(q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z);
}
/**
 * Returns a quaternion where each component is multiplied by the `scalar`.
 */
function scale$3(scalar, q) {
    return create$b({
        w: q.w * scalar,
        x: q.x * scalar,
        y: q.y * scalar,
        z: q.z * scalar,
    });
}
/**
 * Creates a `Quaternion` that is rotated the given radians around an axis.
 *
 * @param axis The axis to rotate around.
 * @param radians The rotation, in radians.
 * @returns A rotated quaternion.
 */
function fromAxisAngle(axis, radians) {
    var halfAngle = radians / 2;
    var s = Math.sin(halfAngle);
    var x = axis.x * s;
    var y = axis.y * s;
    var z = axis.z * s;
    var w = Math.cos(halfAngle);
    return { x: x, y: y, z: z, w: w };
}
/**
 * Returns a quaternion using the upper 3x3 of a pure rotation matrix
 * (unscaled).
 */
function fromMatrixRotation(matrix) {
    var m = toObject(matrix);
    var scale = fromMatrixScale(matrix);
    var is1 = 1 / scale.x;
    var is2 = 1 / scale.y;
    var is3 = 1 / scale.z;
    var sm11 = m.m11 * is1;
    var sm12 = m.m21 * is2;
    var sm13 = m.m31 * is3;
    var sm21 = m.m12 * is1;
    var sm22 = m.m22 * is2;
    var sm23 = m.m32 * is3;
    var sm31 = m.m13 * is1;
    var sm32 = m.m23 * is2;
    var sm33 = m.m33 * is3;
    var trace = sm11 + sm22 + sm33;
    if (trace > 0) {
        var s = Math.sqrt(trace + 1.0) * 2;
        return {
            x: (sm23 - sm32) / s,
            y: (sm31 - sm13) / s,
            z: (sm12 - sm21) / s,
            w: 0.25 * s,
        };
    }
    else if (sm11 > sm22 && sm11 > sm33) {
        var s = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
        return {
            x: 0.25 * s,
            y: (sm12 + sm21) / s,
            z: (sm31 + sm13) / s,
            w: (sm23 - sm32) / s,
        };
    }
    else if (sm22 > sm33) {
        var s = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
        return {
            x: (sm12 + sm21) / s,
            y: 0.25 * s,
            z: (sm23 + sm32) / s,
            w: (sm31 - sm13) / s,
        };
    }
    else {
        var s = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
        return {
            x: (sm31 + sm13) / s,
            y: (sm23 + sm32) / s,
            z: 0.25 * s,
            w: (sm12 - sm21) / s,
        };
    }
}
function fromEuler(euler) {
    var ex = euler.x, ey = euler.y, ez = euler.z, order = euler.order;
    var c1 = Math.cos(ex / 2);
    var c2 = Math.cos(ey / 2);
    var c3 = Math.cos(ez / 2);
    var s1 = Math.sin(ex / 2);
    var s2 = Math.sin(ey / 2);
    var s3 = Math.sin(ez / 2);
    var x = 0, y = 0, z = 0, w = 0;
    switch (order) {
        case 'xyz':
            x = s1 * c2 * c3 + c1 * s2 * s3;
            y = c1 * s2 * c3 - s1 * c2 * s3;
            z = c1 * c2 * s3 + s1 * s2 * c3;
            w = c1 * c2 * c3 - s1 * s2 * s3;
            break;
        case 'yxz':
            x = s1 * c2 * c3 + c1 * s2 * s3;
            y = c1 * s2 * c3 - s1 * c2 * s3;
            z = c1 * c2 * s3 - s1 * s2 * c3;
            w = c1 * c2 * c3 + s1 * s2 * s3;
            break;
        case 'zxy':
            x = s1 * c2 * c3 - c1 * s2 * s3;
            y = c1 * s2 * c3 + s1 * c2 * s3;
            z = c1 * c2 * s3 + s1 * s2 * c3;
            w = c1 * c2 * c3 - s1 * s2 * s3;
            break;
        case 'zyx':
            x = s1 * c2 * c3 - c1 * s2 * s3;
            y = c1 * s2 * c3 + s1 * c2 * s3;
            z = c1 * c2 * s3 - s1 * s2 * c3;
            w = c1 * c2 * c3 + s1 * s2 * s3;
            break;
        case 'yzx':
            x = s1 * c2 * c3 + c1 * s2 * s3;
            y = c1 * s2 * c3 + s1 * c2 * s3;
            z = c1 * c2 * s3 - s1 * s2 * c3;
            w = c1 * c2 * c3 - s1 * s2 * s3;
            break;
        case 'xzy':
            x = s1 * c2 * c3 - c1 * s2 * s3;
            y = c1 * s2 * c3 - s1 * c2 * s3;
            z = c1 * c2 * s3 + s1 * s2 * c3;
            w = c1 * c2 * c3 + s1 * s2 * s3;
            break;
    }
    return { x: x, y: y, z: z, w: w };
}
/**
 * Multiplies `a` x `b` and returns a new quaternion with the result.
 */
function multiply$1(a, b) {
    // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
    return {
        x: a.x * b.w + a.w * b.x + a.y * b.z - a.z * b.y,
        y: a.y * b.w + a.w * b.y + a.z * b.x - a.x * b.z,
        z: a.z * b.w + a.w * b.z + a.x * b.y - a.y * b.x,
        w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z,
    };
}
/**
 * Type guard that checks if the given type is a Quaternion.
 */
function isType(obj) {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    var o = obj;
    return (o != null &&
        o.hasOwnProperty('x') &&
        o.hasOwnProperty('y') &&
        o.hasOwnProperty('z') &&
        o.hasOwnProperty('w'));
}

var quaternion = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create$b,
  fromJson: fromJson$3,
  normalize: normalize$1,
  magnitude: magnitude$1,
  scale: scale$3,
  fromAxisAngle: fromAxisAngle,
  fromMatrixRotation: fromMatrixRotation,
  fromEuler: fromEuler,
  multiply: multiply$1,
  isType: isType
});

function create$a() {
    var _a, _b, _c, _d, _e, _f;
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    if (args.length === 1) {
        return {
            x: (_a = args[0].x) !== null && _a !== void 0 ? _a : 0,
            y: (_b = args[0].y) !== null && _b !== void 0 ? _b : 0,
            z: (_c = args[0].z) !== null && _c !== void 0 ? _c : 0,
        };
    }
    else if (args.length === 3) {
        return {
            x: (_d = args[0]) !== null && _d !== void 0 ? _d : 0,
            y: (_e = args[1]) !== null && _e !== void 0 ? _e : 0,
            z: (_f = args[2]) !== null && _f !== void 0 ? _f : 0,
        };
    }
    return {
        x: 0,
        y: 0,
        z: 0,
    };
}
/* eslint-enable @typescript-eslint/no-explicit-any */
/* eslint-enable padding-line-between-statements */
/**
 * Checks if each component of the given vector is populated with a numeric
 * component. A component is invalid if it contains a non-finite or NaN value.
 */
function isValid$1(_a) {
    var x = _a.x, y = _a.y, z = _a.z;
    return [x, y, z].every(function (v) { return isFinite(v) && !isNaN(v); });
}
/**
 * Returns a vector representing the scale elements of `matrix`.
 */
function fromMatrixScale(matrix) {
    var m = toObject(matrix);
    return {
        x: Math.hypot(m.m11, m.m21, m.m31),
        y: Math.hypot(m.m12, m.m22, m.m32),
        z: Math.hypot(m.m13, m.m23, m.m33),
    };
}
/**
 * Returns a vector representing the position elements of `matrix`.
 */
function fromMatrixPosition(matrix) {
    var m = toObject(matrix);
    return { x: m.m14, y: m.m24, z: m.m34 };
}
/**
 * Parses a JSON string representation of a Vector3 and returns an object.
 *
 * @param json A JSON string, either in the form `[x,y,z]` or `{"x": 0, "y": 0, "z": 0}`
 * @returns A parsed Vector3.
 */
function fromJson$2(json) {
    var obj = JSON.parse(json);
    if (Array.isArray(obj)) {
        var x = obj[0], y = obj[1], z = obj[2];
        return create$a(x, y, z);
    }
    else {
        var x = obj.x, y = obj.y, z = obj.z;
        return create$a(x, y, z);
    }
}
/**
 * Creates a `Vector3` from an array. Pass `offset` to read values from the
 * starting index.
 *
 * @see #toArray()
 * @see #create()
 */
function fromArray(nums, offset) {
    if (offset === void 0) { offset = 0; }
    var x = nums[offset];
    var y = nums[offset + 1];
    var z = nums[offset + 2];
    return create$a(x, y, z);
}
/**
 * Converts a Vector3 to an array where the values of the vector will be
 * represented as [x, y, z];
 *
 * @see #fromArray()
 * @see #create()
 */
function toArray(_a) {
    var x = _a.x, y = _a.y, z = _a.z;
    return [x, y, z];
}
/**
 * Returns a directional vector on the positive x axis, Vector3(1, 0, 0).
 */
function right() {
    return create$a(1, 0, 0);
}
/**
 * Returns a directional vector on the positive y axis, Vector3(0, 1, 0).
 */
function up() {
    return create$a(0, 1, 0);
}
/**
 * Returns a directional vector on the positive z axis, Vector3(0, 0, -1).
 */
function forward() {
    return create$a(0, 0, -1);
}
/**
 * Returns a directional vector on the negative x axis, Vector3(-1, 0, 0).
 */
function left() {
    return create$a(-1, 0, 0);
}
/**
 * Returns a directional vector on the negative y axis, Vector3(0, -1, 0).
 */
function down() {
    return create$a(0, -1, 0);
}
/**
 * Returns a directional vector on the negative z axis, Vector3(0, 0, 1).
 */
function back() {
    return create$a(0, 0, 1);
}
/**
 * Returns a vector at the origin, Vector3(0, 0, 0).
 */
function origin() {
    return create$a(0, 0, 0);
}
/**
 * Returns a vector with that will have a magnitude of 1.
 */
function normalize(vector) {
    var length = magnitude(vector);
    return { x: vector.x / length, y: vector.y / length, z: vector.z / length };
}
/**
 * Returns the straight-line length from (0, 0, 0) to the given vector.
 */
function magnitude(vector) {
    return Math.sqrt(magnitudeSquared(vector));
}
/**
 * Returns the straight-line length from (0, 0, 0) to the given vector).
 *
 * When comparing lengths of vectors, you should use this function as it's
 * slightly more efficient to calculate.
 */
function magnitudeSquared(vector) {
    return vector.x * vector.x + vector.y * vector.y + vector.z * vector.z;
}
/**
 * Returns a vector that is the cross product of two vectors.
 *
 * The cross product of two vectors results in a third vector which is
 * perpendicular to the two input vectors. The result's magnitude is equal to
 * the magnitudes of the two inputs multiplied together and then multiplied by
 * the sine of the angle between the inputs. You can determine the direction of
 * the result vector using the "left hand rule".
 */
function cross(a, b) {
    return {
        x: a.y * b.z - a.z * b.y,
        y: a.z * b.x - a.x * b.z,
        z: a.x * b.y - a.y * b.x,
    };
}
/**
 * Returns a vector that is the sum of two vectors.
 */
function add(a) {
    var vectors = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        vectors[_i - 1] = arguments[_i];
    }
    return vectors.reduce(function (res, next) {
        return { x: res.x + next.x, y: res.y + next.y, z: res.z + next.z };
    }, a);
}
/**
 * Returns a vector that is the difference between two vectors.
 */
function subtract(a) {
    var vectors = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        vectors[_i - 1] = arguments[_i];
    }
    return vectors.reduce(function (res, next) {
        return { x: res.x - next.x, y: res.y - next.y, z: res.z - next.z };
    }, a);
}
/**
 * Returns a vector that where each component of `b` is multiplied with `a`.
 */
function multiply(a, b) {
    return { x: a.x * b.x, y: a.y * b.y, z: a.z * b.z };
}
/**
 * Returns a vector where each value of a vector is multiplied by the `scalar`.
 */
function scale$2(scalar, vector) {
    return { x: vector.x * scalar, y: vector.y * scalar, z: vector.z * scalar };
}
/**
 * Returns a value representing the dot product of two vectors.
 *
 * The dot product is a float value equal to the magnitudes of the two vectors
 * multiplied together and then multiplied by the cosine of the angle between
 * them.
 */
function dot$1(a, b) {
    return a.x * b.x + a.y * b.y + a.z * b.z;
}
/**
 * Returns the angle, in radians, between two vectors.
 *
 * The angle returned is the unsigned angle between the two vectors. This means
 * the smaller of the two possible angles between the two vectors is used. The
 * result is never greater than 180 degrees.
 */
function angleTo(a, b) {
    var theta = dot$1(a, b) / (magnitude(a) * magnitude(b));
    // Clamp to avoid numerical problems.
    return Math.acos(theta);
}
/**
 * Returns the Euler angle, in radians with the `xyz` ordering, between two vectors.
 *
 * This method will normalize both vectors for the calculation, and uses the
 * algorithm described in https://www.xarg.org/proof/quaternion-from-two-vectors/.
 */
function eulerTo(a, b) {
    var normalizedA = normalize(a);
    var normalizedB = normalize(b);
    var dotDelta = Math.cos(toRadians(1));
    var dotAB = dot$1(normalizedA, normalizedB);
    var vectorsAreParallel = Math.abs(dotAB) > dotDelta;
    if (vectorsAreParallel) {
        return dotAB > 1 - 1e-6 ? create$c() : create$c({ x: Math.PI });
    }
    var normalizedQ = normalize$1(create$b(exports.__assign({ w: 1 + dotAB }, cross(normalizedA, normalizedB))));
    return fromRotationMatrix(makeRotation(normalizedQ));
}
/**
 * Performs a projection of a `vector` onto `onNormal`.
 *
 * A projection is represented as the nearest point along a normal to a vector,
 * which constructs a triangle from the origin, to the vector, to the projected
 * point.
 *
 * ```
 * Vector -->  *   * <-- Projected
 *              \
 *               \ | <-- Normal
 *                \|
 *                 * <-- Origin
 * ```
 */
function project(vector, onNormal) {
    return scale$2(dot$1(onNormal, vector) / magnitude(onNormal), onNormal);
}
/**
 * Returns a vector that is rotated about an origin point.
 *
 * @param angle The angle to rotate, in radians.
 * @param point The origin point to rotate around.
 * @param axisDirection The direction used to compute the axis.
 * @param axisPosition The point of the axis.
 */
function rotateAboutAxis(angle, point, axisDirection, axisPosition) {
    if (angle !== 0) {
        var x = point.x, y = point.y, z = point.z;
        var a = axisPosition.x, b = axisPosition.y, c = axisPosition.z;
        var u = axisDirection.x, v = axisDirection.y, w = axisDirection.z;
        var newX = (a * (v * v + w * w) - u * (b * v + c * w - u * x - v * y - w * z)) *
            (1 - Math.cos(angle)) +
            x * Math.cos(angle) +
            (-c * v + b * w - w * y + v * z) * Math.sin(angle);
        var newY = (b * (u * u + w * w) - v * (a * u + c * w - u * x - v * y - w * z)) *
            (1 - Math.cos(angle)) +
            y * Math.cos(angle) +
            (c * u - a * w + w * x - u * z) * Math.sin(angle);
        var newZ = (c * (u * u + v * v) - w * (a * u + b * v - u * x - v * y - w * z)) *
            (1 - Math.cos(angle)) +
            z * Math.cos(angle) +
            (-b * u + a * v - v * x + u * y) * Math.sin(angle);
        return { x: newX, y: newY, z: newZ };
    }
    else {
        return point;
    }
}
/**
 * Returns a vector that is multiplied with a matrix.
 */
function transformMatrix$1(vector, m) {
    var x = vector.x, y = vector.y, z = vector.z;
    var w = 1 / (m[3] * x + m[7] * y + m[11] * z + m[15]);
    return {
        x: (m[0] * x + m[4] * y + m[8] * z + m[12]) * w,
        y: (m[1] * x + m[5] * y + m[9] * z + m[13]) * w,
        z: (m[2] * x + m[6] * y + m[10] * z + m[14]) * w,
    };
}
/**
 * Euclidean distance between two vectors
 */
function distance$1(a, b) {
    return Math.sqrt(distanceSquared$1(a, b));
}
/**
 * Returns the squared distance between two vectors. If you're just comparing
 * distances, this is slightly more efficient than `distanceTo`.
 */
function distanceSquared$1(a, b) {
    var _a = subtract(a, b), dx = _a.x, dy = _a.y, dz = _a.z;
    return dx * dx + dy * dy + dz * dz;
}
/**
 * Returns `true` if two vectors have the same values.
 */
function isEqual$2(a, b) {
    return a.x === b.x && a.y === b.y && a.z === b.z;
}
/**
 * Returns a vector that contains the largest components of `a` and `b`.
 */
function max(a, b) {
    return create$a(Math.max(a.x, b.x), Math.max(a.y, b.y), Math.max(a.z, b.z));
}
/**
 * Returns a vector that contains the smallest components of `a` and `b`.
 */
function min(a, b) {
    return create$a(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z));
}
/**
 * Returns a vector that each of its component negated.
 */
function negate(vector) {
    return { x: -vector.x, y: -vector.y, z: -vector.z };
}
/**
 * Performs a linear interpolation between `a` and `b` and returns the result.
 * The value of `t` is clamped between `[0, 1]`.
 *
 * @param a The start value.
 * @param b The end value.
 * @param t A value between 0 and 1.
 * @returns A point between `a` and `b`.
 */
function lerp(a, b, t) {
    return {
        x: lerp$2(a.x, b.x, t),
        y: lerp$2(a.y, b.y, t),
        z: lerp$2(a.z, b.z, t),
    };
}
/**
 * Maps a normalized device coordinate (NDC) space to world space coordinates.
 *
 * @param ndc A point in normalized device coordinates.
 * @param worldMatrix A camera's world matrix.
 * @param projectionMatrixInverse A camera's inverse projection matrix.
 * @returns A point in world space coordinates.
 */
function transformNdcToWorldSpace(ndc, worldMatrix, projectionMatrixInverse) {
    return transformMatrix$1(transformMatrix$1(ndc, projectionMatrixInverse), worldMatrix);
}

var vector3 = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create$a,
  isValid: isValid$1,
  fromMatrixScale: fromMatrixScale,
  fromMatrixPosition: fromMatrixPosition,
  fromJson: fromJson$2,
  fromArray: fromArray,
  toArray: toArray,
  right: right,
  up: up,
  forward: forward,
  left: left,
  down: down,
  back: back,
  origin: origin,
  normalize: normalize,
  magnitude: magnitude,
  magnitudeSquared: magnitudeSquared,
  cross: cross,
  add: add,
  subtract: subtract,
  multiply: multiply,
  scale: scale$2,
  dot: dot$1,
  angleTo: angleTo,
  eulerTo: eulerTo,
  project: project,
  rotateAboutAxis: rotateAboutAxis,
  transformMatrix: transformMatrix$1,
  distance: distance$1,
  distanceSquared: distanceSquared$1,
  isEqual: isEqual$2,
  max: max,
  min: min,
  negate: negate,
  lerp: lerp,
  transformNdcToWorldSpace: transformNdcToWorldSpace
});

/**
 * Returns a `BoundingBox` with the given min and max points.
 */
var create$9 = function (min, max) {
    return { min: min, max: max };
};
/**
 * Construct a minimal bounding box for a set of vectors, such that all vectors
 * are contained by the bounding box.
 */
var fromVectors = function (vectors) {
    return union.apply(void 0, vectors.map(function (v) { return create$9(v, v); }));
};
/**
 * Returns the center point of the given `BoundingBox`.
 */
var center$3 = function (boundingBox) {
    return scale$2(0.5, add(boundingBox.min, boundingBox.max));
};
/**
 * Returns the diagonal vector between the `min` and `max` vectors of the
 * given `BoundingBox`.
 */
var diagonal = function (boundingBox) {
    return subtract(boundingBox.max, boundingBox.min);
};
/**
 * Returns a floating-point spatial error tolerance based on the extents of the box.
 */
var epsilon = function (boundingBox) {
    return (Math.max(Math.max(magnitude(boundingBox.max), magnitude(boundingBox.min)), magnitude(diagonal(boundingBox))) * 1e-6);
};
function union(box) {
    var rest = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        rest[_i - 1] = arguments[_i];
    }
    var boxes = __spreadArray([box], rest, true);
    return boxes.reduce(function (a, b) {
        return create$9(min(a.min, b.min), max(a.max, b.max));
    });
}
/* eslint-enable padding-line-between-statements */
/**
 * Returns the distance between the min and max for the provided
 * bounding box for each axis.
 */
var lengths = function (box) {
    return create$a(box.max.x - box.min.x, box.max.y - box.min.y, box.max.z - box.min.z);
};
/**
 * Checks if each component of the given bounding box is populated with a numeric
 * component. A component is invalid if it contains a non-finite or NaN value.
 */
function isValid(boundingBox) {
    var maxIsValid = isValid$1(boundingBox.max);
    var minIsValid = isValid$1(boundingBox.min);
    return maxIsValid && minIsValid;
}

var boundingBox = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create$9,
  fromVectors: fromVectors,
  center: center$3,
  diagonal: diagonal,
  epsilon: epsilon,
  union: union,
  lengths: lengths,
  isValid: isValid
});

/**
 * Returns a `BoundingSphere` that encompasses the provided `BoundingBox`.
 */
var create$8 = function (boundingBox$1) {
    var boundingBoxCenter = center$3(boundingBox$1);
    var centerToBoundingPlane = subtract(boundingBox$1.max, boundingBoxCenter);
    var radius = magnitude(centerToBoundingPlane);
    var length = Math.max(radius, magnitude(boundingBoxCenter));
    var epsilon = length === 0 ? 1.0 : length * 1e-6;
    return { center: boundingBoxCenter, radius: radius, epsilon: epsilon };
};

var boundingSphere = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create$8
});

/**
 * Returns a new `Rectangle` with the given position and size.
 */
function create$7(x, y, width, height) {
    return { x: x, y: y, width: width, height: height };
}
/**
 * Returns a new `Rectangle` at the origin point and given size.
 */
function fromDimensions(dimensions) {
    return create$7(0, 0, dimensions.width, dimensions.height);
}
/**
 * Returns a new `Rectangle` with the given position and size.
 */
function fromPointAndDimensions(point, dimensions) {
    return create$7(point.x, point.y, dimensions.width, dimensions.height);
}
/**
 * Returns a new `Rectangle` with the given top-left and bottom-right positions.
 * The returned rectangle will always returns a positive width and height.
 */
function fromPoints(topLeftPt, bottomRightPt) {
    var minX = Math.min(topLeftPt.x, bottomRightPt.x);
    var minY = Math.min(topLeftPt.y, bottomRightPt.y);
    var maxX = Math.max(topLeftPt.x, bottomRightPt.x);
    var maxY = Math.max(topLeftPt.y, bottomRightPt.y);
    return create$7(minX, minY, maxX - minX, maxY - minY);
}
/**
 * Returns a rectangle where the longest length of `rect` will be equal to the
 * shortest length of `to`. The shortest length of `rect` will be proportionally
 * scaled to match the aspect ratio of `rect`. The returned rectangle will be
 * centered within `to`.
 *
 * @see {@link cropFit}
 */
function containFit$1(to, rect) {
    var scale = Math.min(to.width / rect.width, to.height / rect.height);
    var dimensions$1 = proportionalScale(scale, rect);
    var position = subtract$1(center$2(to), center$1(dimensions$1));
    return fromPointAndDimensions(position, dimensions$1);
}
/**
 * Returns a rectangle where the shortest length of `rect` will be equal to the
 * longest length of `to`. The longest length of `rect` will be proportionally
 * scaled to match the aspect ratio of `rect`. The returned rectangle will be
 * centered within `to`.
 *
 * @see {@link containFit}
 */
function cropFit$1(to, rect) {
    var scale = Math.max(to.width / rect.width, to.height / rect.height);
    var dimensions$1 = proportionalScale(scale, rect);
    var position = subtract$1(center$2(to), center$1(dimensions$1));
    return fromPointAndDimensions(position, dimensions$1);
}
/**
 * Returns a rectangle where each side of `rect` will be reduced proportionally
 * to have an area less than or equal to the provided `to` value. The returned
 * rectangle will be centered within the original bounds of `rect`.
 *
 * @param to - the maximum area this rectangle can have
 * @param rect - the rectangle to scale to fit the specified area
 */
function scaleFit$1(to, rect) {
    var scale = Math.min(Math.sqrt(to / area$1(rect)), 1);
    var dimensions$1 = floor(proportionalScale(scale, rect));
    var position = subtract$1(center$2(rect), center$1(dimensions$1));
    return fromPointAndDimensions(position, dimensions$1);
}
/**
 * Returns a rectangle where the position and dimensions are scaled by the given
 * factors. If `scaleY` is omitted, then the position and dimensions are scaled
 * uniformly by `scaleOrScaleX`.
 *
 * @param rect The rectangle to scale.
 * @param scaleOrScaleX The uniform scale factor, or the horizontal scale
 *  factor.
 * @param scaleY The vertical scale factor.
 * @returns A scaled rectangle.
 */
function scale$1(rect, scaleOrScaleX, scaleY) {
    if (scaleY == null) {
        return scale$1(rect, scaleOrScaleX, scaleOrScaleX);
    }
    else {
        var x = rect.x, y = rect.y, width = rect.width, height = rect.height;
        var scaleX = scaleOrScaleX;
        return create$7(x * scaleX, y * scaleY, width * scaleX, height * scaleY);
    }
}
/**
 * Returns true if two rectangles are equal in position and size.
 */
function isEqual$1(a, b) {
    return isEqual$3(a, b) && isEqual(a, b);
}
/**
 * Returns a rectangle that has its position shifted by a given offset. The
 * size of the rectangle is unchanged.
 */
function offset(delta, rect) {
    return fromPointAndDimensions(add$1(topLeft(rect), delta), rect);
}
/**
 * Returns the area of the rectangle.
 */
function area$1(rect) {
    return rect.width * rect.height;
}
/**
 * Returns the center point of the rectangle.
 */
function center$2(rect) {
    return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 };
}
/**
 * Returns the top-left position of the rectangle, as a point.
 */
function topLeft(rect) {
    return create$d(rect.x, rect.y);
}
/**
 * Returns the bottom-right position of the rectangle, as a point.
 */
function bottomRight(rect) {
    return create$d(rect.x + rect.width, rect.y + rect.height);
}
/**
 * Returns `true` if the given rectangle has a portrait aspect ratio.
 */
function isPortrait(rect) {
    return rect.width < rect.height;
}
/**
 * Returns `true` if the given rectangle has a landscape aspect ratio.
 */
function isLandscape(rect) {
    return rect.width > rect.height;
}
/**
 * Returns `true` if the given rectangle has a square aspect ratio.
 */
function isSquare(rect) {
    return rect.width === rect.height;
}
/**
 * Pads a rectangle by the given amount, maintaining the center position.
 *
 * @param rect The rectangle to apply padding to.
 * @param padding The padding to add.
 */
function pad(rect, padding) {
    return create$7(rect.x - padding, rect.y - padding, rect.width + padding * 2, rect.height + padding * 2);
}
/**
 * Returns `true` if the given rectangle contains all the given `points`.
 *
 * @param rect The rectangle to check against.
 * @param points The points to check.
 */
function containsPoints(rect) {
    var points = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        points[_i - 1] = arguments[_i];
    }
    return points.every(function (point) {
        return (rect.x <= point.x &&
            rect.x + rect.width >= point.x &&
            rect.y <= point.y &&
            rect.y + rect.height >= point.y);
    });
}
/**
 * Parses a JSON string representation of a Rectangle and returns an object.
 *
 * @param json A JSON string, either in the form `[x,y,width,height]` or `{"x": 0, "y": 0, "width": 10, "height": 10}`
 * @returns A parsed Point.
 */
function fromJson$1(json) {
    var obj = JSON.parse(json);
    if (Array.isArray(obj)) {
        var x = obj[0], y = obj[1], width = obj[2], height = obj[3];
        return create$7(x, y, width, height);
    }
    else {
        var x = obj.x, y = obj.y, width = obj.width, height = obj.height;
        return create$7(x, y, width, height);
    }
}

var rectangle = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create$7,
  fromDimensions: fromDimensions,
  fromPointAndDimensions: fromPointAndDimensions,
  fromPoints: fromPoints,
  containFit: containFit$1,
  cropFit: cropFit$1,
  scaleFit: scaleFit$1,
  scale: scale$1,
  isEqual: isEqual$1,
  offset: offset,
  area: area$1,
  center: center$2,
  topLeft: topLeft,
  bottomRight: bottomRight,
  isPortrait: isPortrait,
  isLandscape: isLandscape,
  isSquare: isSquare,
  pad: pad,
  containsPoints: containsPoints,
  fromJson: fromJson$1
});

/**
 * Returns a `Dimensions` with the given width and height.
 *
 */
var create$6 = function (width, height) {
    return { width: width, height: height };
};
/**
 * Returns a `Dimensions` with the same width and height.
 */
var square = function (size) {
    return create$6(size, size);
};
/**
 * Returns `true` if two dimensions have the same width and height. Otherwise
 * `false`.
 */
var isEqual = function (a, b) {
    return a.width === b.width && a.height === b.height;
};
/**
 * Returns a scaled dimensions, where the width is scaled by `scaleX` and height
 * is scaled by `scaleY`.
 */
var scale = function (scaleX, scaleY, dimensions) {
    return {
        width: dimensions.width * scaleX,
        height: dimensions.height * scaleY,
    };
};
/**
 * Returns a dimension where each length is scaled by `scaleFactor`.
 */
var proportionalScale = function (scaleFactor, dimensions) {
    return scale(scaleFactor, scaleFactor, dimensions);
};
/**
 * Returns a `Dimensions` where the lengths of `dimensions` are trimmed to fit
 * into `to`.
 */
var trim = function (to, dimensions) {
    return {
        width: Math.min(to.width, dimensions.width),
        height: Math.min(to.height, dimensions.height),
    };
};
/**
 * Returns a `Dimensions` where the longest length of `dimensions` will be equal
 * to the shortest length of `to`. The shortest length of `dimensions` will be
 * proportionally scaled to match the aspect ratio of `dimensions`.
 *
 * @see #cropFit()
 */
var containFit = function (to, dimensions) {
    var _a = containFit$1(toRectangle(to), toRectangle(dimensions)), width = _a.width, height = _a.height;
    return { width: width, height: height };
};
/**
 * Returns a `Dimensions` where the shortest length of `dimensions` will be
 * equal to the longest length of `to`. The longest length of `dimensions` will
 * be proportionally scaled to match the aspect ratio of `dimensions`.
 *
 * @see #containFit()
 */
var cropFit = function (to, dimensions) {
    var _a = cropFit$1(toRectangle(to), toRectangle(dimensions)), width = _a.width, height = _a.height;
    return { width: width, height: height };
};
/**
 * Returns a `Dimensions` where each side of `dimensions` will be reduced proportionally
 * to have an area less than or equal to the provided `to` value. The returned
 * dimensions will be centered within the original bounds of `dimensions`.
 *
 * @param to - the maximum area this dimensions can have
 * @param dimensions - the dimensions to scale to fit the specified area
 */
var scaleFit = function (to, dimensions) {
    var _a = scaleFit$1(to, toRectangle(dimensions)), width = _a.width, height = _a.height;
    return { width: width, height: height };
};
/**
 * Returns a `Dimensions` with each length rounded.
 */
var round = function (dimensions) {
    return {
        width: Math.round(dimensions.width),
        height: Math.round(dimensions.height),
    };
};
/**
 * Returns a `Dimensions` with each length rounded down.
 */
var floor = function (dimensions) {
    return {
        width: Math.floor(dimensions.width),
        height: Math.floor(dimensions.height),
    };
};
/**
 * Returns the center point of the given `dimensions`.
 */
var center$1 = function (dimensions) {
    return { x: dimensions.width / 2, y: dimensions.height / 2 };
};
/**
 * Returns the aspect ratio of the given `dimensions`, as defined by width over
 * height.
 */
var aspectRatio = function (_a) {
    var width = _a.width, height = _a.height;
    return width / height;
};
/**
 * Returns the area of the given `dimensions`.
 */
var area = function (_a) {
    var width = _a.width, height = _a.height;
    return width * height;
};
/**
 * Returns a `Dimensions` fitted to the provided aspect ratio.
 *
 * @param ratio - Aspect ratio to fit the provided Dimensions to
 * @param dimensions - Dimensions to fit to the specified ratio
 */
var fitToRatio = function (ratio, dimensions) {
    if (dimensions.width >= dimensions.height * ratio) {
        return create$6(dimensions.height * ratio, dimensions.height);
    }
    return create$6(dimensions.width, dimensions.width / ratio);
};
/**
 * Converts a dimension to a rectangle, with an optional position.
 */
function toRectangle(dimensions, position) {
    if (position === void 0) { position = create$d(); }
    return fromPointAndDimensions(position, dimensions);
}

var dimensions = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create$6,
  square: square,
  isEqual: isEqual,
  scale: scale,
  proportionalScale: proportionalScale,
  trim: trim,
  containFit: containFit,
  cropFit: cropFit,
  scaleFit: scaleFit,
  round: round,
  floor: floor,
  center: center$1,
  aspectRatio: aspectRatio,
  area: area,
  fitToRatio: fitToRatio,
  toRectangle: toRectangle
});

/**
 * Creates a new `Line3`. If unspecified, the start and end values of the line
 * will be at origin.
 *
 * @param values The values to assign to the line.
 */
function create$5(values) {
    var _a, _b;
    if (values === void 0) { values = {}; }
    return {
        start: (_a = values.start) !== null && _a !== void 0 ? _a : origin(),
        end: (_b = values.end) !== null && _b !== void 0 ? _b : origin(),
    };
}
/**
 * Returns the point that is halfway between start and end.
 */
function center(line) {
    return lerp(line.start, line.end, 0.5);
}
/**
 * Returns a line where the start and end points are transformed with the given
 * matrix.
 *
 * @param line The line to transform.
 * @param matrix The matrix to apply.
 * @returns A transformed line.
 */
function transformMatrix(line, matrix) {
    var start = transformMatrix$1(line.start, matrix);
    var end = transformMatrix$1(line.end, matrix);
    return { start: start, end: end };
}
/**
 * Euclidean distance between the start and end points of the line.
 */
function distance(line) {
    return distance$1(line.start, line.end);
}
/**
 * Returns the squared distance between a line's start and end point. If you're
 * just comparing distances, this is slightly more efficient than `distanceTo`.
 */
function distanceSquared(line) {
    return distanceSquared$1(line.start, line.end);
}
/**
 * Returns a vector describing the direction of the line from start to end.
 */
function direction(line) {
    return subtract(line.end, line.start);
}

var line3 = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create$5,
  center: center,
  transformMatrix: transformMatrix,
  distance: distance,
  distanceSquared: distanceSquared,
  direction: direction
});

function create$3() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    if (args.length === 2) {
        return {
            a: args[0].x,
            b: args[0].y,
            c: args[1].x,
            d: args[1].y,
        };
    }
    else if (args.length === 4) {
        return {
            a: args[0],
            b: args[1],
            c: args[2],
            d: args[3],
        };
    }
    return {
        a: 0,
        b: 0,
        c: 0,
        d: 0,
    };
}
/**
 * Returns the determinant of the provided matrix.
 */
function determinant(matrix) {
    return matrix.a * matrix.d - matrix.b * matrix.c;
}
/**
 * Returns the dot product of the two vectors represented in this matrix.
 */
function dot(matrix) {
    return matrix.a * matrix.c + matrix.b * matrix.d;
}

var matrix2 = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create$3,
  determinant: determinant,
  dot: dot
});

/**
 * Creates a new plane. Defaults to a normal of `[0,0,0]` and constant of `0`.
 *
 * @param values Values to assign to the plane.
 * @returns A new plane.
 */
function create$2(values) {
    if (values === void 0) { values = {}; }
    return exports.__assign({ normal: origin(), constant: 0 }, values);
}
/**
 * Creates a plane from a normal and an arbitrary point on a plane.
 *
 * @param normal A normal.
 * @param point A point on the plane.
 * @returns A new plane.
 */
function fromNormalAndCoplanarPoint(normal, point) {
    var constant = -dot$1(point, normal);
    return create$2({ normal: normal, constant: constant });
}
/**
 * Returns the perpendicular distance from the plane to the given point.
 *
 * @param plane The plane.
 * @param point The point to calculate distance from `plane`.
 * @returns A distance.
 */
function distanceToPoint(plane, point) {
    return dot$1(plane.normal, point) + plane.constant;
}
/**
 * Returns the point where the line intersects with this plane. If the line does
 * not intersect, then `undefined` is returned. If the line is on the plane,
 * then the starting point of the line is returned.
 *
 * @param plane The plane to intersect.
 * @param line The line to intersect.
 * @returns An intersecting point on the plane and line.
 */
function intersectLine(plane, line) {
    var direction$1 = direction(line);
    var denominator = dot$1(plane.normal, direction$1);
    if (denominator === 0) {
        if (distanceToPoint(plane, line.start) === 0) {
            return line.start;
        }
        else {
            return undefined;
        }
    }
    var t = -(dot$1(line.start, plane.normal) + plane.constant) / denominator;
    if (t < 0 || t > 1) {
        return undefined;
    }
    else {
        return add(scale$2(t, direction$1), line.start);
    }
}
/**
 * Projects the given `point` onto the given `plane`.
 *
 * @param plane The plane to project onto.
 * @param point The point to project.
 * @returns The projected point.
 */
function projectPoint(plane, point) {
    var d = distanceToPoint(plane, point);
    return add(point, scale$2(-d, plane.normal));
}

var plane = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create$2,
  fromNormalAndCoplanarPoint: fromNormalAndCoplanarPoint,
  distanceToPoint: distanceToPoint,
  intersectLine: intersectLine,
  projectPoint: projectPoint
});

/**
 * Creates a new ray with the given values, or using default values if none are
 * provided. The direction defaults to `{x: 0, y: 0, z: -1}` if undefined.
 *
 * @param value The values of the ray.
 * @returns A new ray.
 */
function create$1(value) {
    var _a, _b;
    if (value === void 0) { value = {}; }
    return {
        origin: (_a = value.origin) !== null && _a !== void 0 ? _a : origin(),
        direction: (_b = value.direction) !== null && _b !== void 0 ? _b : forward(),
    };
}
/**
 * Returns a point at the given distance along this ray.
 *
 * @param ray The ray to get the point on.
 * @param distance A distance from origin along the ray's direction.
 * @returns A point on the ray.
 */
function at(ray, distance) {
    return add(scale$2(distance, ray.direction), ray.origin);
}
/**
 * Computes the distance of the `ray`s origin to the given `plane`. Returns a
 * distance of 0 if the ray is coplanar and returns `undefined` if the ray does
 * not intersect with the plane.
 *
 * @param ray The ray to get the distance for.
 * @param plane The plane to compute the distance to.
 * @returns The distance to the plane, or `undefined` if it cannot be computed.
 */
function distanceToPlane(ray, plane$1) {
    var d = dot$1(plane$1.normal, ray.direction);
    if (d === 0) {
        // Ray is on plane.
        return distanceToPoint(plane$1, ray.origin) === 0 ? 0 : undefined;
    }
    else {
        var t = -(dot$1(ray.origin, plane$1.normal) + plane$1.constant) / d;
        // Checks if ray intersects plane.
        return t >= 0 ? t : undefined;
    }
}
/**
 * Computes the intersection point of the given `ray` to the given `plane`. If
 * the ray does not intersect with the plane, then `undefined` is returned.
 *
 * @param ray The ray to intersect.
 * @param plane The plane to intersect with.
 * @returns The intersection point, or `undefined` if the ray does not
 * intersect.
 */
function intersectPlane(ray, plane) {
    var t = distanceToPlane(ray, plane);
    return t != null ? at(ray, t) : undefined;
}

var ray = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create$1,
  at: at,
  distanceToPlane: distanceToPlane,
  intersectPlane: intersectPlane
});

/**
 * Returns a new Vector4. If `value` is undefined, then `{x: 0, y: 0, z: 0,
 * w: 0}` is returned.
 */
function create(value) {
    if (value === void 0) { value = {}; }
    return exports.__assign({ x: 0, y: 0, z: 0, w: 0 }, value);
}
/**
 * Parses a JSON string representation of a `Vector4`.
 *
 * @param json A JSON string either in the form of `[x, y, z, w]` or `{"x": 0, "y": 0, "z": 0, "w": 0}`.
 * @returns A parsed `Vector4`.
 */
function fromJson(json) {
    var obj = JSON.parse(json);
    if (Array.isArray(obj)) {
        var x = obj[0], y = obj[1], z = obj[2], w = obj[3];
        return create({ x: x, y: y, z: z, w: w });
    }
    else {
        return create(obj);
    }
}

var vector4 = /*#__PURE__*/Object.freeze({
  __proto__: null,
  create: create,
  fromJson: fromJson
});

exports.__asyncValues = __asyncValues;
exports.__awaiter = __awaiter;
exports.__extends = __extends;
exports.__generator = __generator;
exports.__read = __read;
exports.__spreadArray = __spreadArray;
exports.angle = angle;
exports.boundingBox = boundingBox;
exports.boundingSphere = boundingSphere;
exports.clamp = clamp;
exports.dimensions = dimensions;
exports.euler = euler;
exports.line3 = line3;
exports.matrix2 = matrix2;
exports.matrix4 = matrix4;
exports.plane = plane;
exports.point = point;
exports.quaternion = quaternion;
exports.ray = ray;
exports.rectangle = rectangle;
exports.vector3 = vector3;
exports.vector4 = vector4;
//# sourceMappingURL=bundle-BhTmftd-.js.map

//# sourceMappingURL=bundle-BhTmftd-.js.map