Add tests for d3.geo.length.
Also return the perimeter for polygons.
This commit is contained in:
Родитель
2c019c300c
Коммит
f4a4d700dc
|
@ -6485,12 +6485,8 @@ d3 = function() {
|
|||
point: d3_noop,
|
||||
lineStart: d3_geo_lengthLineStart,
|
||||
lineEnd: d3_noop,
|
||||
polygonStart: function() {
|
||||
d3_geo_length.lineStart = d3_noop;
|
||||
},
|
||||
polygonEnd: function() {
|
||||
d3_geo_length.lineStart = d3_geo_lengthLineStart;
|
||||
}
|
||||
polygonStart: d3_noop,
|
||||
polygonEnd: d3_noop
|
||||
};
|
||||
function d3_geo_lengthLineStart() {
|
||||
var λ0, sinφ0, cosφ0;
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -11,15 +11,10 @@ var d3_geo_length = {
|
|||
point: d3_noop,
|
||||
lineStart: d3_geo_lengthLineStart,
|
||||
lineEnd: d3_noop,
|
||||
polygonStart: function() {
|
||||
d3_geo_length.lineStart = d3_noop;
|
||||
},
|
||||
polygonEnd: function() {
|
||||
d3_geo_length.lineStart = d3_geo_lengthLineStart;
|
||||
}
|
||||
polygonStart: d3_noop,
|
||||
polygonEnd: d3_noop
|
||||
};
|
||||
|
||||
|
||||
function d3_geo_lengthLineStart() {
|
||||
var λ0, sinφ0, cosφ0;
|
||||
|
||||
|
@ -27,6 +22,7 @@ function d3_geo_lengthLineStart() {
|
|||
λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
|
||||
d3_geo_length.point = nextPoint;
|
||||
};
|
||||
|
||||
d3_geo_length.lineEnd = function() {
|
||||
d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
require("../env");
|
||||
|
||||
var vows = require("vows"),
|
||||
assert = require("assert");
|
||||
|
||||
var suite = vows.describe("d3.geo.length");
|
||||
|
||||
var π = Math.PI;
|
||||
|
||||
suite.addBatch({
|
||||
"length": {
|
||||
topic: function() {
|
||||
return d3.geo.length;
|
||||
},
|
||||
"the length of points are zero": function(length) {
|
||||
assert.inDelta(length({type: "Point", coordinates: [0, 0]}), 0, 1e-6);
|
||||
assert.inDelta(length({type: "MultiPoint", coordinates: [[0, 1], [2, 3]]}), 0, 1e-6);
|
||||
},
|
||||
"the length of a line string is the sum of its great arc segments": function(length) {
|
||||
assert.inDelta(length({type: "LineString", coordinates: [[-45, 0], [45, 0]]}), Math.PI / 2, 1e-6);
|
||||
assert.inDelta(length({type: "LineString", coordinates: [[-45, 0], [-30, 0], [-15, 0], [0, 0]]}), Math.PI / 4, 1e-6);
|
||||
assert.inDelta(length({type: "MultiLineString", coordinates: [[[-45, 0], [-30, 0]], [[-15, 0], [0, 0]]]}), Math.PI / 6, 1e-6);
|
||||
},
|
||||
"the length of a polygon is its perimeter": function(length) {
|
||||
assert.inDelta(length({type: "Polygon", coordinates: [[[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]]]}), 0.157008, 1e-6);
|
||||
assert.inDelta(length({type: "MultiPolygon", coordinates: [[[[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]]]]}), 0.157008, 1e-6);
|
||||
assert.inDelta(length({type: "MultiPolygon", coordinates: [[[[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]]], [[[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]]]}), 0.209354, 1e-6);
|
||||
},
|
||||
"the length of a polygon is its perimeter, including holes": function(length) {
|
||||
assert.inDelta(length({type: "Polygon", coordinates: [[[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]], [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]]}), 0.209354, 1e-6);
|
||||
},
|
||||
"the length of a feature collection is the sum of its features": function(length) {
|
||||
assert.inDelta(length({type: "FeatureCollection", features: [
|
||||
{type: "Feature", geometry: {type: "LineString", coordinates: [[-45, 0], [0, 0]]}},
|
||||
{type: "Feature", geometry: {type: "LineString", coordinates: [[0, 0], [45, 0]]}}
|
||||
]}), Math.PI / 2, 1e-6);
|
||||
},
|
||||
"the length of a geometry collection is the sum of its geometries": function(length) {
|
||||
assert.inDelta(length({type: "GeometryCollection", geometries: [
|
||||
{type: "GeometryCollection", geometries: [{type: "LineString", coordinates: [[-45, 0], [0, 0]]}]},
|
||||
{type: "LineString", coordinates: [[0, 0], [45, 0]]}
|
||||
]}), Math.PI / 2, 1e-6);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
suite.export(module);
|
Загрузка…
Ссылка в новой задаче