From a3ab4b10950617dbc668b9efbb3993b3bbbe4c6d Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Fri, 1 Mar 2013 17:14:14 -0500 Subject: [PATCH] Fix mercator tests, these are broken in Leaflet master. --- spec/suites/geo/ProjectionSpec.js | 33 ++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/spec/suites/geo/ProjectionSpec.js b/spec/suites/geo/ProjectionSpec.js index 30046ba0..1e83280a 100644 --- a/spec/suites/geo/ProjectionSpec.js +++ b/spec/suites/geo/ProjectionSpec.js @@ -2,31 +2,42 @@ describe("Projection.Mercator", function() { var p = L.Projection.Mercator; expect.Assertion.prototype.near = function(expected, delta) { - delta = 0 || 1.0; + delta = 0 || 10; expect(this.obj.x).to - .be.within(expected.x - delta, expected.y + delta); + .be.within(expected.x - delta, expected.x + delta); expect(this.obj.y).to - .be.within(expected.y - delta, expected.x + delta); + .be.within(expected.y - delta, expected.y + delta); }; describe("#project", function() { - it("projects", function() { + it("projects a center point", function() { //edge cases expect(p.project(new L.LatLng(0, 0))).near(new L.Point(0, 0)); - expect(p.project(new L.LatLng(90, 180))).near(new L.Point(-Math.PI, Math.PI)); - expect(p.project(new L.LatLng(-90, -180))).near(new L.Point(-Math.PI, -Math.PI)); + }); - expect(p.project(new L.LatLng(50, 30))).near(new L.Point(0.523598775598, 1.010683188683)); + it("projects the northeast corner of the world", function() { + expect(p.project(new L.LatLng(90, 180))).near(new L.Point(20037508.342789244, 19970326.50745906)); + }); + + it("projects the southwest corner of the world", function() { + expect(p.project(new L.LatLng(-90, -180))).near(new L.Point(-20037508, -19970326)); + }); + + it("projects 50, 30", function() { + expect(p.project(new L.LatLng(50, 30))).near(new L.Point(3339584, 6392021)); }); }); describe("#unproject", function() { - it("unprojects", function() { - function pr(point) { - return p.project(p.unproject(point)); - } + function pr(point) { + return p.project(p.unproject(point)); + } + it("unprojects a center point", function() { expect(pr(new L.Point(0, 0))).near(new L.Point(0, 0)); + }); + + it("pi points", function() { expect(pr(new L.Point(-Math.PI, Math.PI))).near(new L.Point(-Math.PI, Math.PI)); expect(pr(new L.Point(-Math.PI, -Math.PI))).near(new L.Point(-Math.PI, -Math.PI));