Adding distanceTo method to all geometry types. This calculates the shortest distance between any two geometries. For geometries that are entirely contained within polygons, the distance returned will be the distance to the nearest edge. Set the edge option to false to return 0 in cases where one geometry contains another. Details about the distance calculation can be returned by setting the details option true. Details include information about endpoints of the shortest segment between the two geometries. r=ahocevar (closes #1907)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8836 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -250,7 +250,37 @@
|
||||
t.fail(failures[f]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function test_distanceToSegment(t) {
|
||||
var dist = OpenLayers.Geometry.distanceToSegment;
|
||||
|
||||
var cases = [{
|
||||
got: dist({x: 0, y: 0}, {x1: 0, y1: 1, x2: 1, y2: 1}),
|
||||
expected: {distance: 1, x: 0, y: 1}
|
||||
}, {
|
||||
got: dist({x: 0, y: 0}, {x1: -1, y1: -1, x2: 0, y2: -1}),
|
||||
expected: {distance: 1, x: 0, y: -1}
|
||||
}, {
|
||||
got: dist({x: 0, y: 0}, {x1: -1, y1: -1, x2: 1, y2: 1}),
|
||||
expected: {distance: 0, x: 0, y: 0}
|
||||
}, {
|
||||
got: dist({x: 1, y: 1}, {x1: 2, y1: 0, x2: 2, y2: 3}),
|
||||
expected: {distance: 1, x: 2, y: 1}
|
||||
}, {
|
||||
got: dist({x: -1, y: -1}, {x1: -2, y1: -2, x2: -1, y2: -3}),
|
||||
expected: {distance: Math.sqrt(2), x: -2, y: -2}
|
||||
}, {
|
||||
got: dist({x: -1, y: 1}, {x1: -3, y1: 1, x2: -1, y2: 3}),
|
||||
expected: {distance: Math.sqrt(2), x: -2, y: 2}
|
||||
}];
|
||||
|
||||
t.plan(cases.length);
|
||||
for(var i=0; i<cases.length; ++i) {
|
||||
t.eq(cases[i].got, cases[i].expected, "case " + i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function test_fromWKT(t) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user