Commit 480bfb6c authored by Mike Bostock's avatar Mike Bostock
Browse files

Refactor geo tests for minimal loading.

parent ae9d4a40
......@@ -7,27 +7,27 @@ var suite = vows.describe("d3.geo.albers");
suite.addBatch({
"albers": {
topic: load("geo/albers"),
topic: load("geo/albers").expression("d3.geo.albers"),
"default": projectionTestSuite({
topic: function(d3) { return d3.geo.albers(); },
"has the parallels 29.5°, 45.5°": function(albers) {
assert.inDelta(albers.parallels(), [29.5, 45.5], 1e-6);
topic: function(projection) { return projection(); },
"has the parallels 29.5°, 45.5°": function(p) {
assert.inDelta(p.parallels(), [29.5, 45.5], 1e-6);
},
"has the rotation 98°, 0°": function(albers) {
assert.inDelta(albers.rotate(), [98, 0, 0], 1e-6);
"has the rotation 98°, 0°": function(p) {
assert.inDelta(p.rotate(), [98, 0, 0], 1e-6);
},
"has the center 0°, 38°": function(albers) {
assert.inDelta(albers.center(), [0, 38], 1e-6);
"has the center 0°, 38°": function(p) {
assert.inDelta(p.center(), [0, 38], 1e-6);
},
"has the scale 1000": function(albers) {
assert.inDelta(albers.scale(), 1000, 1e-6);
"has the scale 1000": function(p) {
assert.inDelta(p.scale(), 1000, 1e-6);
}
}, {
"Washington, DC": [[-120.50000000, 47.50000000], [ 215.47899724, 51.97649392]],
"San Francisco, CA": [[-122.42000000, 37.78000000], [ 150.07267740, 211.25782936]]
}),
"translated to 0,0 and at scale 1": projectionTestSuite({
topic: function(d3) { return d3.geo.albers().translate([0, 0]).scale(1); }
topic: function(projection) { return projection().translate([0, 0]).scale(1); }
}, {
"Washington, DC": [[-120.50000000, 47.50000000], [ -0.26452100, -0.19802351]],
"San Francisco, CA": [[-122.42000000, 37.78000000], [ -0.32992732, -0.03874217]]
......
......@@ -7,11 +7,11 @@ var suite = vows.describe("d3.geo.albersUsa");
suite.addBatch({
"albersUsa": {
topic: load("geo/albers-usa"),
topic: load("geo/albers-usa").expression("d3.geo.albersUsa"),
"default": projectionTestSuite({
topic: function(d3) { return d3.geo.albersUsa(); },
"has the scale 1000": function(albers) {
assert.inDelta(albers.scale(), 1000, 1e-6);
topic: function(projection) { return projection(); },
"has the scale 1000": function(p) {
assert.inDelta(p.scale(), 1000, 1e-6);
}
}, {
"Washington, DC": [[-120.50000000, 47.50000000], [ 215.47899724, 51.97649392]],
......@@ -21,7 +21,7 @@ suite.addBatch({
"San Juan, PR": [[ -66.07000000, 18.45000000], [ 909.15925090, 456.39482719]]
}),
"translated to 0,0 and at scale 1": projectionTestSuite({
topic: function(d3) { return d3.geo.albersUsa().translate([0, 0]).scale(1); }
topic: function(projection) { return projection().translate([0, 0]).scale(1); }
}, {
"Washington, DC": [[-120.50000000, 47.50000000], [ -0.26452100, -0.19802351]],
"San Francisco, CA": [[-122.42000000, 37.78000000], [ -0.32992732, -0.03874217]],
......
var vows = require("vows"),
d3 = require("../../"),
load = require("../load"),
assert = require("../env-assert");
......@@ -8,96 +9,96 @@ var π = Math.PI;
suite.addBatch({
"area": {
topic: load("geo/area", "geo/circle", "geo/graticule", "arrays/range"),
"Point": function(d3) {
assert.equal(d3.geo.area({type: "Point", coordinates: [0, 0]}), 0);
topic: load("geo/area").expression("d3.geo.area"),
"Point": function(area) {
assert.equal(area({type: "Point", coordinates: [0, 0]}), 0);
},
"MultiPoint": function(d3) {
assert.equal(d3.geo.area({type: "MultiPoint", coordinates: [[0, 1], [2, 3]]}), 0);
"MultiPoint": function(area) {
assert.equal(area({type: "MultiPoint", coordinates: [[0, 1], [2, 3]]}), 0);
},
"LineString": function(d3) {
assert.equal(d3.geo.area({type: "LineString", coordinates: [[0, 1], [2, 3]]}), 0);
"LineString": function(area) {
assert.equal(area({type: "LineString", coordinates: [[0, 1], [2, 3]]}), 0);
},
"MultiLineString": function(d3) {
assert.equal(d3.geo.area({type: "MultiLineString", coordinates: [[[0, 1], [2, 3]], [[4, 5], [6, 7]]]}), 0);
"MultiLineString": function(area) {
assert.equal(area({type: "MultiLineString", coordinates: [[[0, 1], [2, 3]], [[4, 5], [6, 7]]]}), 0);
},
"Polygon": {
"tiny": function(d3) {
assert.inDelta(d3.geo.area({type: "Polygon", coordinates: [[
"tiny": function(area) {
assert.inDelta(area({type: "Polygon", coordinates: [[
[-64.66070178517852, 18.33986913231323],
[-64.66079715091509, 18.33994007490749],
[-64.66074946804680, 18.33994007490749],
[-64.66070178517852, 18.33986913231323]
]]}), 4.890516e-13, 1e-13);
},
"semilune": function(d3) {
assert.inDelta(d3.geo.area({type: "Polygon", coordinates: [[[0, 0], [0, 90], [90, 0], [0, 0]]]}), π / 2, 1e-6);
"semilune": function(area) {
assert.inDelta(area({type: "Polygon", coordinates: [[[0, 0], [0, 90], [90, 0], [0, 0]]]}), π / 2, 1e-6);
},
"lune": function(d3) {
assert.equal(d3.geo.area({type: "Polygon", coordinates: [[[0, 0], [0, 90], [90, 0], [0, -90], [0, 0]]]}), π);
"lune": function(area) {
assert.equal(area({type: "Polygon", coordinates: [[[0, 0], [0, 90], [90, 0], [0, -90], [0, 0]]]}), π);
},
"hemispheres": {
"North": function(d3) {
assert.inDelta(d3.geo.area({type: "Polygon", coordinates: [[[0, 0], [-90, 0], [180, 0], [90, 0], [0, 0]]]}), 2 * π, 1e-6);
"North": function(area) {
assert.inDelta(area({type: "Polygon", coordinates: [[[0, 0], [-90, 0], [180, 0], [90, 0], [0, 0]]]}), 2 * π, 1e-6);
},
"South": function(d3) {
assert.inDelta(d3.geo.area({type: "Polygon", coordinates: [[[0, 0], [90, 0], [180, 0], [-90, 0], [0, 0]]]}), 2 * π, 1e-6);
"South": function(area) {
assert.inDelta(area({type: "Polygon", coordinates: [[[0, 0], [90, 0], [180, 0], [-90, 0], [0, 0]]]}), 2 * π, 1e-6);
},
"East": function(d3) {
assert.equal(d3.geo.area({type: "Polygon", coordinates: [[[0, 0], [0, 90], [180, 0], [0, -90], [0, 0]]]}), 2 * π);
"East": function(area) {
assert.equal(area({type: "Polygon", coordinates: [[[0, 0], [0, 90], [180, 0], [0, -90], [0, 0]]]}), 2 * π);
},
"West": function(d3) {
assert.equal(d3.geo.area({type: "Polygon", coordinates: [[[0, 0], [0, -90], [180, 0], [0, 90], [0, 0]]]}), 2 * π);
"West": function(area) {
assert.equal(area({type: "Polygon", coordinates: [[[0, 0], [0, -90], [180, 0], [0, 90], [0, 0]]]}), 2 * π);
}
},
"graticule outline": {
"sphere": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.graticule().extent([[-180, -90], [180, 90]]).outline()), 4 * π, 1e-5);
"sphere": function(area) {
assert.inDelta(area(d3.geo.graticule().extent([[-180, -90], [180, 90]]).outline()), 4 * π, 1e-5);
},
"hemisphere": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.graticule().extent([[-180, 0], [180, 90]]).outline()), 2 * π, 1e-5);
"hemisphere": function(area) {
assert.inDelta(area(d3.geo.graticule().extent([[-180, 0], [180, 90]]).outline()), 2 * π, 1e-5);
},
"semilune": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.graticule().extent([[0, 0], [90, 90]]).outline()), π / 2, 1e-5);
"semilune": function(area) {
assert.inDelta(area(d3.geo.graticule().extent([[0, 0], [90, 90]]).outline()), π / 2, 1e-5);
}
},
"circles": {
"hemisphere": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.circle().angle(90)()), 2 * π, 1e-5);
"hemisphere": function(area) {
assert.inDelta(area(d3.geo.circle().angle(90)()), 2 * π, 1e-5);
},
"60°": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.circle().angle(60).precision(.1)()), π, 1e-5);
"60°": function(area) {
assert.inDelta(area(d3.geo.circle().angle(60).precision(.1)()), π, 1e-5);
},
"60° North": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.circle().angle(60).precision(.1).origin([0, 90])()), π, 1e-5);
"60° North": function(area) {
assert.inDelta(area(d3.geo.circle().angle(60).precision(.1).origin([0, 90])()), π, 1e-5);
},
"45°": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.circle().angle(45).precision(.1)()), π * (2 - Math.SQRT2), 1e-5);
"45°": function(area) {
assert.inDelta(area(d3.geo.circle().angle(45).precision(.1)()), π * (2 - Math.SQRT2), 1e-5);
},
"45° North": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.circle().angle(45).precision(.1).origin([0, 90])()), π * (2 - Math.SQRT2), 1e-5);
"45° North": function(area) {
assert.inDelta(area(d3.geo.circle().angle(45).precision(.1).origin([0, 90])()), π * (2 - Math.SQRT2), 1e-5);
},
"45° South": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.circle().angle(45).precision(.1).origin([0, -90])()), π * (2 - Math.SQRT2), 1e-5);
"45° South": function(area) {
assert.inDelta(area(d3.geo.circle().angle(45).precision(.1).origin([0, -90])()), π * (2 - Math.SQRT2), 1e-5);
},
"135°": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.circle().angle(135).precision(.1)()), π * (2 + Math.SQRT2), 1e-5);
"135°": function(area) {
assert.inDelta(area(d3.geo.circle().angle(135).precision(.1)()), π * (2 + Math.SQRT2), 1e-5);
},
"135° North": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.circle().angle(135).precision(.1).origin([0, 90])()), π * (2 + Math.SQRT2), 1e-5);
"135° North": function(area) {
assert.inDelta(area(d3.geo.circle().angle(135).precision(.1).origin([0, 90])()), π * (2 + Math.SQRT2), 1e-5);
},
"135° South": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.circle().angle(135).precision(.1).origin([0, -90])()), π * (2 + Math.SQRT2), 1e-5);
"135° South": function(area) {
assert.inDelta(area(d3.geo.circle().angle(135).precision(.1).origin([0, -90])()), π * (2 + Math.SQRT2), 1e-5);
},
"tiny": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.circle().angle(1e-6).precision(.1)()), 0, 1e-6);
"tiny": function(area) {
assert.inDelta(area(d3.geo.circle().angle(1e-6).precision(.1)()), 0, 1e-6);
},
"huge": function(d3) {
assert.inDelta(d3.geo.area(d3.geo.circle().angle(180 - 1e-6).precision(.1)()), 4 * π, 1e-6);
"huge": function(area) {
assert.inDelta(area(d3.geo.circle().angle(180 - 1e-6).precision(.1)()), 4 * π, 1e-6);
},
"60° with 45° hole": function(d3) {
"60° with 45° hole": function(area) {
var circle = d3.geo.circle().precision(.1);
assert.inDelta(d3.geo.area({
assert.inDelta(area({
type: "Polygon",
coordinates: [
circle.angle(60)().coordinates[0],
......@@ -105,9 +106,9 @@ suite.addBatch({
]
}), π * (Math.SQRT2 - 1), 1e-5);
},
"45° holes at [0°, 0°] and [0°, 90°]": function(d3) {
"45° holes at [0°, 0°] and [0°, 90°]": function(area) {
var circle = d3.geo.circle().precision(.1).angle(45);
assert.inDelta(d3.geo.area({
assert.inDelta(area({
type: "Polygon",
coordinates: [
circle.origin([0, 0])().coordinates[0].reverse(),
......@@ -115,9 +116,9 @@ suite.addBatch({
]
}), π * 2 * Math.SQRT2, 1e-5);
},
"45° holes at [0°, 90°] and [0°, 0°]": function(d3) {
"45° holes at [0°, 90°] and [0°, 0°]": function(area) {
var circle = d3.geo.circle().precision(.1).angle(45);
assert.inDelta(d3.geo.area({
assert.inDelta(area({
type: "Polygon",
coordinates: [
circle.origin([0, 90])().coordinates[0].reverse(),
......@@ -127,36 +128,36 @@ suite.addBatch({
}
},
"stripes": {
"45°, -45°": function(d3) {
assert.inDelta(d3.geo.area(stripes(d3, 45, -45)), π * 2 * Math.SQRT2, 1e-5);
"45°, -45°": function(area) {
assert.inDelta(area(stripes(d3, 45, -45)), π * 2 * Math.SQRT2, 1e-5);
},
"-45°, 45°": function(d3) {
assert.inDelta(d3.geo.area(stripes(d3, -45, 45)), π * 2 * (2 - Math.SQRT2), 1e-5);
"-45°, 45°": function(area) {
assert.inDelta(area(stripes(d3, -45, 45)), π * 2 * (2 - Math.SQRT2), 1e-5);
},
"45°, 30°": function(d3) {
assert.inDelta(d3.geo.area(stripes(d3, 45, 30)), π * (Math.SQRT2 - 1), 1e-5);
"45°, 30°": function(area) {
assert.inDelta(area(stripes(d3, 45, 30)), π * (Math.SQRT2 - 1), 1e-5);
}
}
},
"MultiPolygon": {
"two hemispheres": function(d3) {
assert.equal(d3.geo.area({type: "MultiPolygon", coordinates: [
"two hemispheres": function(area) {
assert.equal(area({type: "MultiPolygon", coordinates: [
[[[0, 0], [-90, 0], [180, 0], [90, 0], [0, 0]]],
[[[0, 0], [90, 0], [180, 0], [-90, 0], [0, 0]]]
]}), 4 * π);
}
},
"Sphere": function(d3) {
assert.equal(d3.geo.area({type: "Sphere"}), 4 * π);
"Sphere": function(area) {
assert.equal(area({type: "Sphere"}), 4 * π);
},
"GeometryCollection": function(d3) {
assert.equal(d3.geo.area({type: "GeometryCollection", geometries: [{type: "Sphere"}]}), 4 * π);
"GeometryCollection": function(area) {
assert.equal(area({type: "GeometryCollection", geometries: [{type: "Sphere"}]}), 4 * π);
},
"FeatureCollection": function(d3) {
assert.equal(d3.geo.area({type: "FeatureCollection", features: [{type: "Feature", geometry: {type: "Sphere"}}]}), 4 * π);
"FeatureCollection": function(area) {
assert.equal(area({type: "FeatureCollection", features: [{type: "Feature", geometry: {type: "Sphere"}}]}), 4 * π);
},
"Feature": function(d3) {
assert.equal(d3.geo.area({type: "Feature", geometry: {type: "Sphere"}}), 4 * π);
"Feature": function(area) {
assert.equal(area({type: "Feature", geometry: {type: "Sphere"}}), 4 * π);
}
}
});
......
......@@ -7,9 +7,9 @@ var suite = vows.describe("d3.geo.azimuthalEqualArea");
suite.addBatch({
"azimuthalEqualArea": {
topic: load("geo/azimuthal-equal-area"),
topic: load("geo/azimuthal-equal-area").expression("d3.geo.azimuthalEqualArea"),
"default": projectionTestSuite({
topic: function(d3) { return d3.geo.azimuthalEqualArea(); }
topic: function(projection) { return projection(); }
}, {
"Null Island": [[ 0.00000000, 0.00000000], [ 480.00000000, 250.00000000]],
"Honolulu, HI": [[ -21.01262744, 82.63349103], [ 470.78325089, 51.18095336]],
......@@ -21,7 +21,7 @@ suite.addBatch({
"the North Pole": [[ 0.00000000, 85.00000000], [ 480.00000000, 47.32293772]]
}),
"translated to 0,0 and at scale 1": projectionTestSuite({
topic: function(d3) { return d3.geo.azimuthalEqualArea().translate([0, 0]).scale(1); }
topic: function(projection) { return projection().translate([0, 0]).scale(1); }
}, {
"Null Island": [[ 0.00000000, 0.00000000], [ 0.00000000, 0.00000000]],
"Honolulu, HI": [[ -21.01262744, 82.63349120], [ -0.06144499, -1.32546031]],
......
......@@ -7,9 +7,9 @@ var suite = vows.describe("d3.geo.azimuthalEquidistant");
suite.addBatch({
"azimuthalEquidistant": {
topic: load("geo/azimuthal-equidistant"),
topic: load("geo/azimuthal-equidistant").expression("d3.geo.azimuthalEquidistant"),
"default": projectionTestSuite({
topic: function(d3) { return d3.geo.azimuthalEquidistant(); }
topic: function(projection) { return projection(); }
}, {
"Null Island": [[ 0.00000000, 0.00000000], [ 480.00000000, 250.00000000]],
"Honolulu, HI": [[ -21.01262744, 82.63349103], [ 469.92237700, 32.61061747]],
......@@ -21,7 +21,7 @@ suite.addBatch({
"the North Pole": [[ 0.00000000, 85.00000000], [ 480.00000000, 27.47052037]],
}),
"translated to 0,0 and at scale 1": projectionTestSuite({
topic: function(d3) { return d3.geo.azimuthalEquidistant().translate([0, 0]).scale(1); }
topic: function(projection) { return projection().translate([0, 0]).scale(1); }
}, {
"Null Island": [[ 0.00000000, 0.00000000], [ 0.00000000, 0.00000000]],
"Honolulu, HI": [[ -21.01262744, 82.63349120], [ -0.06718415, -1.44926255]],
......
......@@ -6,9 +6,9 @@ var suite = vows.describe("d3.geo.bounds");
suite.addBatch({
"bounds": {
topic: load("geo/bounds"),
"Feature": function(d3) {
assert.deepEqual(d3.geo.bounds({
topic: load("geo/bounds").expression("d3.geo.bounds"),
"Feature": function(bounds) {
assert.deepEqual(bounds({
type: "Feature",
geometry: {
type: "MultiPoint",
......@@ -16,8 +16,8 @@ suite.addBatch({
}
}), [[-123, 38], [-122, 39]])
},
"FeatureCollection": function(d3) {
assert.deepEqual(d3.geo.bounds({
"FeatureCollection": function(bounds) {
assert.deepEqual(bounds({
type: "FeatureCollection",
features: [
{
......@@ -37,8 +37,8 @@ suite.addBatch({
]
}), [[-123, 38], [-122, 39]])
},
"GeometryCollection": function(d3) {
assert.deepEqual(d3.geo.bounds({
"GeometryCollection": function(bounds) {
assert.deepEqual(bounds({
type: "GeometryCollection",
geometries: [
{
......@@ -52,44 +52,44 @@ suite.addBatch({
]
}), [[-123, 38], [-122, 39]])
},
"LineString": function(d3) {
assert.deepEqual(d3.geo.bounds({
"LineString": function(bounds) {
assert.deepEqual(bounds({
type: "LineString",
coordinates: [[-123, 39], [-122, 38]]
}), [[-123, 38], [-122, 39]])
},
"MultiLineString": function(d3) {
assert.deepEqual(d3.geo.bounds({
"MultiLineString": function(bounds) {
assert.deepEqual(bounds({
type: "MultiLineString",
coordinates: [[[-123, 39], [-122, 38]]]
}), [[-123, 38], [-122, 39]])
},
"MultiPoint": function(d3) {
assert.deepEqual(d3.geo.bounds({
"MultiPoint": function(bounds) {
assert.deepEqual(bounds({
type: "MultiPoint",
coordinates: [[-123, 39], [-122, 38]]
}), [[-123, 38], [-122, 39]])
},
"MultiPolygon": function(d3) {
assert.deepEqual(d3.geo.bounds({
"MultiPolygon": function(bounds) {
assert.deepEqual(bounds({
type: "MultiPolygon",
coordinates: [[[[-123, 39], [-122, 39], [-122, 38], [-123, 39]], [[10, 20], [20, 20], [20, 10], [10, 10], [10, 20]]]]
}), [[-123, 38], [-122, 39]])
},
"Point": function(d3) {
assert.deepEqual(d3.geo.bounds({
"Point": function(bounds) {
assert.deepEqual(bounds({
type: "Point",
coordinates: [-123, 39]
}), [[-123, 39], [-123, 39]])
},
"Polygon": function(d3) {
assert.deepEqual(d3.geo.bounds({
"Polygon": function(bounds) {
assert.deepEqual(bounds({
type: "Polygon",
coordinates: [[[-123, 39], [-122, 39], [-122, 38], [-123, 39]], [[10, 20], [20, 20], [20, 10], [10, 10], [10, 20]]]
}), [[-123, 38], [-122, 39]])
},
"NestedCollection": function(d3) {
assert.deepEqual(d3.geo.bounds({
"NestedCollection": function(bounds) {
assert.deepEqual(bounds({
type: "FeatureCollection",
features: [
{
......
var vows = require("vows"),
d3 = require("../../"),
load = require("../load"),
assert = require("../env-assert");
......@@ -6,90 +7,90 @@ var suite = vows.describe("d3.geo.centroid");
suite.addBatch({
"centroid": {
topic: load("geo/centroid", "arrays/range"),
"Point": function(d3) {
assert.deepEqual(d3.geo.centroid({type: "Point", coordinates: [0, 0]}), [0, 0]);
topic: load("geo/centroid").expression("d3.geo.centroid"),
"Point": function(centroid) {
assert.deepEqual(centroid({type: "Point", coordinates: [0, 0]}), [0, 0]);
},
"MultiPoint": {
"": function(d3) {
assert.inDelta(d3.geo.centroid({type: "MultiPoint", coordinates: [[0, 0], [1, 2]]}), [0.499847, 1.000038], 1e-6);
"": function(centroid) {
assert.inDelta(centroid({type: "MultiPoint", coordinates: [[0, 0], [1, 2]]}), [0.499847, 1.000038], 1e-6);
},
"antimeridian": function(d3) {
assert.deepEqual(d3.geo.centroid({type: "MultiPoint", coordinates: [[179, 0], [-179, 0]]}), [180, 0]);
"antimeridian": function(centroid) {
assert.deepEqual(centroid({type: "MultiPoint", coordinates: [[179, 0], [-179, 0]]}), [180, 0]);
},
"rings": {
"equator": function(d3) {
assert.isUndefined(d3.geo.centroid({type: "MultiPoint", coordinates: [[0, 0], [90, 0], [180, 0], [-90, 0]]}));
"equator": function(centroid) {
assert.isUndefined(centroid({type: "MultiPoint", coordinates: [[0, 0], [90, 0], [180, 0], [-90, 0]]}));
},
"polar": function(d3) {
assert.isUndefined(d3.geo.centroid({type: "MultiPoint", coordinates: [[0, 0], [0, 90], [180, 0], [0, -90]]}));
"polar": function(centroid) {
assert.isUndefined(centroid({type: "MultiPoint", coordinates: [[0, 0], [0, 90], [180, 0], [0, -90]]}));
}
}
},
"LineString": function(d3) {
assert.inDelta(d3.geo.centroid({type: "LineString", coordinates: [[0, 0], [1, 0]]}), [.5, 0], 1e-6);
assert.inDelta(d3.geo.centroid({type: "LineString", coordinates: [[0, 0], [0, 90]]}), [0, 45], 1e-6);
assert.inDelta(d3.geo.centroid({type: "LineString", coordinates: [[0, 0], [0, 45], [0, 90]]}), [0, 45], 1e-6);
assert.inDelta(d3.geo.centroid({type: "LineString", coordinates: [[-1, -1], [1, 1]]}), [0, 0], 1e-6);
assert.inDelta(d3.geo.centroid({type: "LineString", coordinates: [[-60, -1], [60, 1]]}), [0, 0], 1e-6);
assert.inDelta(d3.geo.centroid({type: "LineString", coordinates: [[179, -1], [-179, 1]]}), [180, 0], 1e-6);
assert.inDelta(d3.geo.centroid({type: "LineString", coordinates: [[-179, 0], [0, 0], [179, 0]]}), [0, 0], 1e-6);
assert.inDelta(d3.geo.centroid({type: "LineString", coordinates: [[-180, -90], [0, 0], [0, 90]]}), [0, 0], 1e-6);
assert.isUndefined(d3.geo.centroid({type: "LineString", coordinates: [[0, -90], [0, 90]]}));
"LineString": function(centroid) {
assert.inDelta(centroid({type: "LineString", coordinates: [[0, 0], [1, 0]]}), [.5, 0], 1e-6);
assert.inDelta(centroid({type: "LineString", coordinates: [[0, 0], [0, 90]]}), [0, 45], 1e-6);
assert.inDelta(centroid({type: "LineString", coordinates: [[0, 0], [0, 45], [0, 90]]}), [0, 45], 1e-6);
assert.inDelta(centroid({type: "LineString", coordinates: [[-1, -1], [1, 1]]}), [0, 0], 1e-6);
assert.inDelta(centroid({type: "LineString", coordinates: [[-60, -1], [60, 1]]}), [0, 0], 1e-6);
assert.inDelta(centroid({type: "LineString", coordinates: [[179, -1], [-179, 1]]}), [180, 0], 1e-6);
assert.inDelta(centroid({type: "LineString", coordinates: [[-179, 0], [0, 0], [179, 0]]}), [0, 0], 1e-6);
assert.inDelta(centroid({type: "LineString", coordinates: [[-180, -90], [0, 0], [0, 90]]}), [0, 0], 1e-6);
assert.isUndefined(centroid({type: "LineString", coordinates: [[0, -90], [0, 90]]}));
},
"MultiLineString": function(d3) {
assert.inDelta(d3.geo.centroid({type: "MultiLineString", coordinates: [[[0, 0], [0, 2]]]}), [0, 1], 1e-6);
"MultiLineString": function(centroid) {
assert.inDelta(centroid({type: "MultiLineString", coordinates: [[[0, 0], [0, 2]]]}), [0, 1], 1e-6);
},
"Polygon": function(d3) {
assert.inDelta(d3.geo.centroid({type: "Polygon", coordinates: [[[0, -90], [0, 0], [0, 90], [1, 0], [0, -90]]]}), [.5, 0], 1e-6);
//assert.inDelta(d3.geo.centroid(d3.geo.circle().angle(5).origin([0, 45])()), [0, 45], 1e-6);
assert.equal(d3.geo.centroid({type: "Polygon", coordinates: [d3.range(-180, 180 + 1 / 2, 1).map(function(x) { return [x, -60]; })]})[1], -90);
assert.inDelta(d3.geo.centroid({type: "Polygon", coordinates: [[[0, -10], [0, 10], [10, 10], [10, -10], [0, -10]]]}), [5, 0], 1e-6);
"Polygon": function(centroid) {
assert.inDelta(centroid({type: "Polygon", coordinates: [[[0, -90], [0, 0], [0, 90], [1, 0], [0, -90]]]}), [.5, 0], 1e-6);
//assert.inDelta(centroid(d3.geo.circle().angle(5).origin([0, 45])()), [0, 45], 1e-6);
assert.equal(centroid({type: "Polygon", coordinates: [d3.range(-180, 180 + 1 / 2, 1).map(function(x) { return [x, -60]; })]})[1], -90);
assert.inDelta(centroid({type: "Polygon", coordinates: [[[0, -10], [0, 10], [10, 10], [10, -10], [0, -10]]]}), [5, 0], 1e-6);
},
"MultiPolygon": function(d3) {
assert.inDelta(d3.geo.centroid({type: "MultiPolygon", coordinates: [[[[0, -90], [0, 0], [0, 90], [1, 0], [0, -90]]]]}), [.5, 0], 1e-6);
"MultiPolygon": function(centroid) {
assert.inDelta(centroid({type: "MultiPolygon", coordinates: [[[[0, -90], [0, 0], [0, 90], [1, 0], [0, -90]]]]}), [.5, 0], 1e-6);
},
"Sphere": function(d3) {
assert.isUndefined(d3.geo.centroid({type: "Sphere"}));
"Sphere": function(centroid) {
assert.isUndefined(centroid({type: "Sphere"}));
},
"Feature": function(d3) {
assert.deepEqual(d3.geo.centroid({type: "Feature", geometry: {type: "Point", coordinates: [0, 0]}}), [0, 0]);
"Feature": function(centroid) {
assert.deepEqual(centroid({type: "Feature", geometry: {type: "Point", coordinates: [0, 0]}}), [0, 0]);
},
"FeatureCollection": function(d3) {
assert.inDelta(d3.geo.centroid({type: "FeatureCollection", features: [
"FeatureCollection": function(centroid) {
assert.inDelta(centroid({type: "FeatureCollection", features: [
{type: "Feature", geometry: {type: "LineString"