add tests, jshint cleanup

This commit is contained in:
Bryan Housel
2014-06-16 11:49:07 -04:00
parent 1c61b4b0f2
commit 1a2b9c82f6
3 changed files with 71 additions and 3 deletions
+1 -1
View File
@@ -118,7 +118,7 @@ iD.geo.lineIntersection = function(a, b) {
}
return null;
}
};
// Return whether point is contained in polygon.
//
+28
View File
@@ -156,6 +156,34 @@ describe('iD.geo', function() {
});
});
describe('.lineIntersection', function() {
it('returns null if lines are colinear with overlap', function() {
var a = [[0, 0], [10, 0]],
b = [[-5, 0], [5, 0]];
expect(iD.geo.lineIntersection(a, b)).to.be.null;
});
it('returns null if lines are colinear but disjoint', function() {
var a = [[5, 0], [10, 0]],
b = [[-10, 0], [-5, 0]];
expect(iD.geo.lineIntersection(a, b)).to.be.null;
});
it('returns null if lines are parallel', function() {
var a = [[0, 0], [10, 0]],
b = [[0, 5], [10, 5]];
expect(iD.geo.lineIntersection(a, b)).to.be.null;
});
it('returns the intersection point between 2 lines', function() {
var a = [[0, 0], [10, 0]],
b = [[5, 10], [5, -10]];
expect(iD.geo.lineIntersection(a, b)).to.eql([5, 0]);
});
it('returns null if lines are not parallel but not intersecting', function() {
var a = [[0, 0], [10, 0]],
b = [[-5, 10], [-5, -10]];
expect(iD.geo.lineIntersection(a, b)).to.be.null;
});
});
describe('.pointInPolygon', 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]];
+42 -2
View File
@@ -10,7 +10,7 @@ describe("iD.svg.Midpoints", function () {
.call(iD.svg.Surface(context));
});
it("finds the location of the midpoints", function () {
it("creates midpoint on segment completely within the extent", function () {
var a = iD.Node({loc: [0, 0]}),
b = iD.Node({loc: [50, 0]}),
line = iD.Way({nodes: [a.id, b.id]}),
@@ -23,7 +23,7 @@ describe("iD.svg.Midpoints", function () {
expect(surface.select('.midpoint').datum().loc).to.eql([25, 0]);
});
it("doesn't create midpoints on segments with pixel length less than 40", function () {
it("doesn't create midpoint on segment with pixel length less than 40", function () {
var a = iD.Node({loc: [0, 0]}),
b = iD.Node({loc: [39, 0]}),
line = iD.Way({nodes: [a.id, b.id]}),
@@ -35,4 +35,44 @@ describe("iD.svg.Midpoints", function () {
expect(surface.selectAll('.midpoint')[0]).to.have.length(0);
});
it("doesn't create midpoint on segment completely outside of the extent", function () {
var a = iD.Node({loc: [-100, 0]}),
b = iD.Node({loc: [-50, 0]}),
line = iD.Way({nodes: [a.id, b.id]}),
graph = iD.Graph([a, b, line]),
extent = iD.geo.Extent([0, 0], [100, 100]);
context.selectedIDs = function() { return [line.id]; };
surface.call(iD.svg.Midpoints(projection, context), graph, [line], filter, extent);
expect(surface.selectAll('.midpoint')[0]).to.have.length(0);
});
it("creates midpoint on extent edge for segment partially outside of the extent", function () {
var a = iD.Node({loc: [50, 0]}),
b = iD.Node({loc: [500, 0]}),
line = iD.Way({nodes: [a.id, b.id]}),
graph = iD.Graph([a, b, line]),
extent = iD.geo.Extent([0, 0], [100, 100]);
context.selectedIDs = function() { return [line.id]; };
surface.call(iD.svg.Midpoints(projection, context), graph, [line], filter, extent);
expect(surface.select('.midpoint').datum().loc).to.eql([100, 0]);
});
it("doesn't create midpoint on extent edge for segment with pixel length less than 20", function () {
var a = iD.Node({loc: [81, 0]}),
b = iD.Node({loc: [500, 0]}),
line = iD.Way({nodes: [a.id, b.id]}),
graph = iD.Graph([a, b, line]),
extent = iD.geo.Extent([0, 0], [100, 100]);
context.selectedIDs = function() { return [line.id]; };
surface.call(iD.svg.Midpoints(projection, context), graph, [line], filter, extent);
expect(surface.selectAll('.midpoint')[0]).to.have.length(0);
});
});