dgeoutils 2.4.17 → 2.4.20

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.
@@ -9,6 +9,11 @@ export interface LatLng {
9
9
  lon?: number;
10
10
  alt?: number;
11
11
  }
12
+ export interface XYZ extends Record<string, any> {
13
+ x: number;
14
+ y: number;
15
+ z?: number;
16
+ }
12
17
  export declare const HALF_PI_IN_DEGREE = 90;
13
18
  export declare const PI_IN_DEGREE = 180;
14
19
  export declare const DOUBLE_PI_IN_DEGREE = 360;
@@ -25,10 +30,14 @@ export declare class DPoint {
25
30
  constructor(x: number, y: number);
26
31
  constructor(x: number, y: number, z?: number);
27
32
  static zero(): DPoint;
28
- static parse(c: LatLng | number[] | DCoord | Point | Feature<Point>, format?: string): DPoint;
33
+ static parse(c: LatLng | number[] | DCoord | Point | Feature<Point> | XYZ, format?: string): DPoint;
29
34
  static parseFromWKT(wkt: string): DPoint;
30
35
  static random(): DPoint;
31
36
  static getTileFromQuadKey(quadKey: string): DPoint;
37
+ toDegreesMinutesSeconds(): {
38
+ x: string;
39
+ y: string;
40
+ };
32
41
  getTileFromCoords(zoom?: number): DPoint;
33
42
  getQuadKeyFromTile(zoom?: number): string;
34
43
  getCoordsFromTile(zoom?: number): DPoint;
@@ -120,6 +129,7 @@ export declare class DPoint {
120
129
  set alt(v: number | undefined);
121
130
  simple<T extends Record<string, number>>(xKey?: string, yKey?: string, zKey?: string): T;
122
131
  setIfLessThan(p: DPoint): DPoint;
132
+ setIfMoreThan(p: DPoint): DPoint;
123
133
  minus(): DPoint;
124
134
  orthodromicPath(point: DPoint, pointsCount?: number): DPolygon;
125
135
  sortByDistance(p: DPolygon): DPolygon;
@@ -10,6 +10,17 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
13
24
  var __read = (this && this.__read) || function (o, n) {
14
25
  var m = typeof Symbol === "function" && o[Symbol.iterator];
15
26
  if (!m) return o;
@@ -63,6 +74,10 @@ var DPoint = (function () {
63
74
  if (lat && lng) {
64
75
  return new DPoint(lng, lat, alt !== null && alt !== void 0 ? alt : 0);
65
76
  }
77
+ var _c = c, x = _c.x, y = _c.y, z = _c.z, properties = __rest(_c, ["x", "y", "z"]);
78
+ if ((0, utils_1.isDefAndNotNull)(x) && (0, utils_1.isDefAndNotNull)(y)) {
79
+ return new DPoint(x, y, z).setProperties(properties);
80
+ }
66
81
  var t = c;
67
82
  if (c.type === 'Point') {
68
83
  t = c.coordinates;
@@ -124,6 +139,12 @@ var DPoint = (function () {
124
139
  }
125
140
  return p;
126
141
  };
142
+ DPoint.prototype.toDegreesMinutesSeconds = function () {
143
+ return {
144
+ x: (0, utils_1.toDegreesMinutesSeconds)(this.x),
145
+ y: (0, utils_1.toDegreesMinutesSeconds)(this.y)
146
+ };
147
+ };
127
148
  DPoint.prototype.getTileFromCoords = function (zoom) {
128
149
  if (zoom === void 0) { zoom = this.z; }
129
150
  (0, utils_1.checkFunction)('getTileFromCoords')
@@ -718,6 +739,11 @@ var DPoint = (function () {
718
739
  this.y = Math.max(this.y, p.y);
719
740
  return this;
720
741
  };
742
+ DPoint.prototype.setIfMoreThan = function (p) {
743
+ this.x = Math.min(this.x, p.x);
744
+ this.y = Math.min(this.y, p.y);
745
+ return this;
746
+ };
721
747
  DPoint.prototype.minus = function () {
722
748
  return this.scale(-1);
723
749
  };
@@ -7,4 +7,4 @@ export * from './FastSearch';
7
7
  export * from './TraceMatrix';
8
8
  export * from './DPolygonLoop';
9
9
  export * from './DPlane';
10
- export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, DGeo } from './utils';
10
+ export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, parseDegreesMinutesSeconds, DGeo } from './utils';
package/dist/cjs/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.DGeo = exports.getCombinations = exports.cartesianProduct = exports.isDefAndNotNull = exports.createMatrix = exports.createArray = exports.createCanvas = exports.gaussianElimination = void 0;
17
+ exports.DGeo = exports.parseDegreesMinutesSeconds = exports.getCombinations = exports.cartesianProduct = exports.isDefAndNotNull = exports.createMatrix = exports.createArray = exports.createCanvas = exports.gaussianElimination = void 0;
18
18
  __exportStar(require("./DCircle"), exports);
19
19
  __exportStar(require("./DLine"), exports);
20
20
  __exportStar(require("./DNumbers"), exports);
@@ -32,4 +32,5 @@ Object.defineProperty(exports, "createMatrix", { enumerable: true, get: function
32
32
  Object.defineProperty(exports, "isDefAndNotNull", { enumerable: true, get: function () { return utils_1.isDefAndNotNull; } });
33
33
  Object.defineProperty(exports, "cartesianProduct", { enumerable: true, get: function () { return utils_1.cartesianProduct; } });
34
34
  Object.defineProperty(exports, "getCombinations", { enumerable: true, get: function () { return utils_1.getCombinations; } });
35
+ Object.defineProperty(exports, "parseDegreesMinutesSeconds", { enumerable: true, get: function () { return utils_1.parseDegreesMinutesSeconds; } });
35
36
  Object.defineProperty(exports, "DGeo", { enumerable: true, get: function () { return utils_1.DGeo; } });
@@ -44,4 +44,6 @@ export declare const cartesianProduct: {
44
44
  };
45
45
  export declare const getCombinations: <T>(arr: T[][]) => T[][];
46
46
  export declare const div: (a: number, b: number) => number;
47
+ export declare const toDegreesMinutesSeconds: (v: number) => string;
48
+ export declare const parseDegreesMinutesSeconds: (i: string) => number;
47
49
  export {};
package/dist/cjs/utils.js CHANGED
@@ -24,8 +24,19 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
24
24
  }
25
25
  return to.concat(ar || Array.prototype.slice.call(from));
26
26
  };
27
+ var __values = (this && this.__values) || function(o) {
28
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
29
+ if (m) return m.call(o);
30
+ if (o && typeof o.length === "number") return {
31
+ next: function () {
32
+ if (o && i >= o.length) o = void 0;
33
+ return { value: o && o[i++], done: !o };
34
+ }
35
+ };
36
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
37
+ };
27
38
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.div = exports.getCombinations = exports.cartesianProduct = exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
39
+ exports.parseDegreesMinutesSeconds = exports.toDegreesMinutesSeconds = exports.div = exports.getCombinations = exports.cartesianProduct = exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
29
40
  var DPoint_1 = require("./DPoint");
30
41
  exports.DGeo = {
31
42
  DEBUG: false,
@@ -223,3 +234,46 @@ var getCombinations = function (arr) {
223
234
  exports.getCombinations = getCombinations;
224
235
  var div = function (a, b) { return Math.floor(a / b); };
225
236
  exports.div = div;
237
+ var toDegreesMinutesSeconds = function (v) {
238
+ var degrees = Math.floor(v);
239
+ var t = (v % 1) * 60;
240
+ var minutes = Math.floor(t);
241
+ var t2 = (t % 1) * 60;
242
+ var seconds = t2.toFixed(2);
243
+ return "".concat(degrees, "\u00B0 ").concat(minutes, "' ").concat(seconds, "\"");
244
+ };
245
+ exports.toDegreesMinutesSeconds = toDegreesMinutesSeconds;
246
+ var parseDegreesMinutesSeconds = function (i) {
247
+ var e_1, _a;
248
+ var _b, _c, _d, _e, _f, _g, _h;
249
+ var parts = i.matchAll(/(?<value>-?\d+(?<tail>\.\d{0,})?)(?<type>°|'|")/gmiu);
250
+ var d = 0;
251
+ var m = 0;
252
+ var s = 0;
253
+ try {
254
+ for (var parts_1 = __values(parts), parts_1_1 = parts_1.next(); !parts_1_1.done; parts_1_1 = parts_1.next()) {
255
+ var part = parts_1_1.value;
256
+ switch ((_b = part === null || part === void 0 ? void 0 : part.groups) === null || _b === void 0 ? void 0 : _b.type) {
257
+ case '°':
258
+ d = Number((_d = (_c = part === null || part === void 0 ? void 0 : part.groups) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : '0');
259
+ break;
260
+ case '\'':
261
+ m = Number((_f = (_e = part === null || part === void 0 ? void 0 : part.groups) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : '0');
262
+ break;
263
+ case '"':
264
+ s = Number((_h = (_g = part === null || part === void 0 ? void 0 : part.groups) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : '0');
265
+ break;
266
+ default:
267
+ }
268
+ }
269
+ }
270
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
271
+ finally {
272
+ try {
273
+ if (parts_1_1 && !parts_1_1.done && (_a = parts_1.return)) _a.call(parts_1);
274
+ }
275
+ finally { if (e_1) throw e_1.error; }
276
+ }
277
+ return d + m / 60 + s / 3600;
278
+ };
279
+ exports.parseDegreesMinutesSeconds = parseDegreesMinutesSeconds;
@@ -1,6 +1,17 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { DLine } from './DLine';
2
13
  import { DPolygon } from './DPolygon';
3
- import { checkFunction, createArray, DGeo, div, isDefAndNotNull } from './utils';
14
+ import { checkFunction, createArray, DGeo, div, isDefAndNotNull, toDegreesMinutesSeconds } from './utils';
4
15
  const diff = 0;
5
16
  const radiansPolygon = new DPolygon();
6
17
  const pseudoMercatorPolygon = new DPolygon();
@@ -30,6 +41,10 @@ export class DPoint {
30
41
  if (lat && lng) {
31
42
  return new DPoint(lng, lat, alt !== null && alt !== void 0 ? alt : 0);
32
43
  }
44
+ const _a = c, { x, y, z } = _a, properties = __rest(_a, ["x", "y", "z"]);
45
+ if (isDefAndNotNull(x) && isDefAndNotNull(y)) {
46
+ return new DPoint(x, y, z).setProperties(properties);
47
+ }
33
48
  let t = c;
34
49
  if (c.type === 'Point') {
35
50
  t = c.coordinates;
@@ -91,6 +106,12 @@ export class DPoint {
91
106
  }
92
107
  return p;
93
108
  }
109
+ toDegreesMinutesSeconds() {
110
+ return {
111
+ x: toDegreesMinutesSeconds(this.x),
112
+ y: toDegreesMinutesSeconds(this.y)
113
+ };
114
+ }
94
115
  getTileFromCoords(zoom = this.z) {
95
116
  checkFunction('getTileFromCoords')
96
117
  .checkArgument('this')
@@ -595,6 +616,11 @@ export class DPoint {
595
616
  this.y = Math.max(this.y, p.y);
596
617
  return this;
597
618
  }
619
+ setIfMoreThan(p) {
620
+ this.x = Math.min(this.x, p.x);
621
+ this.y = Math.min(this.y, p.y);
622
+ return this;
623
+ }
598
624
  minus() {
599
625
  return this.scale(-1);
600
626
  }
@@ -7,4 +7,4 @@ export * from './FastSearch';
7
7
  export * from './TraceMatrix';
8
8
  export * from './DPolygonLoop';
9
9
  export * from './DPlane';
10
- export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, DGeo } from './utils';
10
+ export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, parseDegreesMinutesSeconds, DGeo } from './utils';
@@ -174,3 +174,33 @@ export const getCombinations = (arr) => {
174
174
  return ans;
175
175
  };
176
176
  export const div = (a, b) => Math.floor(a / b);
177
+ export const toDegreesMinutesSeconds = (v) => {
178
+ const degrees = Math.floor(v);
179
+ const t = (v % 1) * 60;
180
+ const minutes = Math.floor(t);
181
+ const t2 = (t % 1) * 60;
182
+ const seconds = t2.toFixed(2);
183
+ return `${degrees}° ${minutes}' ${seconds}"`;
184
+ };
185
+ export const parseDegreesMinutesSeconds = (i) => {
186
+ var _a, _b, _c, _d, _e, _f, _g;
187
+ const parts = i.matchAll(/(?<value>-?\d+(?<tail>\.\d{0,})?)(?<type>°|'|")/gmiu);
188
+ let d = 0;
189
+ let m = 0;
190
+ let s = 0;
191
+ for (const part of parts) {
192
+ switch ((_a = part === null || part === void 0 ? void 0 : part.groups) === null || _a === void 0 ? void 0 : _a.type) {
193
+ case '°':
194
+ d = Number((_c = (_b = part === null || part === void 0 ? void 0 : part.groups) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : '0');
195
+ break;
196
+ case '\'':
197
+ m = Number((_e = (_d = part === null || part === void 0 ? void 0 : part.groups) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : '0');
198
+ break;
199
+ case '"':
200
+ s = Number((_g = (_f = part === null || part === void 0 ? void 0 : part.groups) === null || _f === void 0 ? void 0 : _f.value) !== null && _g !== void 0 ? _g : '0');
201
+ break;
202
+ default:
203
+ }
204
+ }
205
+ return d + m / 60 + s / 3600;
206
+ };
@@ -9,6 +9,17 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
12
23
  var __read = (this && this.__read) || function (o, n) {
13
24
  var m = typeof Symbol === "function" && o[Symbol.iterator];
14
25
  if (!m) return o;
@@ -27,7 +38,7 @@ var __read = (this && this.__read) || function (o, n) {
27
38
  };
28
39
  import { DLine } from './DLine';
29
40
  import { DPolygon } from './DPolygon';
30
- import { checkFunction, createArray, DGeo, div, isDefAndNotNull } from './utils';
41
+ import { checkFunction, createArray, DGeo, div, isDefAndNotNull, toDegreesMinutesSeconds } from './utils';
31
42
  var diff = 0;
32
43
  var radiansPolygon = new DPolygon();
33
44
  var pseudoMercatorPolygon = new DPolygon();
@@ -60,6 +71,10 @@ var DPoint = (function () {
60
71
  if (lat && lng) {
61
72
  return new DPoint(lng, lat, alt !== null && alt !== void 0 ? alt : 0);
62
73
  }
74
+ var _c = c, x = _c.x, y = _c.y, z = _c.z, properties = __rest(_c, ["x", "y", "z"]);
75
+ if (isDefAndNotNull(x) && isDefAndNotNull(y)) {
76
+ return new DPoint(x, y, z).setProperties(properties);
77
+ }
63
78
  var t = c;
64
79
  if (c.type === 'Point') {
65
80
  t = c.coordinates;
@@ -121,6 +136,12 @@ var DPoint = (function () {
121
136
  }
122
137
  return p;
123
138
  };
139
+ DPoint.prototype.toDegreesMinutesSeconds = function () {
140
+ return {
141
+ x: toDegreesMinutesSeconds(this.x),
142
+ y: toDegreesMinutesSeconds(this.y)
143
+ };
144
+ };
124
145
  DPoint.prototype.getTileFromCoords = function (zoom) {
125
146
  if (zoom === void 0) { zoom = this.z; }
126
147
  checkFunction('getTileFromCoords')
@@ -715,6 +736,11 @@ var DPoint = (function () {
715
736
  this.y = Math.max(this.y, p.y);
716
737
  return this;
717
738
  };
739
+ DPoint.prototype.setIfMoreThan = function (p) {
740
+ this.x = Math.min(this.x, p.x);
741
+ this.y = Math.min(this.y, p.y);
742
+ return this;
743
+ };
718
744
  DPoint.prototype.minus = function () {
719
745
  return this.scale(-1);
720
746
  };
package/dist/esm/index.js CHANGED
@@ -7,4 +7,4 @@ export * from './FastSearch';
7
7
  export * from './TraceMatrix';
8
8
  export * from './DPolygonLoop';
9
9
  export * from './DPlane';
10
- export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, DGeo } from './utils';
10
+ export { gaussianElimination, createCanvas, createArray, createMatrix, isDefAndNotNull, cartesianProduct, getCombinations, parseDegreesMinutesSeconds, DGeo } from './utils';
package/dist/esm/utils.js CHANGED
@@ -23,6 +23,17 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
23
23
  }
24
24
  return to.concat(ar || Array.prototype.slice.call(from));
25
25
  };
26
+ var __values = (this && this.__values) || function(o) {
27
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
28
+ if (m) return m.call(o);
29
+ if (o && typeof o.length === "number") return {
30
+ next: function () {
31
+ if (o && i >= o.length) o = void 0;
32
+ return { value: o && o[i++], done: !o };
33
+ }
34
+ };
35
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
36
+ };
26
37
  import { DPoint } from './DPoint';
27
38
  export var DGeo = {
28
39
  DEBUG: false,
@@ -210,3 +221,44 @@ export var getCombinations = function (arr) {
210
221
  return ans;
211
222
  };
212
223
  export var div = function (a, b) { return Math.floor(a / b); };
224
+ export var toDegreesMinutesSeconds = function (v) {
225
+ var degrees = Math.floor(v);
226
+ var t = (v % 1) * 60;
227
+ var minutes = Math.floor(t);
228
+ var t2 = (t % 1) * 60;
229
+ var seconds = t2.toFixed(2);
230
+ return "".concat(degrees, "\u00B0 ").concat(minutes, "' ").concat(seconds, "\"");
231
+ };
232
+ export var parseDegreesMinutesSeconds = function (i) {
233
+ var e_1, _a;
234
+ var _b, _c, _d, _e, _f, _g, _h;
235
+ var parts = i.matchAll(/(?<value>-?\d+(?<tail>\.\d{0,})?)(?<type>°|'|")/gmiu);
236
+ var d = 0;
237
+ var m = 0;
238
+ var s = 0;
239
+ try {
240
+ for (var parts_1 = __values(parts), parts_1_1 = parts_1.next(); !parts_1_1.done; parts_1_1 = parts_1.next()) {
241
+ var part = parts_1_1.value;
242
+ switch ((_b = part === null || part === void 0 ? void 0 : part.groups) === null || _b === void 0 ? void 0 : _b.type) {
243
+ case '°':
244
+ d = Number((_d = (_c = part === null || part === void 0 ? void 0 : part.groups) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : '0');
245
+ break;
246
+ case '\'':
247
+ m = Number((_f = (_e = part === null || part === void 0 ? void 0 : part.groups) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : '0');
248
+ break;
249
+ case '"':
250
+ s = Number((_h = (_g = part === null || part === void 0 ? void 0 : part.groups) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : '0');
251
+ break;
252
+ default:
253
+ }
254
+ }
255
+ }
256
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
257
+ finally {
258
+ try {
259
+ if (parts_1_1 && !parts_1_1.done && (_a = parts_1.return)) _a.call(parts_1);
260
+ }
261
+ finally { if (e_1) throw e_1.error; }
262
+ }
263
+ return d + m / 60 + s / 3600;
264
+ };