@wemap/geo 2.7.1 → 2.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/geo"
13
13
  },
14
14
  "name": "@wemap/geo",
15
- "version": "2.7.1",
15
+ "version": "2.7.4",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -28,10 +28,10 @@
28
28
  "license": "ISC",
29
29
  "dependencies": {
30
30
  "@wemap/logger": "^2.7.0",
31
- "@wemap/maths": "^2.7.0",
31
+ "@wemap/maths": "^2.7.2",
32
32
  "lodash.isfinite": "^3.3.2",
33
33
  "lodash.isnumber": "^3.0.3",
34
34
  "lodash.isstring": "^4.0.1"
35
35
  },
36
- "gitHead": "3d332f1dce308ba28f2a551c2e709e840c54bd83"
36
+ "gitHead": "346dd50c4934b77b831a081f3543405865f1a65e"
37
37
  }
@@ -89,12 +89,16 @@ class Level {
89
89
 
90
90
  /**
91
91
  * Retrieve the intersection of two levels
92
- * @param {Level} other The other level
92
+ * @param {Level} first The first level
93
+ * @param {Level} second The second level
93
94
  */
94
95
  static intersect(first, second) {
95
96
 
96
97
  if (first === second) {
97
- return first;
98
+ if (first instanceof Level) {
99
+ return first.clone();
100
+ }
101
+ return null;
98
102
  }
99
103
 
100
104
  if (!second) {
@@ -107,13 +111,13 @@ class Level {
107
111
 
108
112
  if (first.isRange && !second.isRange) {
109
113
  if (first.isInside(second.val)) {
110
- return second;
114
+ return second.clone();
111
115
  }
112
116
  return null;
113
117
  }
114
118
  if (!first.isRange && second.isRange) {
115
119
  if (second.isInside(first.val)) {
116
- return first;
120
+ return first.clone();
117
121
  }
118
122
  return null;
119
123
  }
@@ -143,15 +147,18 @@ class Level {
143
147
  static union(first, second) {
144
148
 
145
149
  if (first === second) {
146
- return first;
150
+ if (first instanceof Level) {
151
+ return first.clone();
152
+ }
153
+ return null;
147
154
  }
148
155
 
149
156
  if (!second) {
150
- return first;
157
+ return first.clone();
151
158
  }
152
159
 
153
160
  if (!first) {
154
- return second;
161
+ return second.clone();
155
162
  }
156
163
 
157
164
  let low, up;
@@ -218,6 +225,43 @@ class Level {
218
225
 
219
226
  }
220
227
 
228
+ static diff(first, second) {
229
+
230
+ if (first === null || second === null) {
231
+ return null;
232
+ }
233
+
234
+ if (!first.isRange && !second.isRange) {
235
+ return second.val - first.val;
236
+ }
237
+
238
+ if (first.isRange && !second.isRange) {
239
+ if (first.low === second.val) {
240
+ return second.val - first.up;
241
+ }
242
+ if (first.up === second.val) {
243
+ return second.val - first.low;
244
+ }
245
+ return null;
246
+ }
247
+
248
+ if (second.isRange && !first.isRange) {
249
+ if (first.val === second.low) {
250
+ return second.up - first.val;
251
+ }
252
+ if (first.val === second.up) {
253
+ return second.low - first.val;
254
+ }
255
+ return null;
256
+ }
257
+
258
+ if (Level.equalsTo(first, second)) {
259
+ return 0;
260
+ }
261
+
262
+ return null;
263
+ }
264
+
221
265
  }
222
266
 
223
267
  export default Level;
@@ -138,9 +138,9 @@ describe('Level', () => {
138
138
  expect(Level.intersect(null, null)).is.null;
139
139
 
140
140
  const level = new Level(1);
141
- expect(Level.intersect(level, null)).equals(null);
142
- expect(Level.intersect(null, level)).equals(null);
143
- expect(Level.intersect(level, level)).equals(level);
141
+ expect(Level.intersect(level, null)).is.null;
142
+ expect(Level.intersect(null, level)).is.null;
143
+ expect(Level.equalsTo(Level.intersect(level, level), new Level(1))).true;
144
144
 
145
145
  expect(Level.equalsTo(Level.intersect(new Level(1), new Level(1)), new Level(1))).true;
146
146
  expect(Level.intersect(new Level(1), new Level(2))).is.null;
@@ -167,9 +167,9 @@ describe('Level', () => {
167
167
  expect(Level.union(null, null)).is.null;
168
168
 
169
169
  const level = new Level(1);
170
- expect(Level.union(level, null)).equals(level);
171
- expect(Level.union(null, level)).equals(level);
172
- expect(Level.union(level, level)).equals(level);
170
+ expect(Level.equalsTo(Level.union(level, null), new Level(1))).true;
171
+ expect(Level.equalsTo(Level.union(null, level), new Level(1))).true;
172
+ expect(Level.equalsTo(Level.union(level, level), new Level(1))).true;
173
173
 
174
174
  expect(Level.equalsTo(Level.union(new Level(1), new Level(1)), new Level(1))).true;
175
175
  expect(Level.equalsTo(Level.union(new Level(1), new Level(2)), new Level(1, 2))).true;
@@ -200,4 +200,22 @@ describe('Level', () => {
200
200
  expect(Level.equalsTo(new Level(1, -1).multiplyBy(5), new Level(-5, 5))).true;
201
201
  });
202
202
 
203
+ it('diff', () => {
204
+ expect(Level.diff(null, null)).is.null;
205
+ expect(Level.diff(null, new Level(0))).is.null;
206
+ expect(Level.diff(new Level(0), null)).is.null;
207
+ expect(Level.diff(new Level(0), new Level(0))).equals(0);
208
+ expect(Level.diff(new Level(2), new Level(2))).equals(0);
209
+ expect(Level.diff(new Level(0), new Level(2))).equals(2);
210
+ expect(Level.diff(new Level(2), new Level(0))).equals(-2);
211
+ expect(Level.diff(new Level(0, 1), new Level(0))).equals(-1);
212
+ expect(Level.diff(new Level(0, 1), new Level(1))).equals(1);
213
+ expect(Level.diff(new Level(0, 1), new Level(2))).is.null;
214
+ expect(Level.diff(new Level(0), new Level(0, 1))).equals(1);
215
+ expect(Level.diff(new Level(1), new Level(0, 1))).equals(-1);
216
+ expect(Level.diff(new Level(2), new Level(0, 1))).is.null;
217
+ expect(Level.diff(new Level(0, 1), new Level(0, 1))).equals(0);
218
+ expect(Level.diff(new Level(0, 1), new Level(0, 2))).is.null;
219
+ });
220
+
203
221
  });