/*exported Fabrik*/
var Fabrik = (function() {
  'use strict';

  /**
   * Forward And Backward Reaching Inverse Kinematics.
   */
  function Fabrik( x, y ) {
    // Origin.
    this.x = x || 0;
    this.y = y || 0;

    // End effector position.
    this.xf = 0;
    this.yf = 0;

    this.length = 0;
  }

  Fabrik.prototype.set = function( x, y ) {
    x -= this.x;
    y -= this.y;
  };

  return Fabrik;

}) ();

@@ -1,8 +1,23 @@
+/*globals IK*/%0A
 /*export
@@ -28,16 +28,16 @@
 abrik*/%0A
-
 var Fabr
@@ -72,16 +72,80 @@
 rict';%0A%0A
+  function lerp( a, b, t ) %7B%0A    return a + t * ( b - a );%0A  %7D%0A%0A
   /**%0A  
@@ -441,16 +441,16 @@
 this.x;%0A
-
     y -=
@@ -457,16 +457,642 @@
  this.y;
+%0A%0A    // Distances.%0A    var distance = Math.sqrt( x * x + y * y );%0A    var dx, dy;%0A    var di;%0A%0A    // Parameter.%0A    var t;%0A%0A    var count = this.lengths.length;%0A    var link;%0A    var next;%0A    var i;%0A    if ( distance %3E IK.length( this ) ) %7B%0A      // Not reachable.%0A      for ( i = 0; i %3C count; i++ ) %7B%0A        link = IK.links%5Bi%5D;%0A%0A        // Distance from link to point.%0A        dx = x - link.x;%0A        dy = y - link.y;%0A%0A        di = Math.sqrt( dx * dx + dy * dy );%0A        t = link.length / di;%0A%0A        next.x = lerp( link.x, x, t );%0A        next.y = lerp( link.y, y, t );%0A      %7D%0A    %7D else %7B%0A      // Reachable.%0A    %7D
 %0A  %7D;%0A%0A 

Handle unreachable target case.