code: function findBestRelativePosition(rect, targetRect, constrainRect, rels) {
        var pos, i;
  
        for (i = 0; i < rels.length; i++) {
          pos = relativePosition(rect, targetRect, rels[i]);
  
          if (pos.x >= constrainRect.x && pos.x + pos.w <= constrainRect.w + constrainRect.x &&
            pos.y >= constrainRect.y && pos.y + pos.h <= constrainRect.h + constrainRect.y) {
            return rels[i];
          }
        }
  
        return null;
      }
docs: Tests various positions to get the most suitable one.
  
  @method findBestRelativePosition
  @param {Rect} rect Rect to use as source.
  @param {Rect} targetRect Rect to move relative to.
  @param {Rect} constrainRect Rect to constrain within.
  @param {Array} rels Array of relative positions to test against.