src/math-helpers.js
function rotg (a, b, csr) {
  // Based on Algorithm 4 from "Discontinuous Plane
  // Rotations and the Symmetric Eigenvalue Problem"
  // by Anderson, 2000.
  let c = 0;
  let s = 0;
  let r = 0;
  let t = 0;
  let u = 0;

  if (b === 0) {
    c = _Math.sign(a);
    s = 0;
    r = _Math.abs(a);
  } else if (a === 0) {
    c = 0;
    s = _Math.sign(b);
    r = _Math.abs(b);
  } else if (_Math.abs(a) > _Math.abs(b)) {
    t = b / a;
    u = _Math.sign(a) * _Math.sqrt(1 + t * t);
    c = 1 / u;
    s = t * c;
    r = a * u;
  } else {
    t = a / b;
    u = _Math.sign(a) * _Math.sqrt(1 + t * t);
    s = 1 / u;
    c = t * s;
    r = b * u;
  }
  // try to save some unnecessary object creation
  if (csr !== undefined && csr.length > 2) {
    csr[0] = c;
    csr[1] = s;
    csr[2] = r;
  } else {
    return [c, s, r];
  }
}
function rotg (a, b, csr) {
  // Based on Algorithm 4 from "Discontinuous Plane
  // Rotations and the Symmetric Eigenvalue Problem"
  // by Anderson, 2000.
  let c = 0;
  let s = 0;
  let r = 0;
  let t = 0;
  let u = 0;

  if (b === 0) {
    c = _Math.sign(a);
    s = 0;
    r = _Math.abs(a);
  } else if (a === 0) {
    c = 0;
    s = _Math.sign(b);
    r = _Math.abs(b);
  } else if (_Math.abs(a) > _Math.abs(b)) {
    t = b / a;
    u = _Math.sign(a) * _Math.sqrt(1 + t * t);
    c = 1 / u;
    s = t * c;
    r = a * u;
  } else {
    t = a / b;
    u = _Math.sign(a) * _Math.sqrt(1 + t * t);
    s = 1 / u;
    c = t * s;
    r = b * u;
  }
  // try to save some unnecessary object creation
  if (csr !== undefined && csr.length > 2) {
    csr[0] = c;
    csr[1] = s;
    csr[2] = r;
  } else {
    return [c, s, r];
  }
}
function rotg ( a , b , csr ) { // Based on Algorithm 4 from "Discontinuous Plane // Rotations and the Symmetric Eigenvalue Problem" // by Anderson, 2000. let c = 0 ; let s = 0 ; let r = 0 ; let t = 0 ; let u = 0 ; if ( b === 0 ) { c = _Math . sign ( a ) ; s = 0 ; r = _Math . abs ( a ) ; } else if ( a === 0 ) { c = 0 ; s = _Math . sign ( b ) ; r = _Math . abs ( b ) ; } else if ( _Math . abs ( a ) > _Math . abs ( b ) ) { t = b / a ; u = _Math . sign ( a ) * _Math . sqrt ( 1 + t * t ) ; c = 1 / u ; s = t * c ; r = a * u ; } else { t = a / b ; u = _Math . sign ( a ) * _Math . sqrt ( 1 + t * t ) ; s = 1 / u ; c = t * s ; r = b * u ; } // try to save some unnecessary object creation if ( csr !== undefined && csr . length > 2 ) { csr [ 0 ] = c ; csr [ 1 ] = s ; csr [ 2 ] = r ; } else { return [ c , s , r ] ; } }
Computes the Givens rotation values for a vector.
@memberof Helpers
@param {number} a The x-component of a vector rotated back to a vector on the X-axis.
@param {number} b The y-component of a vector rotated back to a vector on the X-axis.
@param {array} csr (Optional) An array for the values to saved into, if provided. If not, a new array is created.
Computes the Givens rotation values for a vector .