docs: function(geometry, options) {
          var edge = !(options && options.edge === false);
          var details = edge && options && options.details;
          var result, best = {};
          var min = Number.POSITIVE_INFINITY;
          if(geometry instanceof OpenLayers.Geometry.Point) {
              var segs = this.getSortedSegments();
              var x = geometry.x;
              var y = geometry.y;
              var seg;
              for(var i=0, len=segs.length; i<len; ++i) {
                  seg = segs[i];
                  result = OpenLayers.Geometry.distanceToSegment(geometry, seg);
                  if(result.distance < min) {
                      min = result.distance;
                      best = result;
                      if(min === 0) {
                          break;
                      }
                  } else {
                      // if distance increases and we cross y0 to the right of x0, no need to keep looking.
                      if(seg.x2 > x && ((y > seg.y1 && y < seg.y2) || (y < seg.y1 && y > seg.y2))) {
                          break;
                      }
                  }
              }
              if(details) {
                  best = {
                      distance: best.distance,
                      x0: best.x, y0: best.y,
                      x1: x, y1: y
                  };
              } else {
                  best = best.distance;
              }
          } else if(geometry instanceof OpenLayers.Geometry.LineString) { 
              var segs0 = this.getSortedSegments();
              var segs1 = geometry.getSortedSegments();
              var seg0, seg1, intersection, x0, y0;
              var len1 = segs1.length;
              var interOptions = {point: true};
              outer: for(var i=0, len=segs0.length; i<len; ++i) {
                  seg0 = segs0[i];
                  x0 = seg0.x1;
                  y0 = seg0.y1;
                  for(var j=0; j<len1; ++j) {
                      seg1 = segs1[j];
                      intersection = OpenLayers.Geometry.segmentsIntersect(seg0, seg1, interOptions);
                      if(intersection) {
                          min = 0;
                          best = {
                              distance: 0,
                              x0: intersection.x, y0: intersection.y,
                              x1: intersection.x, y1: intersection.y
                          };
                          break outer;
                      } else {
                          result = OpenLayers.Geometry.distanceToSegment({x: x0, y: y0}, seg1);
                          if(result.distance < min) {
                              min = result.distance;
                              best = {
                                  distance: min,
                                  x0: x0, y0: y0,
                                  x1: result.x, y1: result.y
                              };
                          }
                      }
                  }
              }
              if(!details) {
                  best = best.distance;
              }
              if(min !== 0) {
                  // check the final vertex in this line's sorted segments
                  if(seg0) {
                      result = geometry.distanceTo(
                          new OpenLayers.Geometry.Point(seg0.x2, seg0.y2),
                          options
                      );
                      var dist = details ? result.distance : result;
                      if(dist < min) {
                          if(details) {
                              best = {
                                  distance: min,
                                  x0: result.x1, y0: result.y1,
                                  x1: result.x0, y1: result.y0
                              };
                          } else {
                              best = dist;
                          }
                      }
                  }
              }
          } else {
              best = geometry.distanceTo(this, options);
              // swap since target comes from this line
              if(details) {
                  best = {
                      distance: best.distance,
                      x0: best.x1, y0: best.y1,
                      x1: best.x0, y1: best.y0
                  };
              }
          }
          return best;
      }