|
| 1 | +require("../env"); |
| 2 | + |
| 3 | +var vows = require("vows"), |
| 4 | + assert = require("assert"); |
| 5 | + |
| 6 | +var suite = vows.describe("d3.geo.length"); |
| 7 | + |
| 8 | +var π = Math.PI; |
| 9 | + |
| 10 | +suite.addBatch({ |
| 11 | + "length": { |
| 12 | + topic: function() { |
| 13 | + return d3.geo.length; |
| 14 | + }, |
| 15 | + "the length of points are zero": function(length) { |
| 16 | + assert.inDelta(length({type: "Point", coordinates: [0, 0]}), 0, 1e-6); |
| 17 | + assert.inDelta(length({type: "MultiPoint", coordinates: [[0, 1], [2, 3]]}), 0, 1e-6); |
| 18 | + }, |
| 19 | + "the length of a line string is the sum of its great arc segments": function(length) { |
| 20 | + assert.inDelta(length({type: "LineString", coordinates: [[-45, 0], [45, 0]]}), Math.PI / 2, 1e-6); |
| 21 | + assert.inDelta(length({type: "LineString", coordinates: [[-45, 0], [-30, 0], [-15, 0], [0, 0]]}), Math.PI / 4, 1e-6); |
| 22 | + assert.inDelta(length({type: "MultiLineString", coordinates: [[[-45, 0], [-30, 0]], [[-15, 0], [0, 0]]]}), Math.PI / 6, 1e-6); |
| 23 | + }, |
| 24 | + "the length of a polygon is its perimeter": function(length) { |
| 25 | + assert.inDelta(length({type: "Polygon", coordinates: [[[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]]]}), 0.157008, 1e-6); |
| 26 | + assert.inDelta(length({type: "MultiPolygon", coordinates: [[[[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]]]]}), 0.157008, 1e-6); |
| 27 | + 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); |
| 28 | + }, |
| 29 | + "the length of a polygon is its perimeter, including holes": function(length) { |
| 30 | + 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); |
| 31 | + }, |
| 32 | + "the length of a feature collection is the sum of its features": function(length) { |
| 33 | + assert.inDelta(length({type: "FeatureCollection", features: [ |
| 34 | + {type: "Feature", geometry: {type: "LineString", coordinates: [[-45, 0], [0, 0]]}}, |
| 35 | + {type: "Feature", geometry: {type: "LineString", coordinates: [[0, 0], [45, 0]]}} |
| 36 | + ]}), Math.PI / 2, 1e-6); |
| 37 | + }, |
| 38 | + "the length of a geometry collection is the sum of its geometries": function(length) { |
| 39 | + assert.inDelta(length({type: "GeometryCollection", geometries: [ |
| 40 | + {type: "GeometryCollection", geometries: [{type: "LineString", coordinates: [[-45, 0], [0, 0]]}]}, |
| 41 | + {type: "LineString", coordinates: [[0, 0], [45, 0]]} |
| 42 | + ]}), Math.PI / 2, 1e-6); |
| 43 | + } |
| 44 | + } |
| 45 | +}); |
| 46 | + |
| 47 | +suite.export(module); |
0 commit comments