| 1 |
var tape = require("tape"), |
| 2 |
extract = require("../../lib/topojson/topology/extract"), |
| 3 |
cut = require("../../lib/topojson/topology/cut"), |
| 4 |
dedup = require("../../lib/topojson/topology/dedup"); |
| 5 |
|
| 6 |
tape("dedup exact duplicate lines ABC & ABC share an arc", function(test) { |
| 7 |
var topology = dedup(cut(extract({ |
| 8 |
abc: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0]]}, |
| 9 |
abc2: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0]]} |
| 10 |
}))); |
| 11 |
test.deepEqual(topology.objects, { |
| 12 |
abc: {type: "LineString", arcs: {0: 0, 1: 2}}, |
| 13 |
abc2: {type: "LineString", arcs: {0: 0, 1: 2}} |
| 14 |
}); |
| 15 |
test.end(); |
| 16 |
}); |
| 17 |
|
| 18 |
tape("dedup reversed duplicate lines ABC & CBA share an arc", function(test) { |
| 19 |
var topology = dedup(cut(extract({ |
| 20 |
abc: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0]]}, |
| 21 |
cba: {type: "LineString", coordinates: [[2, 0], [1, 0], [0, 0]]} |
| 22 |
}))); |
| 23 |
test.deepEqual(topology.objects, { |
| 24 |
abc: {type: "LineString", arcs: {0: 0, 1: 2}}, |
| 25 |
cba: {type: "LineString", arcs: {0: 2, 1: 0}} |
| 26 |
}); |
| 27 |
test.end(); |
| 28 |
}); |
| 29 |
|
| 30 |
tape("dedup exact duplicate rings ABCA & ABCA share an arc", function(test) { |
| 31 |
var topology = dedup(cut(extract({ |
| 32 |
abca: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [2, 0], [0, 0]]]}, |
| 33 |
abca2: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [2, 0], [0, 0]]]} |
| 34 |
}))); |
| 35 |
test.deepEqual(topology.objects, { |
| 36 |
abca: {type: "Polygon", arcs: [{0: 0, 1: 3}]}, |
| 37 |
abca2: {type: "Polygon", arcs: [{0: 0, 1: 3}]} |
| 38 |
}); |
| 39 |
test.end(); |
| 40 |
}); |
| 41 |
|
| 42 |
tape("dedup reversed duplicate rings ACBA & ABCA share an arc", function(test) { |
| 43 |
var topology = dedup(cut(extract({ |
| 44 |
abca: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [2, 0], [0, 0]]]}, |
| 45 |
acba: {type: "Polygon", coordinates: [[[0, 0], [2, 0], [1, 0], [0, 0]]]} |
| 46 |
}))); |
| 47 |
test.deepEqual(topology.objects, { |
| 48 |
abca: {type: "Polygon", arcs: [{0: 0, 1: 3}]}, |
| 49 |
acba: {type: "Polygon", arcs: [{0: 3, 1: 0}]} |
| 50 |
}); |
| 51 |
test.end(); |
| 52 |
}); |
| 53 |
|
| 54 |
tape("dedup rotated duplicate rings BCAB & ABCA share an arc", function(test) { |
| 55 |
var topology = dedup(cut(extract({ |
| 56 |
abca: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [2, 0], [0, 0]]]}, |
| 57 |
bcab: {type: "Polygon", coordinates: [[[1, 0], [2, 0], [0, 0], [1, 0]]]} |
| 58 |
}))); |
| 59 |
test.deepEqual(topology.objects, { |
| 60 |
abca: {type: "Polygon", arcs: [{0: 0, 1: 3}]}, |
| 61 |
bcab: {type: "Polygon", arcs: [{0: 0, 1: 3}]} |
| 62 |
}); |
| 63 |
test.end(); |
| 64 |
}); |
| 65 |
|
| 66 |
tape("dedup ring ABCA & line ABCA have no cuts", function(test) { |
| 67 |
var topology = dedup(cut(extract({ |
| 68 |
abcaLine: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0], [0, 0]]}, |
| 69 |
abcaPolygon: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [2, 0], [0, 0]]]}, |
| 70 |
}))); |
| 71 |
test.deepEqual(topology.objects, { |
| 72 |
abcaLine: {type: "LineString", arcs: {0: 0, 1: 3}}, |
| 73 |
abcaPolygon: {type: "Polygon", arcs: [{0: 0, 1: 3}]} |
| 74 |
}); |
| 75 |
test.end(); |
| 76 |
}); |
| 77 |
|
| 78 |
tape("dedup ring BCAB & line ABCA have no cuts", function(test) { |
| 79 |
var topology = dedup(cut(extract({ |
| 80 |
abcaLine: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0], [0, 0]]}, |
| 81 |
bcabPolygon: {type: "Polygon", coordinates: [[[1, 0], [2, 0], [0, 0], [1, 0]]]}, |
| 82 |
}))); |
| 83 |
test.deepEqual(topology.objects, { |
| 84 |
abcaLine: {type: "LineString", arcs: {0: 0, 1: 3}}, |
| 85 |
bcabPolygon: {type: "Polygon", arcs: [{0: 0, 1: 3}]} |
| 86 |
}); |
| 87 |
test.deepEqual(topology.coordinates.slice(4, 8), [[0, 0], [1, 0], [2, 0], [0, 0]]); |
| 88 |
test.end(); |
| 89 |
}); |
| 90 |
|
| 91 |
tape("dedup ring ABCA & line BCAB have no cuts", function(test) { |
| 92 |
var topology = dedup(cut(extract({ |
| 93 |
bcabLine: {type: "LineString", coordinates: [[1, 0], [2, 0], [0, 0], [1, 0]]}, |
| 94 |
abcaPolygon: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [2, 0], [0, 0]]]}, // rotated to BCAB |
| 95 |
}))); |
| 96 |
test.deepEqual(topology.objects, { |
| 97 |
bcabLine: {type: "LineString", arcs: {0: 0, 1: 3}}, |
| 98 |
abcaPolygon: {type: "Polygon", arcs: [{0: 0, 1: 3}]} |
| 99 |
}); |
| 100 |
test.end(); |
| 101 |
}); |
| 102 |
|
| 103 |
tape("dedup when an old arc ABC extends a new arc AB, ABC is cut into AB-BC", function(test) { |
| 104 |
var topology = dedup(cut(extract({ |
| 105 |
abc: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0]]}, |
| 106 |
ab: {type: "LineString", coordinates: [[0, 0], [1, 0]]} |
| 107 |
}))); |
| 108 |
test.deepEqual(topology.objects, { |
| 109 |
abc: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 1, 1: 2}}}, |
| 110 |
ab: {type: "LineString", arcs: {0: 0, 1: 1}} |
| 111 |
}); |
| 112 |
test.end(); |
| 113 |
}); |
| 114 |
|
| 115 |
tape("dedup when a reversed old arc CBA extends a new arc AB, CBA is cut into CB-BA", function(test) { |
| 116 |
var topology = dedup(cut(extract({ |
| 117 |
cba: {type: "LineString", coordinates: [[2, 0], [1, 0], [0, 0]]}, |
| 118 |
ab: {type: "LineString", coordinates: [[0, 0], [1, 0]]} |
| 119 |
}))); |
| 120 |
test.deepEqual(topology.objects, { |
| 121 |
cba: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 1, 1: 2}}}, |
| 122 |
ab: {type: "LineString", arcs: {0: 2, 1: 1}} |
| 123 |
}); |
| 124 |
test.end(); |
| 125 |
}); |
| 126 |
|
| 127 |
tape("dedup when a new arc ADE shares its start with an old arc ABC, there are no cuts", function(test) { |
| 128 |
var topology = dedup(cut(extract({ |
| 129 |
ade: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0]]}, |
| 130 |
abc: {type: "LineString", coordinates: [[0, 0], [1, 1], [2, 1]]} |
| 131 |
}))); |
| 132 |
test.deepEqual(topology.objects, { |
| 133 |
ade: {type: "LineString", arcs: {0: 0, 1: 2}}, |
| 134 |
abc: {type: "LineString", arcs: {0: 3, 1: 5}} |
| 135 |
}); |
| 136 |
test.end(); |
| 137 |
}); |
| 138 |
|
| 139 |
tape("dedup ring ABA has no cuts", function(test) { |
| 140 |
var topology = dedup(cut(extract({ |
| 141 |
aba: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [0, 0]]]}, |
| 142 |
}))); |
| 143 |
test.deepEqual(topology.objects, { |
| 144 |
aba: {type: "Polygon", arcs: [{0: 0, 1: 2}]} |
| 145 |
}); |
| 146 |
test.end(); |
| 147 |
}); |
| 148 |
|
| 149 |
tape("dedup ring AA has no cuts", function(test) { |
| 150 |
var topology = dedup(cut(extract({ |
| 151 |
aa: {type: "Polygon", coordinates: [[[0, 0], [0, 0]]]}, |
| 152 |
}))); |
| 153 |
test.deepEqual(topology.objects, { |
| 154 |
aa: {type: "Polygon", arcs: [{0: 0, 1: 1}]} |
| 155 |
}); |
| 156 |
test.end(); |
| 157 |
}); |
| 158 |
|
| 159 |
tape("dedup degenerate ring A has no cuts", function(test) { |
| 160 |
var topology = dedup(cut(extract({ |
| 161 |
a: {type: "Polygon", coordinates: [[[0, 0]]]}, |
| 162 |
}))); |
| 163 |
test.deepEqual(topology.objects, { |
| 164 |
a: {type: "Polygon", arcs: [{0: 0, 1: 0}]} |
| 165 |
}); |
| 166 |
test.end(); |
| 167 |
}); |
| 168 |
|
| 169 |
tape("dedup when a new line DEC shares its end with an old line ABC, there are no cuts", function(test) { |
| 170 |
var topology = dedup(cut(extract({ |
| 171 |
abc: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0]]}, |
| 172 |
dec: {type: "LineString", coordinates: [[0, 1], [1, 1], [2, 0]]} |
| 173 |
}))); |
| 174 |
test.deepEqual(topology.objects, { |
| 175 |
abc: {type: "LineString", arcs: {0: 0, 1: 2}}, |
| 176 |
dec: {type: "LineString", arcs: {0: 3, 1: 5}} |
| 177 |
}); |
| 178 |
test.end(); |
| 179 |
}); |
| 180 |
|
| 181 |
tape("dedup when a new line ABC extends an old line AB, ABC is cut into AB-BC", function(test) { |
| 182 |
var topology = dedup(cut(extract({ |
| 183 |
ab: {type: "LineString", coordinates: [[0, 0], [1, 0]]}, |
| 184 |
abc: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0]]} |
| 185 |
}))); |
| 186 |
test.deepEqual(topology.objects, { |
| 187 |
ab: {type: "LineString", arcs: {0: 0, 1: 1}}, |
| 188 |
abc: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 3, 1: 4}}} |
| 189 |
}); |
| 190 |
test.end(); |
| 191 |
}); |
| 192 |
|
| 193 |
tape("dedup when a new line ABC extends a reversed old line BA, ABC is cut into AB-BC", function(test) { |
| 194 |
var topology = dedup(cut(extract({ |
| 195 |
ba: {type: "LineString", coordinates: [[1, 0], [0, 0]]}, |
| 196 |
abc: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0]]} |
| 197 |
}))); |
| 198 |
test.deepEqual(topology.objects, { |
| 199 |
ba: {type: "LineString", arcs: {0: 0, 1: 1}}, |
| 200 |
abc: {type: "LineString", arcs: {0: 1, 1: 0, next: {0: 3, 1: 4}}} |
| 201 |
}); |
| 202 |
test.end(); |
| 203 |
}); |
| 204 |
|
| 205 |
tape("dedup when a new line starts BC in the middle of an old line ABC, ABC is cut into AB-BC", function(test) { |
| 206 |
var topology = dedup(cut(extract({ |
| 207 |
abc: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0]]}, |
| 208 |
bc: {type: "LineString", coordinates: [[1, 0], [2, 0]]} |
| 209 |
}))); |
| 210 |
test.deepEqual(topology.objects, { |
| 211 |
abc: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 1, 1: 2}}}, |
| 212 |
bc: {type: "LineString", arcs: {0: 1, 1: 2}} |
| 213 |
}); |
| 214 |
test.end(); |
| 215 |
}); |
| 216 |
|
| 217 |
tape("dedup when a new line BC starts in the middle of a reversed old line CBA, CBA is cut into CB-BA", function(test) { |
| 218 |
var topology = dedup(cut(extract({ |
| 219 |
cba: {type: "LineString", coordinates: [[2, 0], [1, 0], [0, 0]]}, |
| 220 |
bc: {type: "LineString", coordinates: [[1, 0], [2, 0]]} |
| 221 |
}))); |
| 222 |
test.deepEqual(topology.objects, { |
| 223 |
cba: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 1, 1: 2}}}, |
| 224 |
bc: {type: "LineString", arcs: {0: 1, 1: 0}} |
| 225 |
}); |
| 226 |
test.end(); |
| 227 |
}); |
| 228 |
|
| 229 |
tape("dedup when a new line ABD deviates from an old line ABC, ABD is cut into AB-BD and ABC is cut into AB-BC", function(test) { |
| 230 |
var topology = dedup(cut(extract({ |
| 231 |
abc: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0]]}, |
| 232 |
abd: {type: "LineString", coordinates: [[0, 0], [1, 0], [3, 0]]} |
| 233 |
}))); |
| 234 |
test.deepEqual(topology.objects, { |
| 235 |
abc: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 1, 1: 2}}}, |
| 236 |
abd: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 4, 1: 5}}} |
| 237 |
}); |
| 238 |
test.end(); |
| 239 |
}); |
| 240 |
|
| 241 |
tape("dedup when a new line ABD deviates from a reversed old line CBA, CBA is cut into CB-BA and ABD is cut into AB-BD", function(test) { |
| 242 |
var topology = dedup(cut(extract({ |
| 243 |
cba: {type: "LineString", coordinates: [[2, 0], [1, 0], [0, 0]]}, |
| 244 |
abd: {type: "LineString", coordinates: [[0, 0], [1, 0], [3, 0]]} |
| 245 |
}))); |
| 246 |
test.deepEqual(topology.objects, { |
| 247 |
cba: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 1, 1: 2}}}, |
| 248 |
abd: {type: "LineString", arcs: {0: 2, 1: 1, next: {0: 4, 1: 5}}} |
| 249 |
}); |
| 250 |
test.end(); |
| 251 |
}); |
| 252 |
|
| 253 |
tape("dedup when a new line DBC merges into an old line ABC, DBC is cut into DB-BC and ABC is cut into AB-BC", function(test) { |
| 254 |
var topology = dedup(cut(extract({ |
| 255 |
abc: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0]]}, |
| 256 |
dbc: {type: "LineString", coordinates: [[3, 0], [1, 0], [2, 0]]} |
| 257 |
}))); |
| 258 |
test.deepEqual(topology.objects, { |
| 259 |
abc: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 1, 1: 2}}}, |
| 260 |
dbc: {type: "LineString", arcs: {0: 3, 1: 4, next: {0: 1, 1: 2}}} |
| 261 |
}); |
| 262 |
test.end(); |
| 263 |
}); |
| 264 |
|
| 265 |
tape("dedup when a new line DBC merges into a reversed old line CBA, DBC is cut into DB-BC and CBA is cut into CB-BA", function(test) { |
| 266 |
var topology = dedup(cut(extract({ |
| 267 |
cba: {type: "LineString", coordinates: [[2, 0], [1, 0], [0, 0]]}, |
| 268 |
dbc: {type: "LineString", coordinates: [[3, 0], [1, 0], [2, 0]]} |
| 269 |
}))); |
| 270 |
test.deepEqual(topology.objects, { |
| 271 |
cba: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 1, 1: 2}}}, |
| 272 |
dbc: {type: "LineString", arcs: {0: 3, 1: 4, next: {0: 1, 1: 0}}} |
| 273 |
}); |
| 274 |
test.end(); |
| 275 |
}); |
| 276 |
|
| 277 |
tape("dedup when a new line DBE shares a single midpoint with an old line ABC, DBE is cut into DB-BE and ABC is cut into AB-BC", function(test) { |
| 278 |
var topology = dedup(cut(extract({ |
| 279 |
abc: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0]]}, |
| 280 |
dbe: {type: "LineString", coordinates: [[0, 1], [1, 0], [2, 1]]} |
| 281 |
}))); |
| 282 |
test.deepEqual(topology.objects, { |
| 283 |
abc: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 1, 1: 2}}}, |
| 284 |
dbe: {type: "LineString", arcs: {0: 3, 1: 4, next: {0: 4, 1: 5}}} |
| 285 |
}); |
| 286 |
test.end(); |
| 287 |
}); |
| 288 |
|
| 289 |
tape("dedup when a new line ABDE skips a point with an old line ABCDE, ABDE is cut into AB-BD-DE and ABCDE is cut into AB-BCD-DE", function(test) { |
| 290 |
var topology = dedup(cut(extract({ |
| 291 |
abcde: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0]]}, |
| 292 |
abde: {type: "LineString", coordinates: [[0, 0], [1, 0], [3, 0], [4, 0]]} |
| 293 |
}))); |
| 294 |
test.deepEqual(topology.objects, { |
| 295 |
abcde: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 1, 1: 3, next: {0: 3, 1: 4}}}}, |
| 296 |
abde: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 6, 1: 7, next: {0: 3, 1: 4}}}} |
| 297 |
}); |
| 298 |
test.end(); |
| 299 |
}); |
| 300 |
|
| 301 |
tape("dedup when a new line ABDE skips a point with a reversed old line EDCBA, ABDE is cut into AB-BD-DE and EDCBA is cut into ED-DCB-BA", function(test) { |
| 302 |
var topology = dedup(cut(extract({ |
| 303 |
edcba: {type: "LineString", coordinates: [[4, 0], [3, 0], [2, 0], [1, 0], [0, 0]]}, |
| 304 |
abde: {type: "LineString", coordinates: [[0, 0], [1, 0], [3, 0], [4, 0]]} |
| 305 |
}))); |
| 306 |
test.deepEqual(topology.objects, { |
| 307 |
edcba: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 1, 1: 3, next: {0: 3, 1: 4}}}}, |
| 308 |
abde: {type: "LineString", arcs: {0: 4, 1: 3, next: {0: 6, 1: 7, next: {0: 1, 1: 0}}}} |
| 309 |
}); |
| 310 |
test.end(); |
| 311 |
}); |
| 312 |
|
| 313 |
tape("dedup when a line ABCDBE self-intersects with its middle, it is not cut", function(test) { |
| 314 |
var topology = dedup(cut(extract({ |
| 315 |
abcdbe: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0], [3, 0], [1, 0], [4, 0]]} |
| 316 |
}))); |
| 317 |
test.deepEqual(topology.objects, { |
| 318 |
abcdbe: {type: "LineString", arcs: {0: 0, 1: 5}} |
| 319 |
}); |
| 320 |
test.end(); |
| 321 |
}); |
| 322 |
|
| 323 |
tape("dedup when a line ABACD self-intersects with its start, it is cut into ABA-ACD", function(test) { |
| 324 |
var topology = dedup(cut(extract({ |
| 325 |
abacd: {type: "LineString", coordinates: [[0, 0], [1, 0], [0, 0], [3, 0], [4, 0]]} |
| 326 |
}))); |
| 327 |
test.deepEqual(topology.objects, { |
| 328 |
abacd: {type: "LineString", arcs: {0: 0, 1: 2, next: {0: 2, 1: 4}}} |
| 329 |
}); |
| 330 |
test.end(); |
| 331 |
}); |
| 332 |
|
| 333 |
tape("dedup when a line ABDCD self-intersects with its end, it is cut into ABD-DCD", function(test) { |
| 334 |
var topology = dedup(cut(extract({ |
| 335 |
abdcd: {type: "LineString", coordinates: [[0, 0], [1, 0], [4, 0], [3, 0], [4, 0]]} |
| 336 |
}))); |
| 337 |
test.deepEqual(topology.objects, { |
| 338 |
abdcd: {type: "LineString", arcs: {0: 0, 1: 2, next: {0: 2, 1: 4}}} |
| 339 |
}); |
| 340 |
test.end(); |
| 341 |
}); |
| 342 |
|
| 343 |
tape("dedup when an old line ABCDBE self-intersects and shares a point B, ABCDBE is cut into AB-BCDB-BE and FBG is cut into FB-BG", function(test) { |
| 344 |
var topology = dedup(cut(extract({ |
| 345 |
abcdbe: {type: "LineString", coordinates: [[0, 0], [1, 0], [2, 0], [3, 0], [1, 0], [4, 0]]}, |
| 346 |
fbg: {type: "LineString", coordinates: [[0, 1], [1, 0], [2, 1]]} |
| 347 |
}))); |
| 348 |
test.deepEqual(topology.objects, { |
| 349 |
abcdbe: {type: "LineString", arcs: {0: 0, 1: 1, next: {0: 1, 1: 4, next: {0: 4, 1: 5}}}}, |
| 350 |
fbg: {type: "LineString", arcs: {0: 6, 1: 7, next: {0: 7, 1: 8}}} |
| 351 |
}); |
| 352 |
test.end(); |
| 353 |
}); |
| 354 |
|
| 355 |
tape("dedup when a line ABCA is closed, there are no cuts", function(test) { |
| 356 |
var topology = dedup(cut(extract({ |
| 357 |
abca: {type: "LineString", coordinates: [[0, 0], [1, 0], [0, 1], [0, 0]]} |
| 358 |
}))); |
| 359 |
test.deepEqual(topology.objects, { |
| 360 |
abca: {type: "LineString", arcs: {0: 0, 1: 3}} |
| 361 |
}); |
| 362 |
test.end(); |
| 363 |
}); |
| 364 |
|
| 365 |
tape("dedup when a ring ABCA is closed, there are no cuts", function(test) { |
| 366 |
var topology = dedup(cut(extract({ |
| 367 |
abca: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [0, 1], [0, 0]]]} |
| 368 |
}))); |
| 369 |
test.deepEqual(topology.objects, { |
| 370 |
abca: {type: "Polygon", arcs: [{0: 0, 1: 3}]} |
| 371 |
}); |
| 372 |
test.end(); |
| 373 |
}); |
| 374 |
|
| 375 |
tape("dedup exact duplicate rings ABCA & ABCA have no cuts", function(test) { |
| 376 |
var topology = dedup(cut(extract({ |
| 377 |
abca: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [0, 1], [0, 0]]]}, |
| 378 |
abca2: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [0, 1], [0, 0]]]} |
| 379 |
}))); |
| 380 |
test.deepEqual(topology.objects, { |
| 381 |
abca: {type: "Polygon", arcs: [{0: 0, 1: 3}]}, |
| 382 |
abca2: {type: "Polygon", arcs: [{0: 0, 1: 3}]} |
| 383 |
}); |
| 384 |
test.end(); |
| 385 |
}); |
| 386 |
|
| 387 |
tape("dedup reversed duplicate rings ABCA & ACBA have no cuts", function(test) { |
| 388 |
var topology = dedup(cut(extract({ |
| 389 |
abca: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [0, 1], [0, 0]]]}, |
| 390 |
acba: {type: "Polygon", coordinates: [[[0, 0], [0, 1], [1, 0], [0, 0]]]} |
| 391 |
}))); |
| 392 |
test.deepEqual(topology.objects, { |
| 393 |
abca: {type: "Polygon", arcs: [{0: 0, 1: 3}]}, |
| 394 |
acba: {type: "Polygon", arcs: [{0: 3, 1: 0}]} |
| 395 |
}); |
| 396 |
test.end(); |
| 397 |
}); |
| 398 |
|
| 399 |
tape("dedup coincident rings ABCA & BCAB have no cuts", function(test) { |
| 400 |
var topology = dedup(cut(extract({ |
| 401 |
abca: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [0, 1], [0, 0]]]}, |
| 402 |
bcab: {type: "Polygon", coordinates: [[[1, 0], [0, 1], [0, 0], [1, 0]]]} |
| 403 |
}))); |
| 404 |
test.deepEqual(topology.objects, { |
| 405 |
abca: {type: "Polygon", arcs: [{0: 0, 1: 3}]}, |
| 406 |
bcab: {type: "Polygon", arcs: [{0: 0, 1: 3}]} |
| 407 |
}); |
| 408 |
test.end(); |
| 409 |
}); |
| 410 |
|
| 411 |
tape("dedup coincident reversed rings ABCA & BACB have no cuts", function(test) { |
| 412 |
var topology = dedup(cut(extract({ |
| 413 |
abca: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [0, 1], [0, 0]]]}, |
| 414 |
bacb: {type: "Polygon", coordinates: [[[1, 0], [0, 0], [0, 1], [1, 0]]]} |
| 415 |
}))); |
| 416 |
test.deepEqual(topology.objects, { |
| 417 |
abca: {type: "Polygon", arcs: [{0: 0, 1: 3}]}, |
| 418 |
bacb: {type: "Polygon", arcs: [{0: 3, 1: 0}]} |
| 419 |
}); |
| 420 |
test.end(); |
| 421 |
}); |
| 422 |
|
| 423 |
tape("dedup coincident rings ABCDA, EFAE & GHCG are cut into ABC-CDA, EFAE and GHCG", function(test) { |
| 424 |
var topology = dedup(cut(extract({ |
| 425 |
abcda: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]]}, |
| 426 |
efae: {type: "Polygon", coordinates: [[[0, -1], [1, -1], [0, 0], [0, -1]]]}, |
| 427 |
ghcg: {type: "Polygon", coordinates: [[[0, 2], [1, 2], [1, 1], [0, 2]]]} |
| 428 |
}))); |
| 429 |
test.deepEqual(topology.objects, { |
| 430 |
abcda: {type: "Polygon", arcs: [{0: 0, 1: 2, next: {0: 2, 1: 4}}]}, |
| 431 |
efae: {type: "Polygon", arcs: [{0: 5, 1: 8}]}, |
| 432 |
ghcg: {type: "Polygon", arcs: [{0: 9, 1: 12}]} |
| 433 |
}); |
| 434 |
test.end(); |
| 435 |
}); |
| 436 |
|
| 437 |
tape("dedup coincident rings ABCA & DBED have no cuts, but are rotated to share B", function(test) { |
| 438 |
var topology = dedup(cut(extract({ |
| 439 |
abca: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [0, 1], [0, 0]]]}, |
| 440 |
dbed: {type: "Polygon", coordinates: [[[2, 1], [1, 0], [2, 2], [2, 1]]]} |
| 441 |
}))); |
| 442 |
test.deepEqual(topology.objects, { |
| 443 |
abca: {type: "Polygon", arcs: [{0: 0, 1: 3}]}, |
| 444 |
dbed: {type: "Polygon", arcs: [{0: 4, 1: 7}]} |
| 445 |
}); |
| 446 |
test.deepEqual(topology.coordinates.slice(0, 4), [[1, 0], [0, 1], [0, 0], [1, 0]]); |
| 447 |
test.deepEqual(topology.coordinates.slice(4, 8), [[1, 0], [2, 2], [2, 1], [1, 0]]); |
| 448 |
test.end(); |
| 449 |
}); |
| 450 |
|
| 451 |
tape("dedup overlapping rings ABCDA and BEFCB are cut into BC-CDAB and BEFC-CB", function(test) { |
| 452 |
var topology = dedup(cut(extract({ |
| 453 |
abcda: {type: "Polygon", coordinates: [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]]}, // rotated to BCDAB, cut BC-CDAB |
| 454 |
befcb: {type: "Polygon", coordinates: [[[1, 0], [2, 0], [2, 1], [1, 1], [1, 0]]]}, |
| 455 |
}))); |
| 456 |
test.deepEqual(topology.objects, { |
| 457 |
abcda: {type: "Polygon", arcs: [{0: 0, 1: 1, next: {0: 1, 1: 4}}]}, |
| 458 |
befcb: {type: "Polygon", arcs: [{0: 5, 1: 8, next: {0: 1, 1: 0}}]} |
| 459 |
}); |
| 460 |
test.end(); |
| 461 |
}); |
| 462 |
|