dgeoutils 2.4.13 → 2.4.16

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.
@@ -1,6 +1,6 @@
1
1
  import { DLine } from './DLine';
2
2
  import { DPolygon } from './DPolygon';
3
- import { Point } from 'geojson';
3
+ import { Point, Feature } from 'geojson';
4
4
  export declare const EARTH_RADIUS_IN_METERS = 6378137;
5
5
  export declare type DCoord = [number, number] | [number, number, number];
6
6
  export interface LatLng {
@@ -19,9 +19,7 @@ export declare class DPoint {
19
19
  x: number;
20
20
  y: number;
21
21
  z?: number | undefined;
22
- properties: {
23
- [key: string]: any;
24
- };
22
+ properties: Record<string, any>;
25
23
  constructor();
26
24
  constructor(xy: number);
27
25
  constructor(x: number, y: number);
@@ -36,6 +34,7 @@ export declare class DPoint {
36
34
  getCoordsFromTile(zoom?: number): DPoint;
37
35
  toCoords(format?: string): DCoord;
38
36
  toGeoJSON(format?: string): Point;
37
+ toGeoJSONFeature(format?: string): Feature<Point>;
39
38
  findLine(p: DPoint): DLine;
40
39
  findInnerAngle(p1: DPoint, p3: DPoint): number;
41
40
  toString(): string;
@@ -119,9 +118,7 @@ export declare class DPoint {
119
118
  set lon(v: number);
120
119
  get alt(): number | undefined;
121
120
  set alt(v: number | undefined);
122
- simple(xKey?: string, yKey?: string): {
123
- [key: string]: number;
124
- };
121
+ simple<T extends Record<string, number>>(xKey?: string, yKey?: string, zKey?: string): T;
125
122
  setIfLessThan(p: DPoint): DPoint;
126
123
  minus(): DPoint;
127
124
  orthodromicPath(point: DPoint, pointsCount?: number): DPolygon;
@@ -58,7 +58,7 @@ var DPoint = (function () {
58
58
  return new DPoint();
59
59
  };
60
60
  DPoint.parse = function (c, format) {
61
- if (format === void 0) { format = 'xyz'; }
61
+ if (format === void 0) { format = utils_1.DGeo.parseFormat; }
62
62
  var _a = c, lat = _a.lat, lon = _a.lon, _b = _a.lng, lng = _b === void 0 ? lon : _b, alt = _a.alt;
63
63
  if (lat && lng) {
64
64
  return new DPoint(lng, lat, alt !== null && alt !== void 0 ? alt : 0);
@@ -157,7 +157,7 @@ var DPoint = (function () {
157
157
  };
158
158
  DPoint.prototype.toCoords = function (format) {
159
159
  var _this = this;
160
- if (format === void 0) { format = 'xyz'; }
160
+ if (format === void 0) { format = utils_1.DGeo.parseFormat; }
161
161
  return format.replace(/[^x-z]/gmiu, '').split('')
162
162
  .map(function (k) { return ({
163
163
  x: _this.x,
@@ -167,12 +167,20 @@ var DPoint = (function () {
167
167
  .filter(function (r) { return r !== undefined; });
168
168
  };
169
169
  DPoint.prototype.toGeoJSON = function (format) {
170
- if (format === void 0) { format = 'xyz'; }
170
+ if (format === void 0) { format = utils_1.DGeo.parseFormat; }
171
171
  return {
172
172
  type: 'Point',
173
173
  coordinates: this.toCoords(format)
174
174
  };
175
175
  };
176
+ DPoint.prototype.toGeoJSONFeature = function (format) {
177
+ if (format === void 0) { format = utils_1.DGeo.parseFormat; }
178
+ return {
179
+ type: 'Feature',
180
+ properties: __assign({}, this.properties),
181
+ geometry: this.toGeoJSON(format)
182
+ };
183
+ };
176
184
  DPoint.prototype.findLine = function (p) {
177
185
  (0, utils_1.checkFunction)('findLine')
178
186
  .checkArgument('this')
@@ -691,14 +699,14 @@ var DPoint = (function () {
691
699
  enumerable: false,
692
700
  configurable: true
693
701
  });
694
- DPoint.prototype.simple = function (xKey, yKey) {
695
- var _a;
702
+ DPoint.prototype.simple = function (xKey, yKey, zKey) {
703
+ var _a, _b;
696
704
  if (xKey === void 0) { xKey = 'x'; }
697
705
  if (yKey === void 0) { yKey = 'y'; }
698
- return _a = {},
699
- _a[xKey] = this.x,
700
- _a[yKey] = this.y,
701
- _a;
706
+ if (zKey === void 0) { zKey = 'z'; }
707
+ return __assign((_a = {}, _a[xKey] = this.x, _a[yKey] = this.y, _a), ((0, utils_1.isDefAndNotNull)(this.z) ? (_b = {},
708
+ _b[zKey] = this.z,
709
+ _b) : {}));
702
710
  };
703
711
  DPoint.prototype.setIfLessThan = function (p) {
704
712
  this.x = Math.max(this.x, p.x);
@@ -739,7 +747,7 @@ var DPoint = (function () {
739
747
  .sort(function (a, b) { return a.properties.distance - b.properties.distance; });
740
748
  };
741
749
  DPoint.prototype.calculateAltitudeByDistanceBetweenPoints = function (p1, p2) {
742
- var _a, _b, _c, _d;
750
+ var _a, _b, _c, _d, _e;
743
751
  if (p1.alt === p2.alt) {
744
752
  this.alt = p1.alt;
745
753
  }
@@ -750,7 +758,7 @@ var DPoint = (function () {
750
758
  var distance1 = this.distance(p1);
751
759
  var distance2 = this.distance(p2);
752
760
  var totalDistance = distance1 + distance2;
753
- if (p1.alt === minAlt) {
761
+ if (((_e = p1.alt) !== null && _e !== void 0 ? _e : 0) === minAlt) {
754
762
  this.alt = minAlt + distance1 / totalDistance * dAlt;
755
763
  }
756
764
  else {
@@ -94,13 +94,13 @@ export declare class DPolygon {
94
94
  onBorder(p: DPoint): boolean;
95
95
  nextStart(): DPolygon;
96
96
  removeDuplicates(): DPolygon;
97
- static toGeoJSONFeatureCollection(polygons: DPolygon[], format?: string): FeatureCollection<LineString | Polygon, Record<string, any>>;
97
+ static toGeoJSONFeatureCollection(polygons: DPolygon[], format?: string): FeatureCollection<LineString | Polygon>;
98
98
  static parse(a: LatLng[], format?: string): DPolygon;
99
99
  static parse(a: number[][], format?: string): DPolygon;
100
100
  static parse(a: DCoord[], format?: string): DPolygon;
101
101
  static parse(a: GeoJsonGeometry | Feature | FeatureCollection<LineString | Polygon>, format?: string): DPolygon | DeepArray<DPolygon>;
102
102
  toArrayOfCoords(format?: string): DCoord[];
103
- toGeoJSONFeature(format?: string): Feature<LineString | Polygon, Record<string, any>>;
103
+ toGeoJSONFeature(format?: string): Feature<LineString | Polygon>;
104
104
  toGeoJSON(format?: string): LineString | Polygon;
105
105
  divideToPieces(piecesCount: number, withAltitude?: boolean): DPolygon;
106
106
  prepareToFastSearch(): void;
@@ -967,14 +967,14 @@ var DPolygon = (function () {
967
967
  return this;
968
968
  };
969
969
  DPolygon.toGeoJSONFeatureCollection = function (polygons, format) {
970
- if (format === void 0) { format = 'xyz'; }
970
+ if (format === void 0) { format = utils_1.DGeo.parseFormat; }
971
971
  return {
972
972
  type: 'FeatureCollection',
973
973
  features: polygons.map(function (polygon) { return polygon.toGeoJSONFeature(format); })
974
974
  };
975
975
  };
976
976
  DPolygon.parse = function (a, format) {
977
- if (format === void 0) { format = 'xyz'; }
977
+ if (format === void 0) { format = utils_1.DGeo.parseFormat; }
978
978
  if (a.type) {
979
979
  switch (a.type) {
980
980
  case 'FeatureCollection':
@@ -990,7 +990,14 @@ var DPolygon = (function () {
990
990
  }, []);
991
991
  case 'Feature': {
992
992
  var t = DPolygon.parse(a.geometry, format);
993
- t.properties = __assign(__assign({}, a.properties), { id: a.id });
993
+ if (Array.isArray(t)) {
994
+ t.forEach(function (record) {
995
+ record.properties = __assign(__assign({}, a.properties), { id: a.id });
996
+ });
997
+ }
998
+ else {
999
+ t.properties = __assign(__assign({}, a.properties), { id: a.id });
1000
+ }
994
1001
  return t;
995
1002
  }
996
1003
  case 'LineString':
@@ -1031,11 +1038,11 @@ var DPolygon = (function () {
1031
1038
  .map(function (r) { return DPoint_1.DPoint.parse(r, format); }));
1032
1039
  };
1033
1040
  DPolygon.prototype.toArrayOfCoords = function (format) {
1034
- if (format === void 0) { format = 'xyz'; }
1041
+ if (format === void 0) { format = utils_1.DGeo.parseFormat; }
1035
1042
  return this.mapArray(function (r) { return r.toCoords(format); });
1036
1043
  };
1037
1044
  DPolygon.prototype.toGeoJSONFeature = function (format) {
1038
- if (format === void 0) { format = 'xyz'; }
1045
+ if (format === void 0) { format = utils_1.DGeo.parseFormat; }
1039
1046
  return {
1040
1047
  type: 'Feature',
1041
1048
  properties: __assign({}, this.properties),
@@ -1043,7 +1050,7 @@ var DPolygon = (function () {
1043
1050
  };
1044
1051
  };
1045
1052
  DPolygon.prototype.toGeoJSON = function (format) {
1046
- if (format === void 0) { format = 'xyz'; }
1053
+ if (format === void 0) { format = utils_1.DGeo.parseFormat; }
1047
1054
  if (this.closed) {
1048
1055
  return {
1049
1056
  type: 'Polygon',
@@ -1,8 +1,10 @@
1
1
  /// <reference types="offscreencanvas" />
2
2
  import { DPoint } from './DPoint';
3
- export declare const DGeo: {
3
+ interface DGeoInterface {
4
4
  DEBUG: boolean;
5
- };
5
+ parseFormat: string;
6
+ }
7
+ export declare const DGeo: DGeoInterface;
6
8
  export declare const warn: (...args: any[]) => void;
7
9
  export declare const isDefAndNotNull: (a: any) => boolean;
8
10
  declare type CheckFunc = (p: DPoint) => CheckFunction;
@@ -19,8 +21,10 @@ interface CheckFunction {
19
21
  checkArgument: (argName: string) => CheckArgument;
20
22
  }
21
23
  export declare const checkFunction: (funcName: string) => CheckFunction;
22
- export declare const createArray: (v: number, fillSymbol?: any) => number[];
23
- export declare const createMatrix: ({ h, w }: DPoint, fillSymbol?: any) => number[][];
24
+ declare type ArrayFillFunction<T> = (index: number) => T;
25
+ export declare const createArray: <T = number>(v: number, fillSymbol?: T | ArrayFillFunction<T> | undefined) => T[];
26
+ declare type MatrixFillFunction<T> = (x: number, y: number) => T;
27
+ export declare const createMatrix: <T>({ h, w }: DPoint, fillSymbol?: T | MatrixFillFunction<T> | undefined) => T[][];
24
28
  export declare const gaussianElimination: {
25
29
  (matrix: number[][]): number[];
26
30
  MIN: number;
package/dist/cjs/utils.js CHANGED
@@ -28,7 +28,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
28
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;
29
29
  var DPoint_1 = require("./DPoint");
30
30
  exports.DGeo = {
31
- DEBUG: false
31
+ DEBUG: false,
32
+ parseFormat: 'xyz'
32
33
  };
33
34
  var warn = function () {
34
35
  var args = [];
@@ -105,13 +106,19 @@ var checkFunction = function (funcName) { return ({
105
106
  }); };
106
107
  exports.checkFunction = checkFunction;
107
108
  var createArray = function (v, fillSymbol) {
108
- if (fillSymbol === void 0) { fillSymbol = 0; }
109
- return new Array(v).fill(fillSymbol);
109
+ if (typeof fillSymbol === 'function') {
110
+ return new Array(v).fill(false)
111
+ .map(function (_, i) { return fillSymbol(i); });
112
+ }
113
+ return new Array(v).fill(fillSymbol !== null && fillSymbol !== void 0 ? fillSymbol : 0);
110
114
  };
111
115
  exports.createArray = createArray;
112
116
  var createMatrix = function (_a, fillSymbol) {
113
117
  var h = _a.h, w = _a.w;
114
- if (fillSymbol === void 0) { fillSymbol = 0; }
118
+ if (typeof fillSymbol === 'function') {
119
+ return (0, exports.createArray)(h)
120
+ .map(function (_, y) { return (0, exports.createArray)(w, function (x) { return fillSymbol(x, y); }); });
121
+ }
115
122
  return (0, exports.createArray)(h)
116
123
  .map(function () { return (0, exports.createArray)(w, fillSymbol); });
117
124
  };
@@ -1,6 +1,6 @@
1
1
  import { DLine } from './DLine';
2
2
  import { DPolygon } from './DPolygon';
3
- import { checkFunction, createArray, div, isDefAndNotNull } from './utils';
3
+ import { checkFunction, createArray, DGeo, div, isDefAndNotNull } from './utils';
4
4
  const diff = 0;
5
5
  const radiansPolygon = new DPolygon();
6
6
  const pseudoMercatorPolygon = new DPolygon();
@@ -25,7 +25,7 @@ export class DPoint {
25
25
  static zero() {
26
26
  return new DPoint();
27
27
  }
28
- static parse(c, format = 'xyz') {
28
+ static parse(c, format = DGeo.parseFormat) {
29
29
  const { lat, lon, lng = lon, alt } = c;
30
30
  if (lat && lng) {
31
31
  return new DPoint(lng, lat, alt !== null && alt !== void 0 ? alt : 0);
@@ -119,7 +119,7 @@ export class DPoint {
119
119
  const y = PI_IN_DEGREE / Math.PI * Math.atan((Math.exp(n) - Math.exp(-n)) / 2);
120
120
  return new DPoint(x, y, zoom);
121
121
  }
122
- toCoords(format = 'xyz') {
122
+ toCoords(format = DGeo.parseFormat) {
123
123
  return format.replace(/[^x-z]/gmiu, '').split('')
124
124
  .map((k) => ({
125
125
  x: this.x,
@@ -128,12 +128,19 @@ export class DPoint {
128
128
  })[k])
129
129
  .filter((r) => r !== undefined);
130
130
  }
131
- toGeoJSON(format = 'xyz') {
131
+ toGeoJSON(format = DGeo.parseFormat) {
132
132
  return {
133
133
  type: 'Point',
134
134
  coordinates: this.toCoords(format)
135
135
  };
136
136
  }
137
+ toGeoJSONFeature(format = DGeo.parseFormat) {
138
+ return {
139
+ type: 'Feature',
140
+ properties: Object.assign({}, this.properties),
141
+ geometry: this.toGeoJSON(format)
142
+ };
143
+ }
137
144
  findLine(p) {
138
145
  checkFunction('findLine')
139
146
  .checkArgument('this')
@@ -573,11 +580,10 @@ export class DPoint {
573
580
  set alt(v) {
574
581
  this.z = v;
575
582
  }
576
- simple(xKey = 'x', yKey = 'y') {
577
- return {
578
- [xKey]: this.x,
579
- [yKey]: this.y
580
- };
583
+ simple(xKey = 'x', yKey = 'y', zKey = 'z') {
584
+ return Object.assign({ [xKey]: this.x, [yKey]: this.y }, (isDefAndNotNull(this.z) ? {
585
+ [zKey]: this.z
586
+ } : {}));
581
587
  }
582
588
  setIfLessThan(p) {
583
589
  this.x = Math.max(this.x, p.x);
@@ -616,7 +622,7 @@ export class DPoint {
616
622
  .sort((a, b) => a.properties.distance - b.properties.distance);
617
623
  }
618
624
  calculateAltitudeByDistanceBetweenPoints(p1, p2) {
619
- var _a, _b, _c, _d;
625
+ var _a, _b, _c, _d, _e;
620
626
  if (p1.alt === p2.alt) {
621
627
  this.alt = p1.alt;
622
628
  }
@@ -627,7 +633,7 @@ export class DPoint {
627
633
  const distance1 = this.distance(p1);
628
634
  const distance2 = this.distance(p2);
629
635
  const totalDistance = distance1 + distance2;
630
- if (p1.alt === minAlt) {
636
+ if (((_e = p1.alt) !== null && _e !== void 0 ? _e : 0) === minAlt) {
631
637
  this.alt = minAlt + distance1 / totalDistance * dAlt;
632
638
  }
633
639
  else {
@@ -4,7 +4,7 @@ import { DCircle } from './DCircle';
4
4
  import { DNumbers } from './DNumbers';
5
5
  import { io as jstsIo, operation } from 'jsts';
6
6
  import { DPolygonLoop } from './DPolygonLoop';
7
- import { isDefAndNotNull } from './utils';
7
+ import { DGeo, isDefAndNotNull } from './utils';
8
8
  const { buffer: { BufferParameters: { CAP_ROUND, CAP_FLAT, CAP_SQUARE } } } = operation;
9
9
  export const MIN_POINTS_IN_VALID_POLYGON = 3;
10
10
  const APPROXIMATION_VALUE = 0.1;
@@ -618,13 +618,13 @@ export class DPolygon {
618
618
  }
619
619
  return this;
620
620
  }
621
- static toGeoJSONFeatureCollection(polygons, format = 'xyz') {
621
+ static toGeoJSONFeatureCollection(polygons, format = DGeo.parseFormat) {
622
622
  return {
623
623
  type: 'FeatureCollection',
624
624
  features: polygons.map((polygon) => polygon.toGeoJSONFeature(format))
625
625
  };
626
626
  }
627
- static parse(a, format = 'xyz') {
627
+ static parse(a, format = DGeo.parseFormat) {
628
628
  if (a.type) {
629
629
  switch (a.type) {
630
630
  case 'FeatureCollection':
@@ -640,7 +640,14 @@ export class DPolygon {
640
640
  }, []);
641
641
  case 'Feature': {
642
642
  const t = DPolygon.parse(a.geometry, format);
643
- t.properties = Object.assign(Object.assign({}, a.properties), { id: a.id });
643
+ if (Array.isArray(t)) {
644
+ t.forEach((record) => {
645
+ record.properties = Object.assign(Object.assign({}, a.properties), { id: a.id });
646
+ });
647
+ }
648
+ else {
649
+ t.properties = Object.assign(Object.assign({}, a.properties), { id: a.id });
650
+ }
644
651
  return t;
645
652
  }
646
653
  case 'LineString':
@@ -680,17 +687,17 @@ export class DPolygon {
680
687
  return new DPolygon(a
681
688
  .map((r) => DPoint.parse(r, format)));
682
689
  }
683
- toArrayOfCoords(format = 'xyz') {
690
+ toArrayOfCoords(format = DGeo.parseFormat) {
684
691
  return this.mapArray((r) => r.toCoords(format));
685
692
  }
686
- toGeoJSONFeature(format = 'xyz') {
693
+ toGeoJSONFeature(format = DGeo.parseFormat) {
687
694
  return {
688
695
  type: 'Feature',
689
696
  properties: Object.assign({}, this.properties),
690
697
  geometry: this.toGeoJSON(format)
691
698
  };
692
699
  }
693
- toGeoJSON(format = 'xyz') {
700
+ toGeoJSON(format = DGeo.parseFormat) {
694
701
  if (this.closed) {
695
702
  return {
696
703
  type: 'Polygon',
@@ -1,6 +1,7 @@
1
1
  import { DPoint } from './DPoint';
2
2
  export const DGeo = {
3
- DEBUG: false
3
+ DEBUG: false,
4
+ parseFormat: 'xyz'
4
5
  };
5
6
  export const warn = (...args) => {
6
7
  if (DGeo.DEBUG) {
@@ -69,9 +70,21 @@ export const checkFunction = (funcName) => ({
69
70
  };
70
71
  }
71
72
  });
72
- export const createArray = (v, fillSymbol = 0) => new Array(v).fill(fillSymbol);
73
- export const createMatrix = ({ h, w }, fillSymbol = 0) => createArray(h)
74
- .map(() => createArray(w, fillSymbol));
73
+ export const createArray = (v, fillSymbol) => {
74
+ if (typeof fillSymbol === 'function') {
75
+ return new Array(v).fill(false)
76
+ .map((_, i) => fillSymbol(i));
77
+ }
78
+ return new Array(v).fill(fillSymbol !== null && fillSymbol !== void 0 ? fillSymbol : 0);
79
+ };
80
+ export const createMatrix = ({ h, w }, fillSymbol) => {
81
+ if (typeof fillSymbol === 'function') {
82
+ return createArray(h)
83
+ .map((_, y) => createArray(w, (x) => fillSymbol(x, y)));
84
+ }
85
+ return createArray(h)
86
+ .map(() => createArray(w, fillSymbol));
87
+ };
75
88
  export const gaussianElimination = (matrix) => {
76
89
  const n = matrix.length;
77
90
  const matrixClone = createMatrix(new DPoint(n + 1, n));
@@ -27,7 +27,7 @@ var __read = (this && this.__read) || function (o, n) {
27
27
  };
28
28
  import { DLine } from './DLine';
29
29
  import { DPolygon } from './DPolygon';
30
- import { checkFunction, createArray, div, isDefAndNotNull } from './utils';
30
+ import { checkFunction, createArray, DGeo, div, isDefAndNotNull } from './utils';
31
31
  var diff = 0;
32
32
  var radiansPolygon = new DPolygon();
33
33
  var pseudoMercatorPolygon = new DPolygon();
@@ -55,7 +55,7 @@ var DPoint = (function () {
55
55
  return new DPoint();
56
56
  };
57
57
  DPoint.parse = function (c, format) {
58
- if (format === void 0) { format = 'xyz'; }
58
+ if (format === void 0) { format = DGeo.parseFormat; }
59
59
  var _a = c, lat = _a.lat, lon = _a.lon, _b = _a.lng, lng = _b === void 0 ? lon : _b, alt = _a.alt;
60
60
  if (lat && lng) {
61
61
  return new DPoint(lng, lat, alt !== null && alt !== void 0 ? alt : 0);
@@ -154,7 +154,7 @@ var DPoint = (function () {
154
154
  };
155
155
  DPoint.prototype.toCoords = function (format) {
156
156
  var _this = this;
157
- if (format === void 0) { format = 'xyz'; }
157
+ if (format === void 0) { format = DGeo.parseFormat; }
158
158
  return format.replace(/[^x-z]/gmiu, '').split('')
159
159
  .map(function (k) { return ({
160
160
  x: _this.x,
@@ -164,12 +164,20 @@ var DPoint = (function () {
164
164
  .filter(function (r) { return r !== undefined; });
165
165
  };
166
166
  DPoint.prototype.toGeoJSON = function (format) {
167
- if (format === void 0) { format = 'xyz'; }
167
+ if (format === void 0) { format = DGeo.parseFormat; }
168
168
  return {
169
169
  type: 'Point',
170
170
  coordinates: this.toCoords(format)
171
171
  };
172
172
  };
173
+ DPoint.prototype.toGeoJSONFeature = function (format) {
174
+ if (format === void 0) { format = DGeo.parseFormat; }
175
+ return {
176
+ type: 'Feature',
177
+ properties: __assign({}, this.properties),
178
+ geometry: this.toGeoJSON(format)
179
+ };
180
+ };
173
181
  DPoint.prototype.findLine = function (p) {
174
182
  checkFunction('findLine')
175
183
  .checkArgument('this')
@@ -688,14 +696,14 @@ var DPoint = (function () {
688
696
  enumerable: false,
689
697
  configurable: true
690
698
  });
691
- DPoint.prototype.simple = function (xKey, yKey) {
692
- var _a;
699
+ DPoint.prototype.simple = function (xKey, yKey, zKey) {
700
+ var _a, _b;
693
701
  if (xKey === void 0) { xKey = 'x'; }
694
702
  if (yKey === void 0) { yKey = 'y'; }
695
- return _a = {},
696
- _a[xKey] = this.x,
697
- _a[yKey] = this.y,
698
- _a;
703
+ if (zKey === void 0) { zKey = 'z'; }
704
+ return __assign((_a = {}, _a[xKey] = this.x, _a[yKey] = this.y, _a), (isDefAndNotNull(this.z) ? (_b = {},
705
+ _b[zKey] = this.z,
706
+ _b) : {}));
699
707
  };
700
708
  DPoint.prototype.setIfLessThan = function (p) {
701
709
  this.x = Math.max(this.x, p.x);
@@ -736,7 +744,7 @@ var DPoint = (function () {
736
744
  .sort(function (a, b) { return a.properties.distance - b.properties.distance; });
737
745
  };
738
746
  DPoint.prototype.calculateAltitudeByDistanceBetweenPoints = function (p1, p2) {
739
- var _a, _b, _c, _d;
747
+ var _a, _b, _c, _d, _e;
740
748
  if (p1.alt === p2.alt) {
741
749
  this.alt = p1.alt;
742
750
  }
@@ -747,7 +755,7 @@ var DPoint = (function () {
747
755
  var distance1 = this.distance(p1);
748
756
  var distance2 = this.distance(p2);
749
757
  var totalDistance = distance1 + distance2;
750
- if (p1.alt === minAlt) {
758
+ if (((_e = p1.alt) !== null && _e !== void 0 ? _e : 0) === minAlt) {
751
759
  this.alt = minAlt + distance1 / totalDistance * dAlt;
752
760
  }
753
761
  else {
@@ -78,7 +78,7 @@ import { DCircle } from './DCircle';
78
78
  import { DNumbers } from './DNumbers';
79
79
  import { io as jstsIo, operation } from 'jsts';
80
80
  import { DPolygonLoop } from './DPolygonLoop';
81
- import { isDefAndNotNull } from './utils';
81
+ import { DGeo, isDefAndNotNull } from './utils';
82
82
  var _a = operation.buffer.BufferParameters, CAP_ROUND = _a.CAP_ROUND, CAP_FLAT = _a.CAP_FLAT, CAP_SQUARE = _a.CAP_SQUARE;
83
83
  export var MIN_POINTS_IN_VALID_POLYGON = 3;
84
84
  var APPROXIMATION_VALUE = 0.1;
@@ -964,14 +964,14 @@ var DPolygon = (function () {
964
964
  return this;
965
965
  };
966
966
  DPolygon.toGeoJSONFeatureCollection = function (polygons, format) {
967
- if (format === void 0) { format = 'xyz'; }
967
+ if (format === void 0) { format = DGeo.parseFormat; }
968
968
  return {
969
969
  type: 'FeatureCollection',
970
970
  features: polygons.map(function (polygon) { return polygon.toGeoJSONFeature(format); })
971
971
  };
972
972
  };
973
973
  DPolygon.parse = function (a, format) {
974
- if (format === void 0) { format = 'xyz'; }
974
+ if (format === void 0) { format = DGeo.parseFormat; }
975
975
  if (a.type) {
976
976
  switch (a.type) {
977
977
  case 'FeatureCollection':
@@ -987,7 +987,14 @@ var DPolygon = (function () {
987
987
  }, []);
988
988
  case 'Feature': {
989
989
  var t = DPolygon.parse(a.geometry, format);
990
- t.properties = __assign(__assign({}, a.properties), { id: a.id });
990
+ if (Array.isArray(t)) {
991
+ t.forEach(function (record) {
992
+ record.properties = __assign(__assign({}, a.properties), { id: a.id });
993
+ });
994
+ }
995
+ else {
996
+ t.properties = __assign(__assign({}, a.properties), { id: a.id });
997
+ }
991
998
  return t;
992
999
  }
993
1000
  case 'LineString':
@@ -1028,11 +1035,11 @@ var DPolygon = (function () {
1028
1035
  .map(function (r) { return DPoint.parse(r, format); }));
1029
1036
  };
1030
1037
  DPolygon.prototype.toArrayOfCoords = function (format) {
1031
- if (format === void 0) { format = 'xyz'; }
1038
+ if (format === void 0) { format = DGeo.parseFormat; }
1032
1039
  return this.mapArray(function (r) { return r.toCoords(format); });
1033
1040
  };
1034
1041
  DPolygon.prototype.toGeoJSONFeature = function (format) {
1035
- if (format === void 0) { format = 'xyz'; }
1042
+ if (format === void 0) { format = DGeo.parseFormat; }
1036
1043
  return {
1037
1044
  type: 'Feature',
1038
1045
  properties: __assign({}, this.properties),
@@ -1040,7 +1047,7 @@ var DPolygon = (function () {
1040
1047
  };
1041
1048
  };
1042
1049
  DPolygon.prototype.toGeoJSON = function (format) {
1043
- if (format === void 0) { format = 'xyz'; }
1050
+ if (format === void 0) { format = DGeo.parseFormat; }
1044
1051
  if (this.closed) {
1045
1052
  return {
1046
1053
  type: 'Polygon',
package/dist/esm/utils.js CHANGED
@@ -25,7 +25,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
25
25
  };
26
26
  import { DPoint } from './DPoint';
27
27
  export var DGeo = {
28
- DEBUG: false
28
+ DEBUG: false,
29
+ parseFormat: 'xyz'
29
30
  };
30
31
  export var warn = function () {
31
32
  var args = [];
@@ -99,12 +100,18 @@ export var checkFunction = function (funcName) { return ({
99
100
  }
100
101
  }); };
101
102
  export var createArray = function (v, fillSymbol) {
102
- if (fillSymbol === void 0) { fillSymbol = 0; }
103
- return new Array(v).fill(fillSymbol);
103
+ if (typeof fillSymbol === 'function') {
104
+ return new Array(v).fill(false)
105
+ .map(function (_, i) { return fillSymbol(i); });
106
+ }
107
+ return new Array(v).fill(fillSymbol !== null && fillSymbol !== void 0 ? fillSymbol : 0);
104
108
  };
105
109
  export var createMatrix = function (_a, fillSymbol) {
106
110
  var h = _a.h, w = _a.w;
107
- if (fillSymbol === void 0) { fillSymbol = 0; }
111
+ if (typeof fillSymbol === 'function') {
112
+ return createArray(h)
113
+ .map(function (_, y) { return createArray(w, function (x) { return fillSymbol(x, y); }); });
114
+ }
108
115
  return createArray(h)
109
116
  .map(function () { return createArray(w, fillSymbol); });
110
117
  };