Debian Codegraph @

topojson/test/clockwise-test.js

raw
1 var tape = require("tape"),
2 clockwise = require("../lib/topojson/clockwise");
3
4 tape("clockwise spherical geometry ensures the ring with the largest absolute area is the exterior", function(test) {
5 var o = {
6 type: "Polygon",
7 coordinates: [
8 [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
9 [[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]]
10 ]
11 };
12 clockwise(o, {"coordinate-system": "spherical"});
13 test.deepEqual(o.coordinates, [
14 [[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]],
15 [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]]
16 ]);
17 test.end();
18 });
19
20 tape("clockwise spherical topology ensures the ring with the largest absolute area is the exterior", function(test) {
21 var o = {
22 type: "Topology",
23 objects: {
24 polygon: {
25 type: "Polygon",
26 arcs: [[0], [1]]
27 }
28 },
29 arcs: [
30 [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
31 [[0, 0], [0, 3], [3, 3], [3, 0], [0, 0]]
32 ]
33 };
34 clockwise(o, {"coordinate-system": "spherical"});
35 test.deepEqual(o.objects.polygon.arcs, [[1], [0]]);
36 test.end();
37 });
38
39 tape("clockwise cartesian geometry ensures the ring with the largest absolute area is the exterior", function(test) {
40 var o = {
41 type: "Polygon",
42 coordinates: [
43 [[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]],
44 [[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]]
45 ]
46 };
47 clockwise(o, {"coordinate-system": "cartesian"});
48 test.deepEqual(o.coordinates, [
49 [[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]],
50 [[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]
51 ]);
52 test.end();
53 });
54
55 tape("clockwise cartesian topology ensures the ring with the largest absolute area is the exterior", function(test) {
56 var o = {
57 type: "Topology",
58 objects: {
59 polygon: {
60 type: "Polygon",
61 arcs: [[0], [1]]
62 }
63 },
64 arcs: [
65 [[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]],
66 [[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]]
67 ]
68 };
69 clockwise(o, {"coordinate-system": "cartesian"});
70 test.deepEqual(o.objects.polygon.arcs, [[1], [0]]);
71 test.end();
72 });