@wemap/geo 1.0.2 → 1.0.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,13 +12,13 @@
12
12
  "directory": "packages/geo"
13
13
  },
14
14
  "name": "@wemap/geo",
15
- "version": "1.0.2",
15
+ "version": "1.0.4",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-utils-js/issues"
18
18
  },
19
19
  "homepage": "https://github.com/wemap/wemap-utils-js#readme",
20
20
  "scripts": {
21
- "test": "mocha -r esm \\\"src/**/*.spec.js\\\""
21
+ "test": "mocha -r esm \"src/**/*.spec.js\""
22
22
  },
23
23
  "keywords": [
24
24
  "utils",
@@ -27,10 +27,10 @@
27
27
  ],
28
28
  "license": "ISC",
29
29
  "dependencies": {
30
- "@wemap/maths": "^0.2.1",
30
+ "@wemap/maths": "^1.0.0",
31
31
  "lodash.isfinite": "^3.3.2",
32
32
  "lodash.isnumber": "^3.0.3",
33
33
  "lodash.isstring": "^4.0.1"
34
34
  },
35
- "gitHead": "ba6b8ab6550b6b3bf87eddff821865e3147cfc96"
35
+ "gitHead": "cab48c01923850987968f072a8f7075a34b3cc32"
36
36
  }
@@ -74,10 +74,14 @@ class BoundingBox {
74
74
  this.northEast = new WGS84(ne2.lat, ne2.lng);
75
75
 
76
76
  } else {
77
- sw.lat = Math.min(sw2.lat, sw.lat);
78
- sw.lng = Math.min(sw2.lng, sw.lng);
79
- ne.lat = Math.max(ne2.lat, ne.lat);
80
- ne.lng = Math.max(ne2.lng, ne.lng);
77
+ this.southWest = new WGS84(
78
+ Math.min(sw2.lat, sw.lat),
79
+ Math.min(sw2.lng, sw.lng)
80
+ );
81
+ this.northEast = new WGS84(
82
+ Math.max(ne2.lat, ne.lat),
83
+ Math.max(ne2.lng, ne.lng)
84
+ );
81
85
  }
82
86
 
83
87
  return this;
@@ -177,9 +181,13 @@ class BoundingBox {
177
181
  return this.northEast.lat;
178
182
  }
179
183
 
184
+ static equalsTo(bb1, bb2) {
185
+ return WGS84.equalsTo(bb1.northEast, bb2.northEast)
186
+ && WGS84.equalsTo(bb1.southWest, bb2.southWest);
187
+ }
188
+
180
189
  equalsTo(other) {
181
- return WGS84.equalsTo(this.northEast, other.northEast)
182
- && WGS84.equalsTo(this.southWest, other.southWest);
190
+ return BoundingBox.equalsTo(this, other);
183
191
  }
184
192
  }
185
193
 
@@ -36,6 +36,38 @@ describe('Bounding Box', () => {
36
36
  });
37
37
 
38
38
 
39
+ it('equalsTo', () => {
40
+ boundingBox = new BoundingBox(northEast, southWest);
41
+ expect(boundingBox.equalsTo(new BoundingBox(
42
+ new WGS84(10, 40), new WGS84(-5, -20)
43
+ ))).true;
44
+ expect(BoundingBox.equalsTo(boundingBox, new BoundingBox(
45
+ new WGS84(10, 40), new WGS84(-5, -20)
46
+ ))).true;
47
+ expect(BoundingBox.equalsTo(boundingBox, new BoundingBox(
48
+ new WGS84(10, 10), new WGS84(-5, -20)
49
+ ))).false;
50
+ expect(BoundingBox.equalsTo(boundingBox, new BoundingBox(
51
+ new WGS84(10, 40), new WGS84(-15, -20)
52
+ ))).false;
53
+ });
54
+
55
+
56
+ it('bounds', () => {
57
+ boundingBox = new BoundingBox(northEast, southWest);
58
+ expect(boundingBox.getNorth()).equals(northEast.lat);
59
+ expect(boundingBox.getEast()).equals(northEast.lng);
60
+ expect(boundingBox.getSouth()).equals(southWest.lat);
61
+ expect(boundingBox.getWest()).equals(southWest.lng);
62
+ expect(WGS84.equalsTo(boundingBox.getNorthEast(), northEast)).true;
63
+ expect(WGS84.equalsTo(boundingBox.getSouthWest(), southWest)).true;
64
+ expect(WGS84.equalsTo(boundingBox.getNorthWest(),
65
+ new WGS84(northEast.lat, southWest.lng))).true;
66
+ expect(WGS84.equalsTo(boundingBox.getSouthEast(),
67
+ new WGS84(southWest.lat, northEast.lng))).true;
68
+ });
69
+
70
+
39
71
  it('center', () => {
40
72
  boundingBox = new BoundingBox();
41
73
  expect(() => boundingBox.center).is.throw(Error);
@@ -86,6 +118,20 @@ describe('Bounding Box', () => {
86
118
  boundingBox.extend(new WGS84(30, 40)),
87
119
  [30, 40, -5, -20]
88
120
  )).true;
121
+
122
+ boundingBox = new BoundingBox(northEast, southWest);
123
+ boundingBox.extend(new BoundingBox(
124
+ new WGS84(10, 10), new WGS84(-10, -10)
125
+ ));
126
+ expect(checkBounds(boundingBox, [10, 40, -10, -20])).true;
127
+
128
+ boundingBox = new BoundingBox(northEast, southWest);
129
+ boundingBox.extend(new BoundingBox());
130
+ expect(checkBounds(boundingBox, [10, 40, -5, -20])).true;
131
+
132
+ boundingBox = new BoundingBox();
133
+ boundingBox.extend(new BoundingBox(northEast, southWest));
134
+ expect(checkBounds(boundingBox, [10, 40, -5, -20])).true;
89
135
  });
90
136
 
91
137
 
@@ -29,7 +29,7 @@ class Level {
29
29
  this.low = Math.min(arg1, arg2);
30
30
  this.up = Math.max(arg1, arg2);
31
31
  }
32
- } else if (typeof arg2 === 'undefined'){
32
+ } else if (typeof arg2 === 'undefined') {
33
33
  this.isRange = false;
34
34
  this.val = arg1;
35
35
  } else {
@@ -164,7 +164,8 @@ class Level {
164
164
  } else if (!first.isRange && second.isRange) {
165
165
  low = Math.min(second.low, first.val);
166
166
  up = Math.max(second.up, first.val);
167
- } else if (first.isRange && second.isRange) {
167
+ } else {
168
+ /* if (first.isRange && second.isRange) */
168
169
  low = Math.min(second.low, first.low);
169
170
  up = Math.max(second.up, first.up);
170
171
  }
@@ -211,12 +212,9 @@ class Level {
211
212
  if (first.isRange && second.isRange) {
212
213
  return first.low === second.low && first.up === second.up;
213
214
  }
214
- if (!first.isRange && !second.isRange) {
215
- return first.val === second.val;
216
- }
215
+ // !first.isRange && !second.isRange
216
+ return first.val === second.val;
217
217
 
218
- // Should never happen.
219
- return false;
220
218
  }
221
219
 
222
220
  }
@@ -177,6 +177,18 @@ describe('Level', () => {
177
177
  expect(Level.equalsTo(Level.union(new Level(-1, 2), new Level(-3, -2)), new Level(-3, 2)));
178
178
  expect(Level.equalsTo(Level.union(new Level(0), new Level(1, 2)), new Level(0, 2)));
179
179
  expect(Level.equalsTo(Level.union(new Level(1, 2), new Level(0)), new Level(0, 2)));
180
+
181
+ expect(Level.equalsTo(new Level(0, 1).union(new Level(1)), new Level(0, 1)));
182
+ });
183
+
184
+
185
+ it('multiplyBy', () => {
186
+ expect(Level.equalsTo(new Level(0).multiplyBy(5), new Level(0)));
187
+ expect(Level.equalsTo(new Level(3).multiplyBy(2), new Level(6)));
188
+ expect(Level.equalsTo(new Level(-1).multiplyBy(5), new Level(-5)));
189
+ expect(Level.equalsTo(new Level(0, 1).multiplyBy(5), new Level(0, 5)));
190
+ expect(Level.equalsTo(new Level(-1, 1).multiplyBy(5), new Level(-5, 5)));
191
+ expect(Level.equalsTo(new Level(1, -1).multiplyBy(5), new Level(-5, 5)));
180
192
  });
181
193
 
182
194
  });