src/third_party/specimenTools/lib/bower_components/Atem-Math-Tools/lib/hobby.js
/**
     * Returns two distances from the respective on-curve points to their
     * control points on the given curve segment.
     *
     * dir0 and dir1 are the tangent directions as radians or instances
     * of Vector.
     *
     * alpha and beta are the tension parameters. The tensions values alpha
     * and beta have no influence on the resulting distance of each other.
     *
     * Tensions are bigger the closer they are to their on-curve points.
     * When using Infinity as a tension the returned magnitude is 0;
     * When using 0 as a tension the returned magnitude is Infinity.
     *    When the tension is 0 and z0 equals z1 its resulting
     *    magnitude is NaN; in this case it is short circuited into
     *    returning Infinity, which is OK as a behavior; because it obeys
     *    the rule above, also it's compatible with the reverse operation
     *    magnitude2tension.
     */
Returns two distances from the respective on-curve points to their
control points on the given curve segment.

dir0 and dir1 are the tangent directions as radians or instances
of Vector.

alpha and beta are the tension parameters. The tensions values alpha
and beta have no influence on the resulting distance of each other.

Tensions are bigger the closer they are to their on-curve points.
When using Infinity as a tension the returned magnitude is 0;
When using 0 as a tension the returned magnitude is Infinity.
When the tension is 0 and z0 equals z1 its resulting
magnitude is NaN; in this case it is short circuited into
returning Infinity, which is OK as a behavior; because it obeys
the rule above, also it's compatible with the reverse operation
magnitude2tension.
Returns two distances from the respective on - curve points to their control points on the given curve segment . dir0 and dir1 are the tangent directions as radians or instances of Vector . alpha and beta are the tension parameters . The tensions values alpha and beta have no influence on the resulting distance of each other . Tensions are bigger the closer they are to their on - curve points . When using Infinity as a tension the returned magnitude is 0 ; When using 0 as a tension the returned magnitude is Infinity . When the tension is 0 and z0 equals z1 its resulting magnitude is NaN ; in this case it is short circuited into returning Infinity which is OK as a behavior ; because it obeys the rule above also it ' s compatible with the reverse operation magnitude2tension .
function _tension2magnitude(z0, dir0, alpha, beta, dir1, z1) {
        var diff_z1z0 = z1['-'](z0)
          , angle_z1z0 = diff_z1z0.angle()
          , magnitude_z1z0 = diff_z1z0.magnitude()
          , theta = normalizeAngle(dir0 - angle_z1z0)
          , phi = normalizeAngle(angle_z1z0 - dir1)
          , u, v;
        if(alpha !== undefined)
            u = (magnitude_z1z0 === 0 && (alpha === 0 || alpha === Infinity))
                ? (alpha === 0 ? Infinity : 0)
                : magnitude_z1z0 * hobby(theta, phi) / alpha
                ;
        if(beta !== undefined)
            v = (magnitude_z1z0 === 0 && (beta === 0 || beta === Infinity))
                ? (beta === 0 ? Infinity : 0)
                : magnitude_z1z0 * hobby(phi, theta) / beta
                ;
        return [u, v];
    }
function _tension2magnitude ( z0 , dir0 , alpha , beta , dir1 , z1 ) { var diff_z1z0 = z1 [ '-' ] ( z0 ) , angle_z1z0 = diff_z1z0 . angle ( ) , magnitude_z1z0 = diff_z1z0 . magnitude ( ) , theta = normalizeAngle ( dir0 - angle_z1z0 ) , phi = normalizeAngle ( angle_z1z0 - dir1 ) , u , v ; if ( alpha !== undefined ) u = ( magnitude_z1z0 === 0 && ( alpha === 0 || alpha === Infinity ) ) ? ( alpha === 0 ? Infinity : 0 ) : magnitude_z1z0 * hobby ( theta , phi ) / alpha ; if ( beta !== undefined ) v = ( magnitude_z1z0 === 0 && ( beta === 0 || beta === Infinity ) ) ? ( beta === 0 ? Infinity : 0 ) : magnitude_z1z0 * hobby ( phi , theta ) / beta ; return [ u , v ] ; }
Returns two distances from the respective on-curve points to their
 control points on the given curve segment.
Returns two distances from the respective on - curve points to their control points on the given curve segment .
// calculating this using the polar form helps us by not // getting into trouble when z1['-'](z0) is <Vector 0, 0> // because that would cause a division by 0 when calculating // theta and pi using cartesian arithmetic.