dgeoutils 2.4.26 → 2.4.27

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.
@@ -0,0 +1,22 @@
1
+ import { DPolygon } from './DPolygon';
2
+ import { DPoint } from './DPoint';
3
+ export declare class InterpolationMatrix {
4
+ private readonly stepSize;
5
+ private readonly p;
6
+ private readonly minPoint;
7
+ private readonly maxPoint;
8
+ private points;
9
+ private cells;
10
+ private allCells;
11
+ private readonly sizePoly;
12
+ private readonly keys;
13
+ constructor(bboxLike: DPolygon, stepSize: number, keys: string[] | string, p?: number);
14
+ setKnownPoints(points: DPoint[] | DPolygon): InterpolationMatrix;
15
+ positionToCellCoords(d: DPoint): DPoint;
16
+ calculate(): InterpolationMatrix;
17
+ getCellValue({ x, y }: DPoint, key?: string | string[]): (number | Record<string, number>);
18
+ get allCellsClone(): DPolygon[];
19
+ private interpolateValues;
20
+ private setKnownValues;
21
+ private generateCells;
22
+ }
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.InterpolationMatrix = void 0;
31
+ var DPolygon_1 = require("./DPolygon");
32
+ var DPoint_1 = require("./DPoint");
33
+ var utils_1 = require("./utils");
34
+ var InterpolationMatrix = (function () {
35
+ function InterpolationMatrix(bboxLike, stepSize, keys, p) {
36
+ if (p === void 0) { p = 2; }
37
+ this.stepSize = stepSize;
38
+ this.p = p;
39
+ this.points = [];
40
+ this.cells = {};
41
+ this.allCells = [];
42
+ this.minPoint = bboxLike.leftTop;
43
+ this.maxPoint = bboxLike.rightBottom;
44
+ this.sizePoly = DPolygon_1.DPolygon.createSquareBySize(new DPoint_1.DPoint(this.stepSize));
45
+ this.keys = Array.isArray(keys) ? keys : [keys];
46
+ this.generateCells();
47
+ }
48
+ InterpolationMatrix.prototype.setKnownPoints = function (points) {
49
+ this.points = points instanceof DPolygon_1.DPolygon ? points.points : points;
50
+ return this;
51
+ };
52
+ InterpolationMatrix.prototype.positionToCellCoords = function (d) {
53
+ return d.clone()
54
+ .move(this.minPoint.clone().minus())
55
+ .divide(this.stepSize)
56
+ .floor();
57
+ };
58
+ InterpolationMatrix.prototype.calculate = function () {
59
+ this.setKnownValues();
60
+ this.interpolateValues();
61
+ return this;
62
+ };
63
+ InterpolationMatrix.prototype.getCellValue = function (_a, key) {
64
+ var x = _a.x, y = _a.y;
65
+ var cell = this.cells[x][y];
66
+ if (key) {
67
+ if (Array.isArray(key)) {
68
+ return key.reduce(function (a, k) {
69
+ a[k] = cell.properties[k];
70
+ return a;
71
+ }, {});
72
+ }
73
+ return cell.properties[key];
74
+ }
75
+ return __assign({}, cell.properties);
76
+ };
77
+ Object.defineProperty(InterpolationMatrix.prototype, "allCellsClone", {
78
+ get: function () {
79
+ return this.allCells.map(function (p) { return p.clone(); });
80
+ },
81
+ enumerable: false,
82
+ configurable: true
83
+ });
84
+ InterpolationMatrix.prototype.interpolateValues = function () {
85
+ var _this = this;
86
+ var points = this.points.map(function (p) { return _this.positionToCellCoords(p); });
87
+ this.allCells.forEach(function (cell) {
88
+ var t = new DPoint_1.DPoint(cell.properties.x, cell.properties.y);
89
+ var distances = points.map(function (p) { return Math.pow(t.distance(p), _this.p); });
90
+ _this.keys.forEach(function (k) {
91
+ if ((0, utils_1.isDefAndNotNull)(cell.properties[k])) {
92
+ return;
93
+ }
94
+ var _a = __read(distances.reduce(function (a, d, i) {
95
+ if ((0, utils_1.isDefAndNotNull)(_this.points[i].properties[k])) {
96
+ a[0] += _this.points[i].properties[k] / d;
97
+ a[1] += 1 / d;
98
+ }
99
+ return a;
100
+ }, [0, 0]), 2), valueSum = _a[0], oneSum = _a[1];
101
+ cell.properties[k] = valueSum / oneSum;
102
+ });
103
+ });
104
+ };
105
+ InterpolationMatrix.prototype.setKnownValues = function () {
106
+ var _this = this;
107
+ this.points.forEach(function (p) {
108
+ var _a = _this.positionToCellCoords(p), x = _a.x, y = _a.y;
109
+ _this.keys.forEach(function (k) {
110
+ _this.cells[x][y].properties[k] = p.properties[k];
111
+ });
112
+ });
113
+ };
114
+ InterpolationMatrix.prototype.generateCells = function () {
115
+ for (var i = this.minPoint.x, x = 0; i < this.maxPoint.x; i += this.stepSize, x++) {
116
+ this.cells[x] = this.cells[x] || {};
117
+ for (var j = this.minPoint.y, y = 0; j < this.maxPoint.y; j += this.stepSize, y++) {
118
+ var t = this.sizePoly
119
+ .clone()
120
+ .loop()
121
+ .move(i, j)
122
+ .run()
123
+ .setProperties({
124
+ x: x,
125
+ y: y
126
+ });
127
+ this.cells[x][y] = t;
128
+ this.allCells.push(t);
129
+ }
130
+ }
131
+ };
132
+ return InterpolationMatrix;
133
+ }());
134
+ exports.InterpolationMatrix = InterpolationMatrix;
@@ -0,0 +1,94 @@
1
+ import { DPolygon } from './DPolygon';
2
+ import { DPoint } from './DPoint';
3
+ import { isDefAndNotNull } from './utils';
4
+ export class InterpolationMatrix {
5
+ constructor(bboxLike, stepSize, keys, p = 2) {
6
+ this.stepSize = stepSize;
7
+ this.p = p;
8
+ this.points = [];
9
+ this.cells = {};
10
+ this.allCells = [];
11
+ this.minPoint = bboxLike.leftTop;
12
+ this.maxPoint = bboxLike.rightBottom;
13
+ this.sizePoly = DPolygon.createSquareBySize(new DPoint(this.stepSize));
14
+ this.keys = Array.isArray(keys) ? keys : [keys];
15
+ this.generateCells();
16
+ }
17
+ setKnownPoints(points) {
18
+ this.points = points instanceof DPolygon ? points.points : points;
19
+ return this;
20
+ }
21
+ positionToCellCoords(d) {
22
+ return d.clone()
23
+ .move(this.minPoint.clone().minus())
24
+ .divide(this.stepSize)
25
+ .floor();
26
+ }
27
+ calculate() {
28
+ this.setKnownValues();
29
+ this.interpolateValues();
30
+ return this;
31
+ }
32
+ getCellValue({ x, y }, key) {
33
+ const cell = this.cells[x][y];
34
+ if (key) {
35
+ if (Array.isArray(key)) {
36
+ return key.reduce((a, k) => {
37
+ a[k] = cell.properties[k];
38
+ return a;
39
+ }, {});
40
+ }
41
+ return cell.properties[key];
42
+ }
43
+ return Object.assign({}, cell.properties);
44
+ }
45
+ get allCellsClone() {
46
+ return this.allCells.map((p) => p.clone());
47
+ }
48
+ interpolateValues() {
49
+ const points = this.points.map((p) => this.positionToCellCoords(p));
50
+ this.allCells.forEach((cell) => {
51
+ const t = new DPoint(cell.properties.x, cell.properties.y);
52
+ const distances = points.map((p) => Math.pow(t.distance(p), this.p));
53
+ this.keys.forEach((k) => {
54
+ if (isDefAndNotNull(cell.properties[k])) {
55
+ return;
56
+ }
57
+ const [valueSum, oneSum] = distances.reduce((a, d, i) => {
58
+ if (isDefAndNotNull(this.points[i].properties[k])) {
59
+ a[0] += this.points[i].properties[k] / d;
60
+ a[1] += 1 / d;
61
+ }
62
+ return a;
63
+ }, [0, 0]);
64
+ cell.properties[k] = valueSum / oneSum;
65
+ });
66
+ });
67
+ }
68
+ setKnownValues() {
69
+ this.points.forEach((p) => {
70
+ const { x, y } = this.positionToCellCoords(p);
71
+ this.keys.forEach((k) => {
72
+ this.cells[x][y].properties[k] = p.properties[k];
73
+ });
74
+ });
75
+ }
76
+ generateCells() {
77
+ for (let i = this.minPoint.x, x = 0; i < this.maxPoint.x; i += this.stepSize, x++) {
78
+ this.cells[x] = this.cells[x] || {};
79
+ for (let j = this.minPoint.y, y = 0; j < this.maxPoint.y; j += this.stepSize, y++) {
80
+ const t = this.sizePoly
81
+ .clone()
82
+ .loop()
83
+ .move(i, j)
84
+ .run()
85
+ .setProperties({
86
+ x,
87
+ y
88
+ });
89
+ this.cells[x][y] = t;
90
+ this.allCells.push(t);
91
+ }
92
+ }
93
+ }
94
+ }
@@ -0,0 +1,131 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __read = (this && this.__read) || function (o, n) {
13
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
14
+ if (!m) return o;
15
+ var i = m.call(o), r, ar = [], e;
16
+ try {
17
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
+ }
19
+ catch (error) { e = { error: error }; }
20
+ finally {
21
+ try {
22
+ if (r && !r.done && (m = i["return"])) m.call(i);
23
+ }
24
+ finally { if (e) throw e.error; }
25
+ }
26
+ return ar;
27
+ };
28
+ import { DPolygon } from './DPolygon';
29
+ import { DPoint } from './DPoint';
30
+ import { isDefAndNotNull } from './utils';
31
+ var InterpolationMatrix = (function () {
32
+ function InterpolationMatrix(bboxLike, stepSize, keys, p) {
33
+ if (p === void 0) { p = 2; }
34
+ this.stepSize = stepSize;
35
+ this.p = p;
36
+ this.points = [];
37
+ this.cells = {};
38
+ this.allCells = [];
39
+ this.minPoint = bboxLike.leftTop;
40
+ this.maxPoint = bboxLike.rightBottom;
41
+ this.sizePoly = DPolygon.createSquareBySize(new DPoint(this.stepSize));
42
+ this.keys = Array.isArray(keys) ? keys : [keys];
43
+ this.generateCells();
44
+ }
45
+ InterpolationMatrix.prototype.setKnownPoints = function (points) {
46
+ this.points = points instanceof DPolygon ? points.points : points;
47
+ return this;
48
+ };
49
+ InterpolationMatrix.prototype.positionToCellCoords = function (d) {
50
+ return d.clone()
51
+ .move(this.minPoint.clone().minus())
52
+ .divide(this.stepSize)
53
+ .floor();
54
+ };
55
+ InterpolationMatrix.prototype.calculate = function () {
56
+ this.setKnownValues();
57
+ this.interpolateValues();
58
+ return this;
59
+ };
60
+ InterpolationMatrix.prototype.getCellValue = function (_a, key) {
61
+ var x = _a.x, y = _a.y;
62
+ var cell = this.cells[x][y];
63
+ if (key) {
64
+ if (Array.isArray(key)) {
65
+ return key.reduce(function (a, k) {
66
+ a[k] = cell.properties[k];
67
+ return a;
68
+ }, {});
69
+ }
70
+ return cell.properties[key];
71
+ }
72
+ return __assign({}, cell.properties);
73
+ };
74
+ Object.defineProperty(InterpolationMatrix.prototype, "allCellsClone", {
75
+ get: function () {
76
+ return this.allCells.map(function (p) { return p.clone(); });
77
+ },
78
+ enumerable: false,
79
+ configurable: true
80
+ });
81
+ InterpolationMatrix.prototype.interpolateValues = function () {
82
+ var _this = this;
83
+ var points = this.points.map(function (p) { return _this.positionToCellCoords(p); });
84
+ this.allCells.forEach(function (cell) {
85
+ var t = new DPoint(cell.properties.x, cell.properties.y);
86
+ var distances = points.map(function (p) { return Math.pow(t.distance(p), _this.p); });
87
+ _this.keys.forEach(function (k) {
88
+ if (isDefAndNotNull(cell.properties[k])) {
89
+ return;
90
+ }
91
+ var _a = __read(distances.reduce(function (a, d, i) {
92
+ if (isDefAndNotNull(_this.points[i].properties[k])) {
93
+ a[0] += _this.points[i].properties[k] / d;
94
+ a[1] += 1 / d;
95
+ }
96
+ return a;
97
+ }, [0, 0]), 2), valueSum = _a[0], oneSum = _a[1];
98
+ cell.properties[k] = valueSum / oneSum;
99
+ });
100
+ });
101
+ };
102
+ InterpolationMatrix.prototype.setKnownValues = function () {
103
+ var _this = this;
104
+ this.points.forEach(function (p) {
105
+ var _a = _this.positionToCellCoords(p), x = _a.x, y = _a.y;
106
+ _this.keys.forEach(function (k) {
107
+ _this.cells[x][y].properties[k] = p.properties[k];
108
+ });
109
+ });
110
+ };
111
+ InterpolationMatrix.prototype.generateCells = function () {
112
+ for (var i = this.minPoint.x, x = 0; i < this.maxPoint.x; i += this.stepSize, x++) {
113
+ this.cells[x] = this.cells[x] || {};
114
+ for (var j = this.minPoint.y, y = 0; j < this.maxPoint.y; j += this.stepSize, y++) {
115
+ var t = this.sizePoly
116
+ .clone()
117
+ .loop()
118
+ .move(i, j)
119
+ .run()
120
+ .setProperties({
121
+ x: x,
122
+ y: y
123
+ });
124
+ this.cells[x][y] = t;
125
+ this.allCells.push(t);
126
+ }
127
+ }
128
+ };
129
+ return InterpolationMatrix;
130
+ }());
131
+ export { InterpolationMatrix };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dgeoutils",
3
- "version": "2.4.26",
3
+ "version": "2.4.27",
4
4
  "description": "Geometries utils for my projects",
5
5
  "scripts": {
6
6
  "build": "npm run build:es2015 && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min",