text: import { root } from './root.js';
  
  let Matrix;
  const TWO_PI = Math.PI * 2;
  const HALF_PI = Math.PI * 0.5;
  
  /**
   * @name Two.Utils.decomposeMatrix
   * @function
   * @param {Two.Matrix} matrix - The matrix to decompose.
   * @returns {Object} An object containing relevant skew values.
   * @description Decompose a 2D 3x3 Matrix to find the skew.
   */
  function decomposeMatrix(matrix, b, c, d, e, f) {
  
    // TODO: Include skewX, skewY
    // https://math.stackexchange.com/questions/237369/given-this-transformation-matrix-how-do-i-decompose-it-into-translation-rotati/417813
    // https://stackoverflow.com/questions/45159314/decompose-2d-transformation-matrix
  
    let a;
  
    if (arguments.length <= 1) {
      a = matrix.a;
      b = matrix.b;
      c = matrix.c;
      d = matrix.d;
      e = matrix.e;
      f = matrix.f;
    } else {
      a = matrix;
    }
  
    return {
      translateX: e,
      translateY: f,
      scaleX: Math.sqrt(a * a + b * b),
      scaleY: Math.sqrt(c * c + d * d),
      rotation: 180 * Math.atan2(b, a) / Math.PI
    };
  
  }
  
  function setMatrix(matrix) {
    Matrix = matrix;
  }
  
  /**
   * @name Two.Utils.getComputedMatrix
   * @function
   * @param {Two.Shape} object - The Two.js object that has a matrix property to calculate from.
   * @param {Two.Matrix} [matrix] - The matrix to apply calculated transformations to if available.
   * @returns {Two.Matrix} The computed matrix of a nested object. If no `matrix` was passed in arguments then a `new Two.Matrix` is returned.
   * @description Method to get the world space transformation of a given object in a Two.js scene.
   */
  function getComputedMatrix(object, matrix) {
  
    matrix = (matrix && matrix.identity()) || new Matrix();
    let parent = object;
    const matrices = [];
  
    while (parent && parent._matrix) {
      matrices.push(parent._matrix);
      parent = parent.parent;
    }
  
    matrices.reverse();
  
    for (let i = 0; i < matrices.length; i++) {
  
      const m = matrices[i];
      const e = m.elements;
      matrix.multiply(
        e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7], e[8], e[9]);
  
    }
  
    return matrix;
  
  }
  
  /**
   * @name Two.Utils.lerp
   * @function
   * @param {Number} a - Start value.
   * @param {Number} b - End value.
   * @param {Number} t - Zero-to-one value describing percentage between a and b.
   * @returns {Number}
   * @description Linear interpolation between two values `a` and `b` by an amount `t`.
   */
  function lerp(a, b, t) {
    return t * (b - a) + a;
  }
  
  /**
   * @name Two.Utils.getPoT
   * @param {Number} value - The number to find the nearest power-of-two value
   * @returns {Number}
   * @description Rounds a number up to the nearest power-of-two value.
   * @see {@link https://en.wikipedia.org/wiki/Power_of_two}
   */
  const pots = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096];
  function getPoT(value) {
    let i = 0;
    while (pots[i] && pots[i] < value) {
      i++;
    }
    return pots[i];
  }
  
  /**
   * @name Two.Utils.mod
   * @function
   * @param {Number} v - The value to modulo
   * @param {Number} l - The value to modulo by
   * @returns {Number}
   * @description Modulo with added functionality to handle negative values in a positive manner.
   */
  function mod(v, l) {
  
    while (v < 0) {
      v += l;
    }
  
    return v % l;
  
  }
  
  const NumArray = root.Float32Array || Array;
  const floor = Math.floor;
  
  /**
  * @name Two.Utils.toFixed
  * @function
  * @param {Number} v - Any float
  * @returns {Number} That float trimmed to the third decimal place.
  * @description A pretty fast toFixed(3) alternative.
  * @see {@link http://jsperf.com/parsefloat-tofixed-vs-math-round/18}
  */
  function toFixed(v) {
    return floor(v * 1000000) / 1000000;
  }
  
  
  export {
    decomposeMatrix, getComputedMatrix, getPoT, setMatrix, lerp, mod, NumArray,
    toFixed, TWO_PI, HALF_PI
  };
  