Debian Codegraph @

topojson/test/simplify-test.js

raw
1 var tape = require("tape"),
2 simplify = require("../lib/topojson/simplify");
3
4 tape("simplify removes points with area below minimum area threshold", function(test) {
5 var topology = simplify({
6 transform: {scale: [1, 1], translate: [0, 0]},
7 objects: {},
8 arcs: [
9 [[0, 0], [10, 10], [0, 1], [1, -1], [-11, 0], [0, -10]]
10 ]
11 }, {
12 "minimum-area": 2,
13 "coordinate-system": "cartesian",
14 });
15 test.deepEqual(
16 topology.arcs,
17 [[[0, 0], [10, 10], [-10, 0], [0, -10]]]
18 );
19 test.end();
20 });
21
22 tape("simplify preserves points with area greater or equal to minimum area threshold", function(test) {
23 var topology = simplify({
24 transform: {scale: [1, 1], translate: [0, 0]},
25 objects: {},
26 arcs: [
27 [[0, 0], [10, 10], [0, 1], [1, -1], [-11, 0], [0, -10]]
28 ]
29 }, {
30 "minimum-area": 2,
31 "coordinate-system": "cartesian",
32 });
33 test.deepEqual(
34 topology.arcs,
35 [[[0, 0], [10, 10], [-10, 0], [0, -10]]]
36 );
37 test.end();
38 });
39
40 tape("simplify assumes delta-encoded arcs for quantized topologies", function(test) {
41 var topology = simplify({
42 transform: {scale: [1, 1], translate: [0, 0]},
43 objects: {},
44 arcs: [
45 [[0, 0], [10, 10], [0, 1], [1, -1], [-11, 0], [0, -10]]
46 ]
47 }, {
48 "minimum-area": 2,
49 "coordinate-system": "cartesian",
50 });
51 test.deepEqual(
52 topology.arcs,
53 [[[0, 0], [10, 10], [-10, 0], [0, -10]]]
54 );
55 test.end();
56 });
57
58 tape("simplify assumes non-delta-encoded arcs for non-quantized topologies", function(test) {
59 var topology = simplify({
60 objects: {},
61 arcs: [
62 [[0, 0], [10, 10], [10, 11], [11, 10], [0, 10], [0, 0]]
63 ]
64 }, {
65 "minimum-area": 2,
66 "coordinate-system": "cartesian",
67 });
68 test.deepEqual(
69 topology.arcs,
70 [[[0, 0], [10, 10], [0, 10], [0, 0]]]
71 );
72 test.end();
73 });
74
75 tape("simplify preserves degenerate arcs in non-quantized topologies", function(test) {
76 var topology = simplify({
77 objects: {},
78 arcs: [
79 [[50, 50], [50, 50]]
80 ]
81 }, {
82 "minimum-area": 2,
83 "coordinate-system": "cartesian"
84 });
85 test.deepEqual(topology.arcs, [
86 [[50, 50], [50, 50]]
87 ]);
88 test.end();
89 });
90
91 tape("simplify preserves degenerate arcs in quantized topologies", function(test) {
92 var topology = simplify({
93 transform: {scale: [1, 1], translate: [0, 0]},
94 objects: {},
95 arcs: [
96 [[50, 50], [0, 0]]
97 ]
98 }, {
99 "minimum-area": 2,
100 "coordinate-system": "cartesian"
101 });
102 test.deepEqual(topology.arcs, [
103 [[50, 50], [0, 0]]
104 ]);
105 test.end();
106 });
107
108 tape("simplify does not remove empty arcs", function(test) {
109 var topology = simplify({
110 transform: {scale: [1, 1], translate: [0, 0]},
111 objects: {
112 foo: {
113 type: "LineString",
114 arcs: [0, 1, 2]
115 }
116 },
117 arcs: [
118 [[0, 0], [10, 0]],
119 [[10, 0], [1, 1], [-1, -1]],
120 [[10, 0], [0, 10]]
121 ]
122 }, {
123 "minimum-area": 1,
124 "coordinate-system": "cartesian"
125 });
126 test.deepEqual(topology.arcs, [
127 [[0, 0], [10, 0]],
128 [[10, 0], [0, 0]],
129 [[10, 0], [0, 10]]
130 ]);
131 test.deepEqual(topology.objects.foo.arcs, [0, 1, 2]);
132 test.end();
133 });
134
135 tape("simplify minimum area is zero on empty input when retain-proportion is specified", function(test) {
136 var options = {
137 "retain-proportion": 1,
138 "coordinate-system": "cartesian"
139 };
140 var topology = simplify({
141 transform: {scale: [1, 1], translate: [0, 0]},
142 objects: {},
143 arcs: []
144 }, options);
145 test.equal(options["minimum-area"], 0);
146 test.deepEqual(topology.arcs, []);
147 test.end();
148 });