| 1 |
var tape = require("tape"), |
| 2 |
extract = require("../../lib/topojson/topology/extract"); |
| 3 |
|
| 4 |
tape("extract copies coordinates sequentially into a buffer", function(test) { |
| 5 |
var topology = extract({ |
| 6 |
foo: { |
| 7 |
type: "LineString", |
| 8 |
coordinates: [[0, 0], [1, 0], [2, 0]] |
| 9 |
}, |
| 10 |
bar: { |
| 11 |
type: "LineString", |
| 12 |
coordinates: [[0, 0], [1, 0], [2, 0]] |
| 13 |
} |
| 14 |
}); |
| 15 |
test.deepEqual(topology.coordinates, [[0, 0], [1, 0], [2, 0], [0, 0], [1, 0], [2, 0]]); |
| 16 |
test.end(); |
| 17 |
}); |
| 18 |
|
| 19 |
tape("extract does not copy point geometries into the coordinate buffer", function(test) { |
| 20 |
var topology = extract({ |
| 21 |
foo: { |
| 22 |
type: "Point", |
| 23 |
coordinates: [0, 0] |
| 24 |
}, |
| 25 |
bar: { |
| 26 |
type: "MultiPoint", |
| 27 |
coordinates: [[0, 0], [1, 0], [2, 0]] |
| 28 |
} |
| 29 |
}); |
| 30 |
test.deepEqual(topology.coordinates, []); |
| 31 |
test.deepEqual(topology.objects.foo.coordinates, [0, 0]); |
| 32 |
test.deepEqual(topology.objects.bar.coordinates, [[0, 0], [1, 0], [2, 0]]); |
| 33 |
test.end(); |
| 34 |
}); |
| 35 |
|
| 36 |
tape("extract includes closing coordinates in polygons", function(test) { |
| 37 |
var topology = extract({ |
| 38 |
foo: { |
| 39 |
type: "Polygon", |
| 40 |
coordinates: [[[0, 0], [1, 0], [2, 0], [0, 0]]] |
| 41 |
} |
| 42 |
}); |
| 43 |
test.deepEqual(topology.coordinates, [[0, 0], [1, 0], [2, 0], [0, 0]]); |
| 44 |
test.end(); |
| 45 |
}); |
| 46 |
|
| 47 |
tape("extract represents lines as contiguous slices of the coordinate buffer", function(test) { |
| 48 |
var topology = extract({ |
| 49 |
foo: { |
| 50 |
type: "LineString", |
| 51 |
coordinates: [[0, 0], [1, 0], [2, 0]] |
| 52 |
}, |
| 53 |
bar: { |
| 54 |
type: "LineString", |
| 55 |
coordinates: [[0, 0], [1, 0], [2, 0]] |
| 56 |
} |
| 57 |
}); |
| 58 |
test.deepEqual(topology.objects, { |
| 59 |
foo: { |
| 60 |
type: "LineString", |
| 61 |
arcs: [0, 2] |
| 62 |
}, |
| 63 |
bar: { |
| 64 |
type: "LineString", |
| 65 |
arcs: [3, 5] |
| 66 |
} |
| 67 |
}); |
| 68 |
test.end(); |
| 69 |
}); |
| 70 |
|
| 71 |
tape("extract represents rings as contiguous slices of the coordinate buffer", function(test) { |
| 72 |
var topology = extract({ |
| 73 |
foo: { |
| 74 |
type: "Polygon", |
| 75 |
coordinates: [[[0, 0], [1, 0], [2, 0], [0, 0]]] |
| 76 |
}, |
| 77 |
bar: { |
| 78 |
type: "Polygon", |
| 79 |
coordinates: [[[0, 0], [1, 0], [2, 0], [0, 0]]] |
| 80 |
} |
| 81 |
}); |
| 82 |
test.deepEqual(topology.objects, { |
| 83 |
foo: { |
| 84 |
type: "Polygon", |
| 85 |
arcs: [[0, 3]] |
| 86 |
}, |
| 87 |
bar: { |
| 88 |
type: "Polygon", |
| 89 |
arcs: [[4, 7]] |
| 90 |
} |
| 91 |
}); |
| 92 |
test.end(); |
| 93 |
}); |
| 94 |
|
| 95 |
tape("extract exposes the constructed lines and rings in the order of construction", function(test) { |
| 96 |
var topology = extract({ |
| 97 |
line: { |
| 98 |
type: "LineString", |
| 99 |
coordinates: [[0, 0], [1, 0], [2, 0]] |
| 100 |
}, |
| 101 |
multiline: { |
| 102 |
type: "MultiLineString", |
| 103 |
coordinates: [[[0, 0], [1, 0], [2, 0]]] |
| 104 |
}, |
| 105 |
polygon: { |
| 106 |
type: "Polygon", |
| 107 |
coordinates: [[[0, 0], [1, 0], [2, 0], [0, 0]]] |
| 108 |
} |
| 109 |
}); |
| 110 |
test.deepEqual(topology.lines, [ |
| 111 |
[0, 2], |
| 112 |
[3, 5] |
| 113 |
]); |
| 114 |
test.deepEqual(topology.rings, [ |
| 115 |
[6, 9] |
| 116 |
]); |
| 117 |
test.end(); |
| 118 |
}); |
| 119 |
|
| 120 |
tape("extract supports nested geometry collections", function(test) { |
| 121 |
var topology = extract({ |
| 122 |
foo: { |
| 123 |
type: "GeometryCollection", |
| 124 |
geometries: [{ |
| 125 |
type: "GeometryCollection", |
| 126 |
geometries: [{ |
| 127 |
type: "LineString", |
| 128 |
coordinates: [[0, 0], [0, 1]] |
| 129 |
}] |
| 130 |
}] |
| 131 |
} |
| 132 |
}); |
| 133 |
test.deepEqual(topology.objects.foo, { |
| 134 |
type: "GeometryCollection", |
| 135 |
geometries: [{ |
| 136 |
type: "GeometryCollection", |
| 137 |
geometries: [{ |
| 138 |
type: "LineString", |
| 139 |
arcs: [0, 1] |
| 140 |
}] |
| 141 |
}] |
| 142 |
}); |
| 143 |
test.end(); |
| 144 |
}); |