-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix d3.geo.interpolate for coincident points.
This also improves accuracy for small distances, using the haversine distance formula instead of the law of cosines. Fixes d3#1080.
- Loading branch information
1 parent
4648db5
commit 889aacc
Showing
6 changed files
with
47 additions
and
13 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,3 @@ | ||
function d3_geo_haversin(x) { | ||
return (x = Math.sin(x / 2)) * x; | ||
} |
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,25 @@ | ||
require("../env"); | ||
|
||
var vows = require("vows"), | ||
assert = require("assert"); | ||
|
||
var suite = vows.describe("d3.geo.interpolate"); | ||
|
||
suite.addBatch({ | ||
"interpolate": { | ||
topic: function() { | ||
return d3.geo.interpolate; | ||
}, | ||
"zero distance": function(arc) { | ||
assert.deepEqual(d3.geo.interpolate([140.63289, -29.95101], [140.63289, -29.95101])(.5), [140.63289, -29.95101]); | ||
}, | ||
"equator": function(arc) { | ||
assert.inDelta(d3.geo.interpolate([10, 0], [20, 0])(.5), [15, 0], 1e-6); | ||
}, | ||
"meridian": function(arc) { | ||
assert.inDelta(d3.geo.interpolate([10, -20], [10, 40])(.5), [10, 10], 1e-6); | ||
} | ||
} | ||
}); | ||
|
||
suite.export(module); |