[Git][debian-gis-team/mapbox-polylabel][upstream] New upstream version 2.0.1
Bas Couwenberg (@sebastic)
gitlab at salsa.debian.org
Sat Jul 6 17:02:08 BST 2024
Bas Couwenberg pushed to branch upstream at Debian GIS Project / mapbox-polylabel
Commits:
32f4f838 by Bas Couwenberg at 2024-07-06T17:58:05+02:00
New upstream version 2.0.1
- - - - -
4 changed files:
- README.md
- package-lock.json
- package.json
- polylabel.js
Changes:
=====================================
README.md
=====================================
@@ -32,14 +32,17 @@ It will be guaranteed to be a global optimum within the given precision.
### JavaScript Usage
Given polygon coordinates in
-[GeoJSON-like format](http://geojson.org/geojson-spec.html#polygon)
+[GeoJSON-like format](http://geojson.org/geojson-spec.html#polygon) (an array of arrays of `[x, y]` points)
and precision (`1.0` by default),
-Polylabel returns the pole of inaccessibility coordinate in `[x, y]` format.
+Polylabel returns the pole of inaccessibility coordinate in `[x, y]` format. The distance to the closest polygon point (in input units) is included as a `distance` property.
```js
-var p = polylabel(polygon, 1.0);
+const p = polylabel([[[0, 0], [1, 0], ...]], 1.0);
+const distance = p.distance;
```
+Be careful to pick precision appropriate for the input units. E.g. in case of geographic coordinates (longitude and latitude), `0.000001` is appropriate, while the default (`1.0`) would be too imprecise.
+
### TypeScript
[TypeScript type definitions](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/polylabel)
=====================================
package-lock.json
=====================================
@@ -1,19 +1,19 @@
{
"name": "polylabel",
- "version": "2.0.0",
+ "version": "2.0.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "polylabel",
- "version": "2.0.0",
+ "version": "2.0.1",
"license": "ISC",
"dependencies": {
- "tinyqueue": "^2.0.3"
+ "tinyqueue": "^3.0.0"
},
"devDependencies": {
- "eslint": "^9.5.0",
- "eslint-config-mourner": "^4.0.0"
+ "eslint": "^9.6.0",
+ "eslint-config-mourner": "^4.0.1"
}
},
"node_modules/@eslint-community/eslint-utils": {
@@ -56,15 +56,15 @@
}
},
"node_modules/@eslint/config-array": {
- "version": "0.16.0",
- "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.16.0.tgz",
- "integrity": "sha512-/jmuSd74i4Czf1XXn7wGRWZCuyaUZ330NH1Bek0Pplatt4Sy1S5haN21SCLLdbeKslQ+S0wEJ+++v5YibSi+Lg==",
+ "version": "0.17.0",
+ "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.17.0.tgz",
+ "integrity": "sha512-A68TBu6/1mHHuc5YJL0U0VVeGNiklLAL6rRmhTCP2B5XjWLMnrX+HkO+IAXyHvks5cyyY1jjK5ITPQ1HGS2EVA==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"@eslint/object-schema": "^2.1.4",
"debug": "^4.3.1",
- "minimatch": "^3.0.5"
+ "minimatch": "^3.1.2"
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
@@ -95,9 +95,9 @@
}
},
"node_modules/@eslint/js": {
- "version": "9.5.0",
- "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.5.0.tgz",
- "integrity": "sha512-A7+AOT2ICkodvtsWnxZP4Xxk3NbZ3VMHd8oihydLRGrJgqqdEz1qSeEgXYyT/Cu8h1TWWsQRejIx48mtjZ5y1w==",
+ "version": "9.6.0",
+ "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.6.0.tgz",
+ "integrity": "sha512-D9B0/3vNg44ZeWbYMpBoXqNP4j6eQD5vNwIlGAuFRRzK/WtT/jvDQW3Bi9kkf3PMDMlM7Yi+73VLUsn5bJcl8A==",
"dev": true,
"license": "MIT",
"engines": {
@@ -423,17 +423,17 @@
}
},
"node_modules/eslint": {
- "version": "9.5.0",
- "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.5.0.tgz",
- "integrity": "sha512-+NAOZFrW/jFTS3dASCGBxX1pkFD0/fsO+hfAkJ4TyYKwgsXZbqzrw+seCYFCcPCYXvnD67tAnglU7GQTz6kcVw==",
+ "version": "9.6.0",
+ "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.6.0.tgz",
+ "integrity": "sha512-ElQkdLMEEqQNM9Njff+2Y4q2afHk7JpkPvrd7Xh7xefwgQynqPxwf55J7di9+MEibWUGdNjFF9ITG9Pck5M84w==",
"dev": true,
"license": "MIT",
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.6.1",
- "@eslint/config-array": "^0.16.0",
+ "@eslint/config-array": "^0.17.0",
"@eslint/eslintrc": "^3.1.0",
- "@eslint/js": "9.5.0",
+ "@eslint/js": "9.6.0",
"@humanwhocodes/module-importer": "^1.0.1",
"@humanwhocodes/retry": "^0.3.0",
"@nodelib/fs.walk": "^1.2.8",
@@ -444,7 +444,7 @@
"escape-string-regexp": "^4.0.0",
"eslint-scope": "^8.0.1",
"eslint-visitor-keys": "^4.0.0",
- "espree": "^10.0.1",
+ "espree": "^10.1.0",
"esquery": "^1.5.0",
"esutils": "^2.0.2",
"fast-deep-equal": "^3.1.3",
@@ -475,9 +475,9 @@
}
},
"node_modules/eslint-config-mourner": {
- "version": "4.0.0",
- "resolved": "https://registry.npmjs.org/eslint-config-mourner/-/eslint-config-mourner-4.0.0.tgz",
- "integrity": "sha512-svOOXP1KFS9DZOR6hxVQVTug75a/aQQ/shc/Tlgvbszo9ypTbRta/elow54Qq6RJ7S8LwnXeuPEAcOdDWExqlg==",
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/eslint-config-mourner/-/eslint-config-mourner-4.0.1.tgz",
+ "integrity": "sha512-seylu4qdUc7kabx42zEedJiCyRDYqwsZLFPPnMRntmOFOQv6cKoM+FqhYpLKZ5dF7A7wW6mCympQSkg6RVxGlg==",
"dev": true,
"license": "ISC",
"dependencies": {
@@ -1121,9 +1121,9 @@
"license": "MIT"
},
"node_modules/tinyqueue": {
- "version": "2.0.3",
- "resolved": "https://registry.npmjs.org/tinyqueue/-/tinyqueue-2.0.3.tgz",
- "integrity": "sha512-ppJZNDuKGgxzkHihX8v9v9G5f+18gzaTfrukGrq6ueg0lmH4nqVnA2IPG0AEH3jKEk2GRJCUhDoqpoiw3PHLBA==",
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/tinyqueue/-/tinyqueue-3.0.0.tgz",
+ "integrity": "sha512-gRa9gwYU3ECmQYv3lslts5hxuIa90veaEcxDYuu3QGOIAEM2mOZkVHp48ANJuu1CURtRdHKUBY5Lm1tHV+sD4g==",
"license": "ISC"
},
"node_modules/type-check": {
=====================================
package.json
=====================================
@@ -1,6 +1,6 @@
{
"name": "polylabel",
- "version": "2.0.0",
+ "version": "2.0.1",
"description": "A JS library for finding optimal label position inside a polygon",
"keywords": [
"polygon",
@@ -9,12 +9,13 @@
],
"main": "polylabel.js",
"type": "module",
+ "sideEffects": false,
"dependencies": {
- "tinyqueue": "^2.0.3"
+ "tinyqueue": "^3.0.0"
},
"devDependencies": {
- "eslint": "^9.5.0",
- "eslint-config-mourner": "^4.0.0"
+ "eslint": "^9.6.0",
+ "eslint-config-mourner": "^4.0.1"
},
"scripts": {
"pretest": "eslint *.js test/*.js",
=====================================
polylabel.js
=====================================
@@ -20,13 +20,13 @@ export default function polylabel(polygon, precision = 1.0, debug = false) {
const cellSize = Math.max(precision, Math.min(width, height));
if (cellSize === precision) {
- const degeneratePoleOfInaccessibility = [minX, minY];
- degeneratePoleOfInaccessibility.distance = 0;
- return degeneratePoleOfInaccessibility;
+ const result = [minX, minY];
+ result.distance = 0;
+ return result;
}
// a priority queue of cells in order of their "potential" (max distance to polygon)
- const cellQueue = new Queue(undefined, compareMax);
+ const cellQueue = new Queue([], (a, b) => b.max - a.max);
// take centroid as the first best guess
let bestCell = getCentroidCell(polygon);
@@ -59,31 +59,26 @@ export default function polylabel(polygon, precision = 1.0, debug = false) {
while (cellQueue.length) {
// pick the most promising cell from the queue
- const cell = cellQueue.pop();
+ const {max, x, y, h: ch} = cellQueue.pop();
// do not drill down further if there's no chance of a better solution
- if (cell.max - bestCell.d <= precision) break;
+ if (max - bestCell.d <= precision) break;
// split the cell into four cells
- h = cell.h / 2;
- potentiallyQueue(cell.x - h, cell.y - h, h);
- potentiallyQueue(cell.x + h, cell.y - h, h);
- potentiallyQueue(cell.x - h, cell.y + h, h);
- potentiallyQueue(cell.x + h, cell.y + h, h);
+ h = ch / 2;
+ potentiallyQueue(x - h, y - h, h);
+ potentiallyQueue(x + h, y - h, h);
+ potentiallyQueue(x - h, y + h, h);
+ potentiallyQueue(x + h, y + h, h);
}
if (debug) {
- console.log(`num probes: ${numProbes}`);
- console.log(`best distance: ${bestCell.d}`);
+ console.log(`num probes: ${numProbes}\nbest distance: ${bestCell.d}`);
}
- const poleOfInaccessibility = [bestCell.x, bestCell.y];
- poleOfInaccessibility.distance = bestCell.d;
- return poleOfInaccessibility;
-}
-
-function compareMax(a, b) {
- return b.max - a.max;
+ const result = [bestCell.x, bestCell.y];
+ result.distance = bestCell.d;
+ return result;
}
function Cell(x, y, h, polygon) {
@@ -142,7 +137,6 @@ function getSegDistSq(px, py, a, b) {
let dy = b[1] - y;
if (dx !== 0 || dy !== 0) {
-
const t = ((px - x) * dx + (py - y) * dy) / (dx * dx + dy * dy);
if (t > 1) {
View it on GitLab: https://salsa.debian.org/debian-gis-team/mapbox-polylabel/-/commit/32f4f83856eebd2443f5f45d7eb7d2f47f94104e
--
This project does not include diff previews in email notifications.
View it on GitLab: https://salsa.debian.org/debian-gis-team/mapbox-polylabel/-/commit/32f4f83856eebd2443f5f45d7eb7d2f47f94104e
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20240706/686f00b9/attachment-0001.htm>
More information about the Pkg-grass-devel
mailing list