iD.util.geo => iD.geo

This commit is contained in:
John Firebaugh
2013-01-22 18:20:20 -05:00
parent 7f8ff43a0f
commit c263ebd4dc
10 changed files with 98 additions and 100 deletions
+15 -15
View File
@@ -26,21 +26,21 @@ describe('Util', function() {
describe('geo', function() {
describe('#roundCoords', function() {
expect(iD.util.geo.roundCoords([0.1, 1])).to.eql([0, 1]);
expect(iD.util.geo.roundCoords([0, 1])).to.eql([0, 1]);
expect(iD.util.geo.roundCoords([0, 1.1])).to.eql([0, 1]);
expect(iD.geo.roundCoords([0.1, 1])).to.eql([0, 1]);
expect(iD.geo.roundCoords([0, 1])).to.eql([0, 1]);
expect(iD.geo.roundCoords([0, 1.1])).to.eql([0, 1]);
});
describe('#interp', function() {
it('interpolates halfway', function() {
var a = [0, 0],
b = [10, 10];
expect(iD.util.geo.interp(a, b, 0.5)).to.eql([5, 5]);
expect(iD.geo.interp(a, b, 0.5)).to.eql([5, 5]);
});
it('interpolates to one side', function() {
var a = [0, 0],
b = [10, 10];
expect(iD.util.geo.interp(a, b, 0)).to.eql([0, 0]);
expect(iD.geo.interp(a, b, 0)).to.eql([0, 0]);
});
});
@@ -48,17 +48,17 @@ describe('Util', function() {
it('distance between two same points is zero', function() {
var a = [0, 0],
b = [0, 0];
expect(iD.util.geo.dist(a, b)).to.eql(0);
expect(iD.geo.dist(a, b)).to.eql(0);
});
it('a straight 10 unit line is 10', function() {
var a = [0, 0],
b = [10, 0];
expect(iD.util.geo.dist(a, b)).to.eql(10);
expect(iD.geo.dist(a, b)).to.eql(10);
});
it('a pythagorean triangle is right', function() {
var a = [0, 0],
b = [4, 3];
expect(iD.util.geo.dist(a, b)).to.eql(5);
expect(iD.geo.dist(a, b)).to.eql(5);
});
});
@@ -66,7 +66,7 @@ describe('Util', function() {
it('says a point in a polygon is on a polygon', function() {
var poly = [[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]];
var point = [0.5, 0.5];
expect(iD.util.geo.pointInPolygon(point, poly)).to.be.true;
expect(iD.geo.pointInPolygon(point, poly)).to.be.true;
});
it('says a point outside of a polygon is outside', function() {
var poly = [
@@ -76,7 +76,7 @@ describe('Util', function() {
[1, 0],
[0, 0]];
var point = [0.5, 1.5];
expect(iD.util.geo.pointInPolygon(point, poly)).to.be.false;
expect(iD.geo.pointInPolygon(point, poly)).to.be.false;
});
});
@@ -84,12 +84,12 @@ describe('Util', function() {
it('says a polygon in a polygon is in', function() {
var outer = [[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]];
var inner = [[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]];
expect(iD.util.geo.polygonContainsPolygon(outer, inner)).to.be.true;
expect(iD.geo.polygonContainsPolygon(outer, inner)).to.be.true;
});
it('says a polygon outside of a polygon is out', function() {
var outer = [[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]];
var inner = [[1, 1], [1, 9], [2, 2], [2, 1], [1, 1]];
expect(iD.util.geo.polygonContainsPolygon(outer, inner)).to.be.false;
expect(iD.geo.polygonContainsPolygon(outer, inner)).to.be.false;
});
});
@@ -97,19 +97,19 @@ describe('Util', function() {
it('says a polygon in a polygon intersects it', function() {
var outer = [[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]];
var inner = [[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]];
expect(iD.util.geo.polygonIntersectsPolygon(outer, inner)).to.be.true;
expect(iD.geo.polygonIntersectsPolygon(outer, inner)).to.be.true;
});
it('says a polygon that partially intersects does', function() {
var outer = [[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]];
var inner = [[-1, -1], [1, 2], [2, 2], [2, 1], [1, 1]];
expect(iD.util.geo.polygonIntersectsPolygon(outer, inner)).to.be.true;
expect(iD.geo.polygonIntersectsPolygon(outer, inner)).to.be.true;
});
it('says totally disjoint polygons do not intersect', function() {
var outer = [[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]];
var inner = [[-1, -1], [-1, -2], [-2, -2], [-2, -1], [-1, -1]];
expect(iD.util.geo.polygonIntersectsPolygon(outer, inner)).to.be.false;
expect(iD.geo.polygonIntersectsPolygon(outer, inner)).to.be.false;
});
});
});