@turf/directional-mean 6.5.0 → 7.0.0-alpha.0
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/README.md +30 -17
- package/dist/es/index.js +57 -58
- package/dist/js/index.d.ts +1 -1
- package/dist/js/index.js +65 -68
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
## DirectionalMeanLine
|
|
6
6
|
|
|
7
|
-
Type: [Object]
|
|
7
|
+
Type: [Object][1]
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Properties
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
* `cartesianAngle` **[number][2]** the mean angle of all lines. (measure from due earth counterclockwise).
|
|
12
|
+
* `bearingAngle` **[number][2]** the mean angle of all lines. (bearing).
|
|
13
|
+
* `circularVariance` **[number][2]** the extent to which features all point in the same direction.
|
|
14
|
+
the value ranges 0-1, the bigger the value, the more variation in directions between lines.
|
|
15
|
+
* `averageX` **[number][2]** the centroid of all lines.
|
|
16
|
+
* `averageY` **[number][2]** the centroid of all line.
|
|
17
|
+
* `averageLength` **[number][2]** the average length of line.
|
|
18
|
+
* `countOfLines` **[number][2]** the count of features.
|
|
19
19
|
|
|
20
20
|
## directionalMean
|
|
21
21
|
|
|
@@ -23,14 +23,15 @@ This module calculate the average angle of a set of lines, measuring the trend o
|
|
|
23
23
|
It can be used in both project coordinate system and geography coordinate system.
|
|
24
24
|
It can handle segments of line or the whole line.
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
### Parameters
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- `options.planar` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether the spatial reference system is projected or geographical. (optional, default `true`)
|
|
31
|
-
- `options.segment` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether treat a LineString as a whole or a set of segments. (optional, default `false`)
|
|
28
|
+
* `lines` **[FeatureCollection][3]<[LineString][4]>**
|
|
29
|
+
* `options` **[object][1]** (optional, default `{}`)
|
|
32
30
|
|
|
33
|
-
**
|
|
31
|
+
* `options.planar` **[boolean][5]** whether the spatial reference system is projected or geographical. (optional, default `true`)
|
|
32
|
+
* `options.segment` **[boolean][5]** whether treat a LineString as a whole or a set of segments. (optional, default `false`)
|
|
33
|
+
|
|
34
|
+
### Examples
|
|
34
35
|
|
|
35
36
|
```javascript
|
|
36
37
|
var lines = turf.lineStrings([
|
|
@@ -41,7 +42,19 @@ var directionalMeanLine = turf.directionalMean(lines);
|
|
|
41
42
|
// => directionalMeanLine
|
|
42
43
|
```
|
|
43
44
|
|
|
44
|
-
Returns **[DirectionalMeanLine]
|
|
45
|
+
Returns **[DirectionalMeanLine][6]** Directional Mean Line
|
|
46
|
+
|
|
47
|
+
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
48
|
+
|
|
49
|
+
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
|
50
|
+
|
|
51
|
+
[3]: https://tools.ietf.org/html/rfc7946#section-3.3
|
|
52
|
+
|
|
53
|
+
[4]: https://tools.ietf.org/html/rfc7946#section-3.1.4
|
|
54
|
+
|
|
55
|
+
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
56
|
+
|
|
57
|
+
[6]: #directionalmeanline
|
|
45
58
|
|
|
46
59
|
<!-- This file is automatically generated. Please don't edit it directly:
|
|
47
60
|
if you find an error, edit the source file (likely index.js), and re-run
|
package/dist/es/index.js
CHANGED
|
@@ -35,20 +35,19 @@ import { featureEach, segmentEach, segmentReduce } from "@turf/meta";
|
|
|
35
35
|
* var directionalMeanLine = turf.directionalMean(lines);
|
|
36
36
|
* // => directionalMeanLine
|
|
37
37
|
*/
|
|
38
|
-
export default function directionalMean(lines, options) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var centroidList = [];
|
|
38
|
+
export default function directionalMean(lines, options = {}) {
|
|
39
|
+
const isPlanar = !!options.planar; // you can't use options.planar || true here.
|
|
40
|
+
const isSegment = options.segment || false;
|
|
41
|
+
let sigmaSin = 0;
|
|
42
|
+
let sigmaCos = 0;
|
|
43
|
+
let countOfLines = 0;
|
|
44
|
+
let sumOfLen = 0;
|
|
45
|
+
const centroidList = [];
|
|
47
46
|
if (isSegment) {
|
|
48
|
-
segmentEach(lines,
|
|
47
|
+
segmentEach(lines, (currentSegment) => {
|
|
49
48
|
// todo fix turf-meta's declaration file
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
const [sin1, cos1] = getCosAndSin(currentSegment.geometry.coordinates, isPlanar);
|
|
50
|
+
const lenOfLine = getLengthOfLineString(currentSegment, isPlanar);
|
|
52
51
|
if (isNaN(sin1) || isNaN(cos1)) {
|
|
53
52
|
return;
|
|
54
53
|
}
|
|
@@ -64,12 +63,12 @@ export default function directionalMean(lines, options) {
|
|
|
64
63
|
}
|
|
65
64
|
else {
|
|
66
65
|
// planar and non-segment
|
|
67
|
-
featureEach(lines,
|
|
66
|
+
featureEach(lines, (currentFeature) => {
|
|
68
67
|
if (currentFeature.geometry.type !== "LineString") {
|
|
69
68
|
throw new Error("shold to support MultiLineString?");
|
|
70
69
|
}
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const [sin1, cos1] = getCosAndSin(currentFeature.geometry.coordinates, isPlanar);
|
|
71
|
+
const lenOfLine = getLengthOfLineString(currentFeature, isPlanar);
|
|
73
72
|
if (isNaN(sin1) || isNaN(cos1)) {
|
|
74
73
|
return;
|
|
75
74
|
}
|
|
@@ -82,13 +81,13 @@ export default function directionalMean(lines, options) {
|
|
|
82
81
|
}
|
|
83
82
|
});
|
|
84
83
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
const cartesianAngle = getAngleBySinAndCos(sigmaSin, sigmaCos);
|
|
85
|
+
const bearingAngle = bearingToCartesian(cartesianAngle);
|
|
86
|
+
const circularVariance = getCircularVariance(sigmaSin, sigmaCos, countOfLines);
|
|
87
|
+
const averageLength = sumOfLen / countOfLines;
|
|
88
|
+
const centroidOfLines = centroid(featureCollection(centroidList));
|
|
89
|
+
const [averageX, averageY] = getCoord(centroidOfLines);
|
|
90
|
+
let meanLinestring;
|
|
92
91
|
if (isPlanar) {
|
|
93
92
|
meanLinestring = getMeanLineString([averageX, averageY], cartesianAngle, averageLength, isPlanar);
|
|
94
93
|
}
|
|
@@ -96,13 +95,13 @@ export default function directionalMean(lines, options) {
|
|
|
96
95
|
meanLinestring = getMeanLineString([averageX, averageY], bearingAngle, averageLength, isPlanar);
|
|
97
96
|
}
|
|
98
97
|
return lineString(meanLinestring, {
|
|
99
|
-
averageLength
|
|
100
|
-
averageX
|
|
101
|
-
averageY
|
|
102
|
-
bearingAngle
|
|
103
|
-
cartesianAngle
|
|
104
|
-
circularVariance
|
|
105
|
-
countOfLines
|
|
98
|
+
averageLength,
|
|
99
|
+
averageX,
|
|
100
|
+
averageY,
|
|
101
|
+
bearingAngle,
|
|
102
|
+
cartesianAngle,
|
|
103
|
+
circularVariance,
|
|
104
|
+
countOfLines,
|
|
106
105
|
});
|
|
107
106
|
}
|
|
108
107
|
/**
|
|
@@ -112,10 +111,10 @@ export default function directionalMean(lines, options) {
|
|
|
112
111
|
* @param coords
|
|
113
112
|
*/
|
|
114
113
|
function euclideanDistance(coords) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
const [x0, y0] = coords[0];
|
|
115
|
+
const [x1, y1] = coords[1];
|
|
116
|
+
const dx = x1 - x0;
|
|
117
|
+
const dy = y1 - y0;
|
|
119
118
|
return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
|
120
119
|
}
|
|
121
120
|
/**
|
|
@@ -127,8 +126,8 @@ function euclideanDistance(coords) {
|
|
|
127
126
|
*/
|
|
128
127
|
function getLengthOfLineString(line, isPlanar) {
|
|
129
128
|
if (isPlanar) {
|
|
130
|
-
return segmentReduce(line,
|
|
131
|
-
|
|
129
|
+
return segmentReduce(line, (previousValue, segment) => {
|
|
130
|
+
const coords = segment.geometry.coordinates; // the signatrue of segmentReduce has problem ?
|
|
132
131
|
return previousValue + euclideanDistance(coords);
|
|
133
132
|
}, 0);
|
|
134
133
|
}
|
|
@@ -146,7 +145,7 @@ function getLengthOfLineString(line, isPlanar) {
|
|
|
146
145
|
* @param angle
|
|
147
146
|
*/
|
|
148
147
|
function bearingToCartesian(angle) {
|
|
149
|
-
|
|
148
|
+
let result = 90 - angle;
|
|
150
149
|
if (result > 180) {
|
|
151
150
|
result -= 360;
|
|
152
151
|
}
|
|
@@ -159,29 +158,29 @@ function bearingToCartesian(angle) {
|
|
|
159
158
|
* @returns {Array<number>} [cos, sin]
|
|
160
159
|
*/
|
|
161
160
|
function getCosAndSin(coordinates, isPlanar) {
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
const beginPoint = coordinates[0];
|
|
162
|
+
const endPoint = coordinates[coordinates.length - 1];
|
|
164
163
|
if (isPlanar) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
164
|
+
const [x0, y0] = beginPoint;
|
|
165
|
+
const [x1, y1] = endPoint;
|
|
166
|
+
const dx = x1 - x0;
|
|
167
|
+
const dy = y1 - y0;
|
|
168
|
+
const h = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
|
170
169
|
if (h < 0.000000001) {
|
|
171
170
|
return [NaN, NaN];
|
|
172
171
|
}
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
const sin1 = dy / h;
|
|
173
|
+
const cos1 = dx / h;
|
|
175
174
|
return [sin1, cos1];
|
|
176
175
|
}
|
|
177
176
|
else {
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
const angle = bearingToCartesian(bearing(beginPoint, endPoint));
|
|
178
|
+
const radian = (angle * Math.PI) / 180;
|
|
180
179
|
return [Math.sin(radian), Math.cos(radian)];
|
|
181
180
|
}
|
|
182
181
|
}
|
|
183
182
|
function getAngleBySinAndCos(sin1, cos1) {
|
|
184
|
-
|
|
183
|
+
let angle = 0;
|
|
185
184
|
if (Math.abs(cos1) < 0.000000001) {
|
|
186
185
|
angle = 90;
|
|
187
186
|
}
|
|
@@ -208,14 +207,14 @@ function getCircularVariance(sin1, cos1, len) {
|
|
|
208
207
|
}
|
|
209
208
|
function getMeanLineString(centroidOfLine, angle, lenOfLine, isPlanar) {
|
|
210
209
|
if (isPlanar) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
210
|
+
const [averageX, averageY] = centroidOfLine;
|
|
211
|
+
let beginX;
|
|
212
|
+
let beginY;
|
|
213
|
+
let endX;
|
|
214
|
+
let endY;
|
|
215
|
+
const r = (angle * Math.PI) / 180;
|
|
216
|
+
const sin = Math.sin(r);
|
|
217
|
+
const cos = Math.cos(r);
|
|
219
218
|
beginX = averageX - (lenOfLine / 2) * cos;
|
|
220
219
|
beginY = averageY - (lenOfLine / 2) * sin;
|
|
221
220
|
endX = averageX + (lenOfLine / 2) * cos;
|
|
@@ -226,10 +225,10 @@ function getMeanLineString(centroidOfLine, angle, lenOfLine, isPlanar) {
|
|
|
226
225
|
];
|
|
227
226
|
}
|
|
228
227
|
else {
|
|
229
|
-
|
|
228
|
+
const end = destination(point(centroidOfLine), lenOfLine / 2, angle, {
|
|
230
229
|
units: "meters",
|
|
231
230
|
});
|
|
232
|
-
|
|
231
|
+
const begin = destination(point(centroidOfLine), -lenOfLine / 2, angle, {
|
|
233
232
|
units: "meters",
|
|
234
233
|
});
|
|
235
234
|
return [getCoord(begin), getCoord(end)];
|
package/dist/js/index.d.ts
CHANGED
package/dist/js/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const bearing_1 = tslib_1.__importDefault(require("@turf/bearing"));
|
|
5
|
+
const centroid_1 = tslib_1.__importDefault(require("@turf/centroid"));
|
|
6
|
+
const destination_1 = tslib_1.__importDefault(require("@turf/destination"));
|
|
7
|
+
const helpers_1 = require("@turf/helpers");
|
|
8
|
+
const invariant_1 = require("@turf/invariant");
|
|
9
|
+
const length_1 = tslib_1.__importDefault(require("@turf/length"));
|
|
10
|
+
const meta_1 = require("@turf/meta");
|
|
13
11
|
/**
|
|
14
12
|
* @typedef {Object} DirectionalMeanLine
|
|
15
13
|
* @property {number} cartesianAngle the mean angle of all lines. (measure from due earth counterclockwise).
|
|
@@ -40,20 +38,19 @@ var meta_1 = require("@turf/meta");
|
|
|
40
38
|
* var directionalMeanLine = turf.directionalMean(lines);
|
|
41
39
|
* // => directionalMeanLine
|
|
42
40
|
*/
|
|
43
|
-
function directionalMean(lines, options) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var centroidList = [];
|
|
41
|
+
function directionalMean(lines, options = {}) {
|
|
42
|
+
const isPlanar = !!options.planar; // you can't use options.planar || true here.
|
|
43
|
+
const isSegment = options.segment || false;
|
|
44
|
+
let sigmaSin = 0;
|
|
45
|
+
let sigmaCos = 0;
|
|
46
|
+
let countOfLines = 0;
|
|
47
|
+
let sumOfLen = 0;
|
|
48
|
+
const centroidList = [];
|
|
52
49
|
if (isSegment) {
|
|
53
|
-
meta_1.segmentEach(lines,
|
|
50
|
+
meta_1.segmentEach(lines, (currentSegment) => {
|
|
54
51
|
// todo fix turf-meta's declaration file
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
const [sin1, cos1] = getCosAndSin(currentSegment.geometry.coordinates, isPlanar);
|
|
53
|
+
const lenOfLine = getLengthOfLineString(currentSegment, isPlanar);
|
|
57
54
|
if (isNaN(sin1) || isNaN(cos1)) {
|
|
58
55
|
return;
|
|
59
56
|
}
|
|
@@ -69,12 +66,12 @@ function directionalMean(lines, options) {
|
|
|
69
66
|
}
|
|
70
67
|
else {
|
|
71
68
|
// planar and non-segment
|
|
72
|
-
meta_1.featureEach(lines,
|
|
69
|
+
meta_1.featureEach(lines, (currentFeature) => {
|
|
73
70
|
if (currentFeature.geometry.type !== "LineString") {
|
|
74
71
|
throw new Error("shold to support MultiLineString?");
|
|
75
72
|
}
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
const [sin1, cos1] = getCosAndSin(currentFeature.geometry.coordinates, isPlanar);
|
|
74
|
+
const lenOfLine = getLengthOfLineString(currentFeature, isPlanar);
|
|
78
75
|
if (isNaN(sin1) || isNaN(cos1)) {
|
|
79
76
|
return;
|
|
80
77
|
}
|
|
@@ -87,13 +84,13 @@ function directionalMean(lines, options) {
|
|
|
87
84
|
}
|
|
88
85
|
});
|
|
89
86
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
const cartesianAngle = getAngleBySinAndCos(sigmaSin, sigmaCos);
|
|
88
|
+
const bearingAngle = bearingToCartesian(cartesianAngle);
|
|
89
|
+
const circularVariance = getCircularVariance(sigmaSin, sigmaCos, countOfLines);
|
|
90
|
+
const averageLength = sumOfLen / countOfLines;
|
|
91
|
+
const centroidOfLines = centroid_1.default(helpers_1.featureCollection(centroidList));
|
|
92
|
+
const [averageX, averageY] = invariant_1.getCoord(centroidOfLines);
|
|
93
|
+
let meanLinestring;
|
|
97
94
|
if (isPlanar) {
|
|
98
95
|
meanLinestring = getMeanLineString([averageX, averageY], cartesianAngle, averageLength, isPlanar);
|
|
99
96
|
}
|
|
@@ -101,13 +98,13 @@ function directionalMean(lines, options) {
|
|
|
101
98
|
meanLinestring = getMeanLineString([averageX, averageY], bearingAngle, averageLength, isPlanar);
|
|
102
99
|
}
|
|
103
100
|
return helpers_1.lineString(meanLinestring, {
|
|
104
|
-
averageLength
|
|
105
|
-
averageX
|
|
106
|
-
averageY
|
|
107
|
-
bearingAngle
|
|
108
|
-
cartesianAngle
|
|
109
|
-
circularVariance
|
|
110
|
-
countOfLines
|
|
101
|
+
averageLength,
|
|
102
|
+
averageX,
|
|
103
|
+
averageY,
|
|
104
|
+
bearingAngle,
|
|
105
|
+
cartesianAngle,
|
|
106
|
+
circularVariance,
|
|
107
|
+
countOfLines,
|
|
111
108
|
});
|
|
112
109
|
}
|
|
113
110
|
exports.default = directionalMean;
|
|
@@ -118,10 +115,10 @@ exports.default = directionalMean;
|
|
|
118
115
|
* @param coords
|
|
119
116
|
*/
|
|
120
117
|
function euclideanDistance(coords) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
const [x0, y0] = coords[0];
|
|
119
|
+
const [x1, y1] = coords[1];
|
|
120
|
+
const dx = x1 - x0;
|
|
121
|
+
const dy = y1 - y0;
|
|
125
122
|
return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
|
126
123
|
}
|
|
127
124
|
/**
|
|
@@ -133,8 +130,8 @@ function euclideanDistance(coords) {
|
|
|
133
130
|
*/
|
|
134
131
|
function getLengthOfLineString(line, isPlanar) {
|
|
135
132
|
if (isPlanar) {
|
|
136
|
-
return meta_1.segmentReduce(line,
|
|
137
|
-
|
|
133
|
+
return meta_1.segmentReduce(line, (previousValue, segment) => {
|
|
134
|
+
const coords = segment.geometry.coordinates; // the signatrue of segmentReduce has problem ?
|
|
138
135
|
return previousValue + euclideanDistance(coords);
|
|
139
136
|
}, 0);
|
|
140
137
|
}
|
|
@@ -152,7 +149,7 @@ function getLengthOfLineString(line, isPlanar) {
|
|
|
152
149
|
* @param angle
|
|
153
150
|
*/
|
|
154
151
|
function bearingToCartesian(angle) {
|
|
155
|
-
|
|
152
|
+
let result = 90 - angle;
|
|
156
153
|
if (result > 180) {
|
|
157
154
|
result -= 360;
|
|
158
155
|
}
|
|
@@ -165,29 +162,29 @@ function bearingToCartesian(angle) {
|
|
|
165
162
|
* @returns {Array<number>} [cos, sin]
|
|
166
163
|
*/
|
|
167
164
|
function getCosAndSin(coordinates, isPlanar) {
|
|
168
|
-
|
|
169
|
-
|
|
165
|
+
const beginPoint = coordinates[0];
|
|
166
|
+
const endPoint = coordinates[coordinates.length - 1];
|
|
170
167
|
if (isPlanar) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
168
|
+
const [x0, y0] = beginPoint;
|
|
169
|
+
const [x1, y1] = endPoint;
|
|
170
|
+
const dx = x1 - x0;
|
|
171
|
+
const dy = y1 - y0;
|
|
172
|
+
const h = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
|
176
173
|
if (h < 0.000000001) {
|
|
177
174
|
return [NaN, NaN];
|
|
178
175
|
}
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
const sin1 = dy / h;
|
|
177
|
+
const cos1 = dx / h;
|
|
181
178
|
return [sin1, cos1];
|
|
182
179
|
}
|
|
183
180
|
else {
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
const angle = bearingToCartesian(bearing_1.default(beginPoint, endPoint));
|
|
182
|
+
const radian = (angle * Math.PI) / 180;
|
|
186
183
|
return [Math.sin(radian), Math.cos(radian)];
|
|
187
184
|
}
|
|
188
185
|
}
|
|
189
186
|
function getAngleBySinAndCos(sin1, cos1) {
|
|
190
|
-
|
|
187
|
+
let angle = 0;
|
|
191
188
|
if (Math.abs(cos1) < 0.000000001) {
|
|
192
189
|
angle = 90;
|
|
193
190
|
}
|
|
@@ -214,14 +211,14 @@ function getCircularVariance(sin1, cos1, len) {
|
|
|
214
211
|
}
|
|
215
212
|
function getMeanLineString(centroidOfLine, angle, lenOfLine, isPlanar) {
|
|
216
213
|
if (isPlanar) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
214
|
+
const [averageX, averageY] = centroidOfLine;
|
|
215
|
+
let beginX;
|
|
216
|
+
let beginY;
|
|
217
|
+
let endX;
|
|
218
|
+
let endY;
|
|
219
|
+
const r = (angle * Math.PI) / 180;
|
|
220
|
+
const sin = Math.sin(r);
|
|
221
|
+
const cos = Math.cos(r);
|
|
225
222
|
beginX = averageX - (lenOfLine / 2) * cos;
|
|
226
223
|
beginY = averageY - (lenOfLine / 2) * sin;
|
|
227
224
|
endX = averageX + (lenOfLine / 2) * cos;
|
|
@@ -232,10 +229,10 @@ function getMeanLineString(centroidOfLine, angle, lenOfLine, isPlanar) {
|
|
|
232
229
|
];
|
|
233
230
|
}
|
|
234
231
|
else {
|
|
235
|
-
|
|
232
|
+
const end = destination_1.default(helpers_1.point(centroidOfLine), lenOfLine / 2, angle, {
|
|
236
233
|
units: "meters",
|
|
237
234
|
});
|
|
238
|
-
|
|
235
|
+
const begin = destination_1.default(helpers_1.point(centroidOfLine), -lenOfLine / 2, angle, {
|
|
239
236
|
units: "meters",
|
|
240
237
|
});
|
|
241
238
|
return [invariant_1.getCoord(begin), invariant_1.getCoord(end)];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/directional-mean",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.0",
|
|
4
4
|
"description": "turf directional-mean module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -58,13 +58,14 @@
|
|
|
58
58
|
"write-json-file": "*"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@turf/bearing": "^
|
|
62
|
-
"@turf/centroid": "^
|
|
63
|
-
"@turf/destination": "^
|
|
64
|
-
"@turf/helpers": "^
|
|
65
|
-
"@turf/invariant": "^
|
|
66
|
-
"@turf/length": "^
|
|
67
|
-
"@turf/meta": "^
|
|
61
|
+
"@turf/bearing": "^7.0.0-alpha.0",
|
|
62
|
+
"@turf/centroid": "^7.0.0-alpha.0",
|
|
63
|
+
"@turf/destination": "^7.0.0-alpha.0",
|
|
64
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
65
|
+
"@turf/invariant": "^7.0.0-alpha.0",
|
|
66
|
+
"@turf/length": "^7.0.0-alpha.0",
|
|
67
|
+
"@turf/meta": "^7.0.0-alpha.0",
|
|
68
|
+
"tslib": "^2.3.0"
|
|
68
69
|
},
|
|
69
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
70
71
|
}
|