Skip to content

Commit 902c432

Browse files
Merge branch 'master' into turf-clusters-dbscan
2 parents c8bb113 + c8b37e8 commit 902c432

File tree

294 files changed

+3552
-5273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

294 files changed

+3552
-5273
lines changed

.monorepolint.config.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const path = require("path");
2-
const glob = require("glob");
2+
const { glob } = require("glob");
33
const fs = require("fs");
44

55
const TS_PACKAGES: string[] = []; // projects that use typescript to build
@@ -249,28 +249,30 @@ module.exports = {
249249
{
250250
options: {
251251
devDependencies: {
252-
"npm-run-all": "*",
252+
benchmark: "^2.1.4",
253+
"npm-run-all": "^4.1.5",
254+
tape: "^5.7.2",
255+
tsx: "^3.14.0",
253256
},
254257
},
255258
includePackages: [...TS_PACKAGES, ...JS_PACKAGES],
256259
},
257260
{
258261
options: {
259262
dependencies: {
260-
tslib: "^2.3.0",
263+
tslib: "^2.6.2",
261264
},
262265
devDependencies: {
263-
tsx: "*",
264-
typescript: "*",
266+
"@types/tape": "^4.2.32",
267+
typescript: "^5.2.2",
265268
},
266269
},
267270
includePackages: TS_PACKAGES,
268271
},
269272
{
270273
options: {
271274
devDependencies: {
272-
rollup: "*",
273-
tsx: "*",
275+
rollup: "^2.79.1",
274276
},
275277
},
276278
includePackages: JS_PACKAGES,

package.json

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,33 @@
4040
"devDependencies": {
4141
"@types/geojson": "7946.0.8",
4242
"@types/node": "18.11.9",
43-
"@typescript-eslint/eslint-plugin": "^6.8.0",
44-
"@typescript-eslint/parser": "^6.8.0",
43+
"@typescript-eslint/eslint-plugin": "^6.10.0",
44+
"@typescript-eslint/parser": "^6.10.0",
4545
"acorn": "^7.4.1",
46-
"camelcase": "*",
46+
"camelcase": "^8.0.0",
4747
"d3-queue": "*",
48-
"decamelize": "*",
48+
"decamelize": "^6.0.0",
4949
"dependency-tree": "^8.1.2",
50-
"documentation": "^14.0.2",
50+
"documentation": "^13.2.5",
5151
"es-check": "^7.1.1",
52-
"eslint": "^8.51.0",
52+
"eslint": "^8.53.0",
5353
"eslint-config-prettier": "^9.0.0",
5454
"eslint-plugin-prettier": "^5.0.1",
5555
"esm": "^3.2.25",
56-
"fs-extra": "*",
57-
"husky": "^4.2.3",
58-
"lerna": "^7.3.0",
59-
"lint-staged": "^10.0.8",
60-
"load-json-file": "*",
61-
"meow": "*",
56+
"fs-extra": "^11.1.1",
57+
"husky": "^4.3.8",
58+
"lerna": "^7.4.2",
59+
"lint-staged": "^10.5.4",
60+
"load-json-file": "^7.0.1",
61+
"meow": "^12.1.1",
6262
"monorepolint": "^0.5.0-alpha.20",
6363
"npm-run-all": "^4.1.5",
6464
"prettier": "^3.0.3",
65-
"progress": "*",
66-
"rollup": "^2.34.2",
67-
"tape": "^5.7.0",
65+
"progress": "^2.0.3",
66+
"rollup": "^2.79.1",
6867
"ts-node": "^9.0.0",
69-
"tsx": "^3.12.8",
68+
"tsx": "^3.14.0",
7069
"typescript": "^5.2.2",
71-
"yamljs": "*"
70+
"yamljs": "^0.3.0"
7271
}
7372
}

packages/turf-along/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@
4848
"test:tape": "tsx test.js"
4949
},
5050
"devDependencies": {
51-
"@types/tape": "*",
52-
"benchmark": "*",
53-
"load-json-file": "*",
54-
"npm-run-all": "*",
55-
"tape": "*",
56-
"tsx": "*",
57-
"typescript": "*"
51+
"@types/tape": "^4.2.32",
52+
"benchmark": "^2.1.4",
53+
"load-json-file": "^7.0.1",
54+
"npm-run-all": "^4.1.5",
55+
"tape": "^5.7.2",
56+
"tsx": "^3.14.0",
57+
"typescript": "^5.2.2"
5858
},
5959
"dependencies": {
6060
"@turf/bearing": "^7.0.0-alpha.2",
6161
"@turf/destination": "^7.0.0-alpha.2",
6262
"@turf/distance": "^7.0.0-alpha.2",
6363
"@turf/helpers": "^7.0.0-alpha.2",
6464
"@turf/invariant": "^7.0.0-alpha.2",
65-
"tslib": "^2.3.0"
65+
"tslib": "^2.6.2"
6666
}
6767
}

packages/turf-along/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const path = require("path");
22
const test = require("tape");
3-
const load = require("load-json-file");
3+
const { loadJsonFileSync } = require("load-json-file");
44
const { featureCollection } = require("@turf/helpers");
55
const along = require("./index").default;
66

7-
const line = load.sync(
7+
const line = loadJsonFileSync(
88
path.join(__dirname, "test", "fixtures", "dc-line.geojson")
99
);
1010

packages/turf-angle/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@
5151
"@turf/distance": "^7.0.0-alpha.2",
5252
"@turf/sector": "^7.0.0-alpha.2",
5353
"@turf/truncate": "^7.0.0-alpha.2",
54-
"@types/tape": "*",
55-
"benchmark": "*",
56-
"glob": "*",
57-
"load-json-file": "*",
58-
"npm-run-all": "*",
59-
"tape": "*",
60-
"tsx": "*",
61-
"typescript": "*",
62-
"write-json-file": "*"
54+
"@types/tape": "^4.2.32",
55+
"benchmark": "^2.1.4",
56+
"glob": "^10.3.10",
57+
"load-json-file": "^7.0.1",
58+
"npm-run-all": "^4.1.5",
59+
"tape": "^5.7.2",
60+
"tsx": "^3.14.0",
61+
"typescript": "^5.2.2",
62+
"write-json-file": "^5.0.0"
6363
},
6464
"dependencies": {
6565
"@turf/bearing": "^7.0.0-alpha.2",
6666
"@turf/helpers": "^7.0.0-alpha.2",
6767
"@turf/invariant": "^7.0.0-alpha.2",
6868
"@turf/rhumb-bearing": "^7.0.0-alpha.2",
69-
"tslib": "^2.3.0"
69+
"tslib": "^2.6.2"
7070
}
7171
}

packages/turf-angle/test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const test = require("tape");
22
const path = require("path");
3-
const glob = require("glob");
4-
const load = require("load-json-file");
5-
const write = require("write-json-file");
3+
const { glob } = require("glob");
4+
const { loadJsonFileSync } = require("load-json-file");
5+
const { writeJsonFileSync } = require("write-json-file");
66
const sector = require("@turf/sector");
77
const bearing = require("@turf/bearing").default;
88
const truncate = require("@turf/truncate").default;
@@ -21,7 +21,7 @@ test("turf-angle", (t) => {
2121
.forEach((filepath) => {
2222
// Input
2323
const { name } = path.parse(filepath);
24-
const geojson = load.sync(filepath);
24+
const geojson = loadJsonFileSync(filepath);
2525
const [start, mid, end] = geojson.features;
2626

2727
// Results
@@ -87,8 +87,8 @@ test("turf-angle", (t) => {
8787
path.join("test", "in"),
8888
path.join("test", "out")
8989
);
90-
if (process.env.REGEN) write.sync(expected, results);
91-
t.deepEqual(results, load.sync(expected), name);
90+
if (process.env.REGEN) writeJsonFileSync(expected, results);
91+
t.deepEqual(results, loadJsonFileSync(expected), name);
9292
});
9393
t.end();
9494
});

packages/turf-area/bench.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require("fs");
22
const path = require("path");
3-
const load = require("load-json-file");
3+
const { loadJsonFileSync } = require("load-json-file");
44
const Benchmark = require("benchmark");
55
const area = require("./index").default;
66

@@ -10,14 +10,14 @@ const fixtures = fs.readdirSync(directory).map((filename) => {
1010
return {
1111
filename,
1212
name: path.parse(filename).name,
13-
geojson: load.sync(directory + filename),
13+
geojson: loadJsonFileSync(directory + filename),
1414
};
1515
});
1616

1717
/**
1818
* Benmark Results
1919
*
20-
* polygon x 3,240,248 ops/sec ±0.91% (90 runs sampled)
20+
* polygon x 8,510,024 ops/sec ±0.28% (96 runs sampled)
2121
*/
2222

2323
// Define benchmark

packages/turf-area/index.ts

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ function polygonArea(coords: any) {
6767
return total;
6868
}
6969

70+
/**
71+
* @private
72+
* A constant factor used to compute the area of a polygon.
73+
* It's derived from the square of the Earth's radius divided by 2.
74+
*
75+
* @type {number}
76+
*/
77+
const FACTOR = (earthRadius * earthRadius) / 2;
78+
79+
/**
80+
* @private
81+
* A constant used for converting degrees to radians.
82+
* Represents the ratio of PI to 180.
83+
*
84+
* @type {number}
85+
*/
86+
const PI_OVER_180 = Math.PI / 180;
87+
7088
/**
7189
* @private
7290
* Calculate the approximate area of the polygon were it projected onto the earth.
@@ -80,46 +98,27 @@ function polygonArea(coords: any) {
8098
* @param {Array<Array<number>>} coords Ring Coordinates
8199
* @returns {number} The approximate signed geodesic area of the polygon in square meters.
82100
*/
83-
function ringArea(coords: number[][]) {
84-
let p1;
85-
let p2;
86-
let p3;
87-
let lowerIndex;
88-
let middleIndex;
89-
let upperIndex;
90-
let i;
91-
let total = 0;
101+
function ringArea(coords: number[][]): number {
92102
const coordsLength = coords.length;
93103

94-
if (coordsLength > 2) {
95-
for (i = 0; i < coordsLength; i++) {
96-
if (i === coordsLength - 2) {
97-
// i = N-2
98-
lowerIndex = coordsLength - 2;
99-
middleIndex = coordsLength - 1;
100-
upperIndex = 0;
101-
} else if (i === coordsLength - 1) {
102-
// i = N-1
103-
lowerIndex = coordsLength - 1;
104-
middleIndex = 0;
105-
upperIndex = 1;
106-
} else {
107-
// i = 0 to N-3
108-
lowerIndex = i;
109-
middleIndex = i + 1;
110-
upperIndex = i + 2;
111-
}
112-
p1 = coords[lowerIndex];
113-
p2 = coords[middleIndex];
114-
p3 = coords[upperIndex];
115-
total += (rad(p3[0]) - rad(p1[0])) * Math.sin(rad(p2[1]));
116-
}
104+
if (coordsLength <= 2) return 0;
105+
let total = 0;
117106

118-
total = (total * earthRadius * earthRadius) / 2;
107+
let i = 0;
108+
while (i < coordsLength) {
109+
const lower = coords[i];
110+
const middle = coords[i + 1 === coordsLength ? 0 : i + 1];
111+
const upper =
112+
coords[i + 2 >= coordsLength ? (i + 2) % coordsLength : i + 2];
113+
114+
const lowerX = lower[0] * PI_OVER_180;
115+
const middleY = middle[1] * PI_OVER_180;
116+
const upperX = upper[0] * PI_OVER_180;
117+
118+
total += (upperX - lowerX) * Math.sin(middleY);
119+
120+
i++;
119121
}
120-
return total;
121-
}
122122

123-
function rad(num: number) {
124-
return (num * Math.PI) / 180;
123+
return total * FACTOR;
125124
}

packages/turf-area/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@
4747
"test:tape": "tsx test.js"
4848
},
4949
"devDependencies": {
50-
"@types/tape": "*",
51-
"benchmark": "*",
52-
"load-json-file": "*",
53-
"npm-run-all": "*",
54-
"tape": "*",
55-
"tsx": "*",
56-
"typescript": "*",
57-
"write-json-file": "*"
50+
"@types/tape": "^4.2.32",
51+
"benchmark": "^2.1.4",
52+
"load-json-file": "^7.0.1",
53+
"npm-run-all": "^4.1.5",
54+
"tape": "^5.7.2",
55+
"tsx": "^3.14.0",
56+
"typescript": "^5.2.2",
57+
"write-json-file": "^5.0.0"
5858
},
5959
"dependencies": {
6060
"@turf/helpers": "^7.0.0-alpha.2",
6161
"@turf/meta": "^7.0.0-alpha.2",
62-
"tslib": "^2.3.0"
62+
"tslib": "^2.6.2"
6363
}
6464
}

packages/turf-area/test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const fs = require("fs");
22
const test = require("tape");
33
const path = require("path");
4-
const load = require("load-json-file");
5-
const write = require("write-json-file");
4+
const { loadJsonFileSync } = require("load-json-file");
5+
const { writeJsonFileSync } = require("write-json-file");
66
const area = require("./index").default;
77

88
const directories = {
@@ -14,7 +14,7 @@ const fixtures = fs.readdirSync(directories.in).map((filename) => {
1414
return {
1515
filename,
1616
name: path.parse(filename).name,
17-
geojson: load.sync(directories.in + filename),
17+
geojson: loadJsonFileSync(directories.in + filename),
1818
};
1919
});
2020

@@ -24,8 +24,8 @@ test("turf-area", (t) => {
2424
const geojson = fixture.geojson;
2525
const results = Math.round(area(geojson));
2626
if (process.env.REGEN)
27-
write.sync(directories.out + name + ".json", results);
28-
t.equal(results, load.sync(directories.out + name + ".json"), name);
27+
writeJsonFileSync(directories.out + name + ".json", results);
28+
t.equal(results, loadJsonFileSync(directories.out + name + ".json"), name);
2929
}
3030
t.end();
3131
});

packages/turf-bbox-clip/bench.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require("fs");
22
const path = require("path");
3-
const load = require("load-json-file");
3+
const { loadJsonFileSync } = require("load-json-file");
44
const Benchmark = require("benchmark");
55
const bbox = require("@turf/bbox").default;
66
const bboxClip = require("./index").default;
@@ -10,7 +10,7 @@ const fixtures = fs.readdirSync(directory).map((filename) => {
1010
return {
1111
filename,
1212
name: path.parse(filename).name,
13-
geojson: load.sync(directory + filename),
13+
geojson: loadJsonFileSync(directory + filename),
1414
};
1515
});
1616

0 commit comments

Comments
 (0)