-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rotated Mercator automatic clip extent.
Fixes #89. Also fixes automatic clip extent for transverse Mercator, which was likewise busted when rotated, but also busted when intersecting with a user- specified clip extent.
- Loading branch information
Showing
3 changed files
with
100 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var tape = require("tape"), | ||
d3 = require("../../"); | ||
|
||
tape("transverseMercator.clipExtent(null) sets the default automatic clip extent", function(test) { | ||
var projection = d3.geoTransverseMercator().translate([0, 0]).scale(1).clipExtent(null).precision(0); | ||
test.pathEqual(d3.geoPath(projection)({type: "Sphere"}), "M3.141593,3.141593L0,3.141593L-3.141593,3.141593L-3.141593,-3.141593L-3.141593,-3.141593L0,-3.141593L3.141593,-3.141593L3.141593,3.141593Z"); | ||
test.equal(projection.clipExtent(), null); | ||
test.end(); | ||
}); | ||
|
||
tape("transverseMercator.center(center) sets the correct automatic clip extent", function(test) { | ||
var projection = d3.geoTransverseMercator().translate([0, 0]).scale(1).center([10, 10]).precision(0); | ||
test.pathEqual(d3.geoPath(projection)({type: "Sphere"}), "M2.966167,3.316126L-0.175426,3.316126L-3.317018,3.316126L-3.317019,-2.967060L-3.317019,-2.967060L-0.175426,-2.967060L2.966167,-2.967060L2.966167,3.316126Z"); | ||
test.equal(projection.clipExtent(), null); | ||
test.end(); | ||
}); | ||
|
||
tape("transverseMercator.clipExtent(extent) intersects the specified clip extent with the automatic clip extent", function(test) { | ||
var projection = d3.geoTransverseMercator().translate([0, 0]).scale(1).clipExtent([[-10, -10], [10, 10]]).precision(0); | ||
test.pathEqual(d3.geoPath(projection)({type: "Sphere"}), "M10,3.141593L0,3.141593L-10,3.141593L-10,-3.141593L-10,-3.141593L0,-3.141593L10,-3.141593L10,3.141593Z"); | ||
test.deepEqual(projection.clipExtent(), [[-10, -10], [10, 10]]); | ||
test.end(); | ||
}); | ||
|
||
tape("transverseMercator.clipExtent(extent).scale(scale) updates the intersected clip extent", function(test) { | ||
var projection = d3.geoTransverseMercator().translate([0, 0]).clipExtent([[-10, -10], [10, 10]]).scale(1).precision(0); | ||
test.pathEqual(d3.geoPath(projection)({type: "Sphere"}), "M10,3.141593L0,3.141593L-10,3.141593L-10,-3.141593L-10,-3.141593L0,-3.141593L10,-3.141593L10,3.141593Z"); | ||
test.deepEqual(projection.clipExtent(), [[-10, -10], [10, 10]]); | ||
test.end(); | ||
}); | ||
|
||
tape("transverseMercator.clipExtent(extent).translate(translate) updates the intersected clip extent", function(test) { | ||
var projection = d3.geoTransverseMercator().scale(1).clipExtent([[-10, -10], [10, 10]]).translate([0, 0]).precision(0); | ||
test.pathEqual(d3.geoPath(projection)({type: "Sphere"}), "M10,3.141593L0,3.141593L-10,3.141593L-10,-3.141593L-10,-3.141593L0,-3.141593L10,-3.141593L10,3.141593Z"); | ||
test.deepEqual(projection.clipExtent(), [[-10, -10], [10, 10]]); | ||
test.end(); | ||
}); | ||
|
||
tape("transverseMercator.rotate(…) does not affect the automatic clip extent", function(test) { | ||
var projection = d3.geoTransverseMercator(), object = { | ||
type: "MultiPoint", | ||
coordinates: [ | ||
[-82.35024908550241, 29.649391549778745], | ||
[-82.35014449996858, 29.65075946917633], | ||
[-82.34916073446641, 29.65070265688781], | ||
[-82.3492653331286, 29.64933474064504] | ||
] | ||
}; | ||
projection.fitExtent([[0, 0], [960, 600]], object); | ||
test.deepEqual(projection.scale(), 15724992.330511674); | ||
test.deepEqual(projection.translate(), [20418843.897824813, 21088401.790971387]); | ||
projection.rotate([0, 95]).fitExtent([[0, 0], [960, 600]], object); | ||
test.deepEqual(projection.scale(), 15724992.330511674); | ||
test.deepEqual(projection.translate(), [20418843.897824813, 47161426.43770847]); | ||
test.end(); | ||
}); |