Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
smallsaucepan authored Nov 29, 2023
2 parents f8220b5 + 66f9b2d commit f1450dd
Show file tree
Hide file tree
Showing 370 changed files with 6,211 additions and 11,192 deletions.
16 changes: 9 additions & 7 deletions .monorepolint.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require("path");
const glob = require("glob");
const { glob } = require("glob");
const fs = require("fs");

const TS_PACKAGES: string[] = []; // projects that use typescript to build
Expand Down Expand Up @@ -249,28 +249,30 @@ module.exports = {
{
options: {
devDependencies: {
"npm-run-all": "*",
benchmark: "^2.1.4",
"npm-run-all": "^4.1.5",
tape: "^5.7.2",
tsx: "^3.14.0",
},
},
includePackages: [...TS_PACKAGES, ...JS_PACKAGES],
},
{
options: {
dependencies: {
tslib: "^2.3.0",
tslib: "^2.6.2",
},
devDependencies: {
tsx: "*",
typescript: "*",
"@types/tape": "^4.2.32",
typescript: "^5.2.2",
},
},
includePackages: TS_PACKAGES,
},
{
options: {
devDependencies: {
rollup: "*",
tsx: "*",
rollup: "^2.79.1",
},
},
includePackages: JS_PACKAGES,
Expand Down
33 changes: 16 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,33 @@
"devDependencies": {
"@types/geojson": "7946.0.8",
"@types/node": "18.11.9",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"@typescript-eslint/parser": "^6.10.0",
"acorn": "^7.4.1",
"camelcase": "*",
"camelcase": "^8.0.0",
"d3-queue": "*",
"decamelize": "*",
"decamelize": "^6.0.0",
"dependency-tree": "^8.1.2",
"documentation": "^14.0.2",
"documentation": "^13.2.5",
"es-check": "^7.1.1",
"eslint": "^8.51.0",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"esm": "^3.2.25",
"fs-extra": "*",
"husky": "^4.2.3",
"lerna": "^7.3.0",
"lint-staged": "^10.0.8",
"load-json-file": "*",
"meow": "*",
"fs-extra": "^11.1.1",
"husky": "^4.3.8",
"lerna": "^7.4.2",
"lint-staged": "^10.5.4",
"load-json-file": "^7.0.1",
"meow": "^12.1.1",
"monorepolint": "^0.5.0-alpha.20",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
"progress": "*",
"rollup": "^2.34.2",
"tape": "^5.7.0",
"progress": "^2.0.3",
"rollup": "^2.79.1",
"ts-node": "^9.0.0",
"tsx": "^3.12.8",
"tsx": "^3.14.0",
"typescript": "^5.2.2",
"yamljs": "*"
"yamljs": "^0.3.0"
}
}
16 changes: 8 additions & 8 deletions packages/turf-along/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@
"test:tape": "tsx test.js"
},
"devDependencies": {
"@types/tape": "*",
"benchmark": "*",
"load-json-file": "*",
"npm-run-all": "*",
"tape": "*",
"tsx": "*",
"typescript": "*"
"@types/tape": "^4.2.32",
"benchmark": "^2.1.4",
"load-json-file": "^7.0.1",
"npm-run-all": "^4.1.5",
"tape": "^5.7.2",
"tsx": "^3.14.0",
"typescript": "^5.2.2"
},
"dependencies": {
"@turf/bearing": "^7.0.0-alpha.2",
"@turf/destination": "^7.0.0-alpha.2",
"@turf/distance": "^7.0.0-alpha.2",
"@turf/helpers": "^7.0.0-alpha.2",
"@turf/invariant": "^7.0.0-alpha.2",
"tslib": "^2.3.0"
"tslib": "^2.6.2"
}
}
4 changes: 2 additions & 2 deletions packages/turf-along/test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const path = require("path");
const test = require("tape");
const load = require("load-json-file");
const { loadJsonFileSync } = require("load-json-file");
const { featureCollection } = require("@turf/helpers");
const along = require("./index").default;

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

Expand Down
20 changes: 10 additions & 10 deletions packages/turf-angle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@
"@turf/distance": "^7.0.0-alpha.2",
"@turf/sector": "^7.0.0-alpha.2",
"@turf/truncate": "^7.0.0-alpha.2",
"@types/tape": "*",
"benchmark": "*",
"glob": "*",
"load-json-file": "*",
"npm-run-all": "*",
"tape": "*",
"tsx": "*",
"typescript": "*",
"write-json-file": "*"
"@types/tape": "^4.2.32",
"benchmark": "^2.1.4",
"glob": "^10.3.10",
"load-json-file": "^7.0.1",
"npm-run-all": "^4.1.5",
"tape": "^5.7.2",
"tsx": "^3.14.0",
"typescript": "^5.2.2",
"write-json-file": "^5.0.0"
},
"dependencies": {
"@turf/bearing": "^7.0.0-alpha.2",
"@turf/helpers": "^7.0.0-alpha.2",
"@turf/invariant": "^7.0.0-alpha.2",
"@turf/rhumb-bearing": "^7.0.0-alpha.2",
"tslib": "^2.3.0"
"tslib": "^2.6.2"
}
}
14 changes: 7 additions & 7 deletions packages/turf-angle/test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const test = require("tape");
const path = require("path");
const glob = require("glob");
const load = require("load-json-file");
const write = require("write-json-file");
const sector = require("@turf/sector");
const { glob } = require("glob");
const { loadJsonFileSync } = require("load-json-file");
const { writeJsonFileSync } = require("write-json-file");
const sector = require("@turf/sector").default;
const bearing = require("@turf/bearing").default;
const truncate = require("@turf/truncate").default;
const distance = require("@turf/distance").default;
Expand All @@ -21,7 +21,7 @@ test("turf-angle", (t) => {
.forEach((filepath) => {
// Input
const { name } = path.parse(filepath);
const geojson = load.sync(filepath);
const geojson = loadJsonFileSync(filepath);
const [start, mid, end] = geojson.features;

// Results
Expand Down Expand Up @@ -87,8 +87,8 @@ test("turf-angle", (t) => {
path.join("test", "in"),
path.join("test", "out")
);
if (process.env.REGEN) write.sync(expected, results);
t.deepEqual(results, load.sync(expected), name);
if (process.env.REGEN) writeJsonFileSync(expected, results);
t.deepEqual(results, loadJsonFileSync(expected), name);
});
t.end();
});
Expand Down
6 changes: 3 additions & 3 deletions packages/turf-area/bench.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const path = require("path");
const load = require("load-json-file");
const { loadJsonFileSync } = require("load-json-file");
const Benchmark = require("benchmark");
const area = require("./index").default;

Expand All @@ -10,14 +10,14 @@ const fixtures = fs.readdirSync(directory).map((filename) => {
return {
filename,
name: path.parse(filename).name,
geojson: load.sync(directory + filename),
geojson: loadJsonFileSync(directory + filename),
};
});

/**
* Benmark Results
*
* polygon x 3,240,248 ops/sec ±0.91% (90 runs sampled)
* polygon x 8,510,024 ops/sec ±0.28% (96 runs sampled)
*/

// Define benchmark
Expand Down
73 changes: 36 additions & 37 deletions packages/turf-area/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ function polygonArea(coords: any) {
return total;
}

/**
* @private
* A constant factor used to compute the area of a polygon.
* It's derived from the square of the Earth's radius divided by 2.
*
* @type {number}
*/
const FACTOR = (earthRadius * earthRadius) / 2;

/**
* @private
* A constant used for converting degrees to radians.
* Represents the ratio of PI to 180.
*
* @type {number}
*/
const PI_OVER_180 = Math.PI / 180;

/**
* @private
* Calculate the approximate area of the polygon were it projected onto the earth.
Expand All @@ -80,46 +98,27 @@ function polygonArea(coords: any) {
* @param {Array<Array<number>>} coords Ring Coordinates
* @returns {number} The approximate signed geodesic area of the polygon in square meters.
*/
function ringArea(coords: number[][]) {
let p1;
let p2;
let p3;
let lowerIndex;
let middleIndex;
let upperIndex;
let i;
let total = 0;
function ringArea(coords: number[][]): number {
const coordsLength = coords.length;

if (coordsLength > 2) {
for (i = 0; i < coordsLength; i++) {
if (i === coordsLength - 2) {
// i = N-2
lowerIndex = coordsLength - 2;
middleIndex = coordsLength - 1;
upperIndex = 0;
} else if (i === coordsLength - 1) {
// i = N-1
lowerIndex = coordsLength - 1;
middleIndex = 0;
upperIndex = 1;
} else {
// i = 0 to N-3
lowerIndex = i;
middleIndex = i + 1;
upperIndex = i + 2;
}
p1 = coords[lowerIndex];
p2 = coords[middleIndex];
p3 = coords[upperIndex];
total += (rad(p3[0]) - rad(p1[0])) * Math.sin(rad(p2[1]));
}
if (coordsLength <= 2) return 0;
let total = 0;

total = (total * earthRadius * earthRadius) / 2;
let i = 0;
while (i < coordsLength) {
const lower = coords[i];
const middle = coords[i + 1 === coordsLength ? 0 : i + 1];
const upper =
coords[i + 2 >= coordsLength ? (i + 2) % coordsLength : i + 2];

const lowerX = lower[0] * PI_OVER_180;
const middleY = middle[1] * PI_OVER_180;
const upperX = upper[0] * PI_OVER_180;

total += (upperX - lowerX) * Math.sin(middleY);

i++;
}
return total;
}

function rad(num: number) {
return (num * Math.PI) / 180;
return total * FACTOR;
}
18 changes: 9 additions & 9 deletions packages/turf-area/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@
"test:tape": "tsx test.js"
},
"devDependencies": {
"@types/tape": "*",
"benchmark": "*",
"load-json-file": "*",
"npm-run-all": "*",
"tape": "*",
"tsx": "*",
"typescript": "*",
"write-json-file": "*"
"@types/tape": "^4.2.32",
"benchmark": "^2.1.4",
"load-json-file": "^7.0.1",
"npm-run-all": "^4.1.5",
"tape": "^5.7.2",
"tsx": "^3.14.0",
"typescript": "^5.2.2",
"write-json-file": "^5.0.0"
},
"dependencies": {
"@turf/helpers": "^7.0.0-alpha.2",
"@turf/meta": "^7.0.0-alpha.2",
"tslib": "^2.3.0"
"tslib": "^2.6.2"
}
}
10 changes: 5 additions & 5 deletions packages/turf-area/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const fs = require("fs");
const test = require("tape");
const path = require("path");
const load = require("load-json-file");
const write = require("write-json-file");
const { loadJsonFileSync } = require("load-json-file");
const { writeJsonFileSync } = require("write-json-file");
const area = require("./index").default;

const directories = {
Expand All @@ -14,7 +14,7 @@ const fixtures = fs.readdirSync(directories.in).map((filename) => {
return {
filename,
name: path.parse(filename).name,
geojson: load.sync(directories.in + filename),
geojson: loadJsonFileSync(directories.in + filename),
};
});

Expand All @@ -24,8 +24,8 @@ test("turf-area", (t) => {
const geojson = fixture.geojson;
const results = Math.round(area(geojson));
if (process.env.REGEN)
write.sync(directories.out + name + ".json", results);
t.equal(results, load.sync(directories.out + name + ".json"), name);
writeJsonFileSync(directories.out + name + ".json", results);
t.equal(results, loadJsonFileSync(directories.out + name + ".json"), name);
}
t.end();
});
4 changes: 2 additions & 2 deletions packages/turf-bbox-clip/bench.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const path = require("path");
const load = require("load-json-file");
const { loadJsonFileSync } = require("load-json-file");
const Benchmark = require("benchmark");
const bbox = require("@turf/bbox").default;
const bboxClip = require("./index").default;
Expand All @@ -10,7 +10,7 @@ const fixtures = fs.readdirSync(directory).map((filename) => {
return {
filename,
name: path.parse(filename).name,
geojson: load.sync(directory + filename),
geojson: loadJsonFileSync(directory + filename),
};
});

Expand Down
Loading

0 comments on commit f1450dd

Please sign in to comment.