docs/examples-0.7.x/libs/leaflet-src.js
function (p, p1, p2, sqDist) {
		var x = p1.x,
		    y = p1.y,
		    dx = p2.x - x,
		    dy = p2.y - y,
		    dot = dx * dx + dy * dy,
		    t;

		if (dot > 0) {
			t = ((p.x - x) * dx + (p.y - y) * dy) / dot;

			if (t > 1) {
				x = p2.x;
				y = p2.y;
			} else if (t > 0) {
				x += dx * t;
				y += dy * t;
			}
		}

		dx = p.x - x;
		dy = p.y - y;

		return sqDist ? dx * dx + dy * dy : new L.Point(x, y);
	}
function (p, p1, p2, sqDist) {
		var x = p1.x,
		    y = p1.y,
		    dx = p2.x - x,
		    dy = p2.y - y,
		    dot = dx * dx + dy * dy,
		    t;

		if (dot > 0) {
			t = ((p.x - x) * dx + (p.y - y) * dy) / dot;

			if (t > 1) {
				x = p2.x;
				y = p2.y;
			} else if (t > 0) {
				x += dx * t;
				y += dy * t;
			}
		}

		dx = p.x - x;
		dy = p.y - y;

		return sqDist ? dx * dx + dy * dy : new L.Point(x, y);
	}
function ( p , p1 , p2 , sqDist ) { var x = p1 . x , y = p1 . y , dx = p2 . x - x , dy = p2 . y - y , dot = dx * dx + dy * dy , t ; if ( dot > 0 ) { t = ( ( p . x - x ) * dx + ( p . y - y ) * dy ) / dot ; if ( t > 1 ) { x = p2 . x ; y = p2 . y ; } else if ( t > 0 ) { x += dx * t ; y += dy * t ; } } dx = p . x - x ; dy = p . y - y ; return sqDist ? dx * dx + dy * dy : new L . Point ( x , y ) ; }
return closest point on segment or distance to that point
return closest point on segment or distance to that point