simplify-geojson-visvalingam 1.3.6 → 1.3.8

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 CHANGED
@@ -31,6 +31,10 @@ npm i --save simplify-geojson-visvalingam
31
31
  * The start and end point of the `LineString` objects will never be removed
32
32
  * Expects **valid** two-dimensional GeoJSON coordinates and is designed for `[x, y]` positions
33
33
 
34
+ ## Performance benchmarks
35
+
36
+ Run `npm run bench` for synthetic timing scenarios, `npm run bench:memory` for separate memory measurements, and `npm run bench:compare -- baseline.json candidate.json` to compare reports. See [benchmark methodology and commands](bench/README.md) for reproducible data, measurement boundaries, profiling, and CI.
37
+
34
38
  ## Usage
35
39
  ### JS
36
40
  ```javascript
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var v=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var _=(e,r)=>{for(var t in r)v(e,t,{get:r[t],enumerable:!0})},B=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of $(r))!q.call(e,l)&&l!==t&&v(e,l,{get:()=>r[l],enumerable:!(n=k(r,l))||n.enumerable});return e};var z=e=>B(v({},"__esModule",{value:!0}),e);var X={};_(X,{default:()=>H});module.exports=z(X);function A(e){return e!=null&&Number.isFinite(e)&&e>0}function a(e){return typeof e=="object"&&e!==null}function F(e){return a(e)&&e?.type==="Feature"}function h(e){return a(e)&&e?.type==="FeatureCollection"}function U(e){return a(e)&&e?.type==="LineString"}function G(e){return a(e)&&e?.type==="MultiLineString"}function g(e){return a(e)&&e?.type==="Polygon"}function w(e){return a(e)&&e?.type==="MultiPolygon"}function O(e){return a(e)&&e?.type==="GeometryCollection"}function M(e){let r=new Uint32Array(e.length),t=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let l=0;l<e.length;l++)r[l]=l;r.sort((l,u)=>e[l][0]-e[u][0]||e[l][1]-e[u][1]),e.length&&(n[r[e.length-1]]=n.length-1);for(let l=1,u=e.length-2;l<e.length;l++,u--)e[r[l]][0]!==e[r[l-1]][0]||e[r[l]][1]!==e[r[l-1]][1]?t[r[l]]=l:t[r[l]]=t[r[l-1]],e[r[u]][0]!==e[r[u+1]][0]||e[r[u]][1]!==e[r[u+1]][1]?n[r[u]]=u:n[r[u]]=n[r[u+1]];return{sortIndexes:r,groupedFrom:t,groupedTo:n}}function H(e,r={}){if(!a(e))throw new TypeError(`Expected provided GeoJSON to be an object, but received ${e===null?"null":typeof e}.`);let t=0;if(r.tolerance!==void 0){if(!A(r.tolerance))throw new Error(`Expected provided tolerance to be a finite positive number, but received ${r.tolerance}.`);t=r.tolerance}let n=0;if(r.fraction!==void 0){if(!A(r.fraction))throw new Error(`Expected provided fraction to be a finite positive number, but received ${r.fraction}.`);if(r.fraction>1)throw new Error(`Expected provided fraction to be less or equal to 1, but received ${r.fraction}.`);n=r.fraction}let l=!0;if(r.mutate!==void 0&&(l=!!r.mutate),t===0&&n===0)return e;l||(e=structuredClone(e));let u={coordinates:[],nextIndexes:[],prevIndexes:[]};return P(e,u),u.coordinates.length&&I(e,V(u,M(u.coordinates),t,n),0),e}function J(e,r){return Math.abs(r.coordinates[e][0]*(r.coordinates[r.prevIndexes[e]][1]-r.coordinates[r.nextIndexes[e]][1])+r.coordinates[r.prevIndexes[e]][0]*(r.coordinates[r.nextIndexes[e]][1]-r.coordinates[e][1])+r.coordinates[r.nextIndexes[e]][0]*(r.coordinates[e][1]-r.coordinates[r.prevIndexes[e]][1]))/2}function S(e,r,t,n){return t[e]-t[r]||n[e][0]-n[r][0]||n[e][1]-n[r][1]}function C(e,r,t,n,l){let u,o,i;for(;i=t,(u=t<<1)<=e[0]&&S(e[i],e[u],n,l)>0&&(i=u),(o=u+1)<=e[0]&&S(e[i],e[o],n,l)>0&&(i=o),t!==i;)L(e,r,t,i),t=i;return t}function K(e,r,t,n,l){let u;for(;t>1&&(u=t>>>1,!(t===u||S(e[u],e[t],n,l)<=0));)L(e,r,t,u),t=u;return t}function p(e,r,t,n,l){K(e,r,C(e,r,r[t],n,l),n,l)}function L(e,r,t,n){r[e[t]]=n,r[e[n]]=t,[e[t],e[n]]=[e[n],e[t]]}function Q(e,r,t,n){return e[0]>1?(L(e,r,1,e[0]),e[0]--,C(e,r,1,t,n),e[e[0]+1]):e[0]===1?(e[0]--,e[1]):-1}function R(e,r,t,n){for(let l=e[0]>>>1;l>0;l--)C(e,r,l,t,n)}function V(e,r,t,n){let l=e.coordinates.length,u=new Uint8Array(l),o=Math.round(l*n),i=new Uint32Array(l),b=new Uint8Array(l),m=new Uint32Array(l+1),d=new Float64Array(l),x=new Uint32Array(l);for(let f=0;f<l;f++)e.prevIndexes[f]!==-1&&e.nextIndexes[f]!==-1&&(d[f]=J(f,e),m[0]++,m[m[0]]=f,x[f]=m[0]);R(m,x,d,e.coordinates);let c;for(;m[0];)if(c=Q(m,x,d,e.coordinates),!u[c]){if(d[c]>=t&&o<=0)break;if(b[c]||(b[c]=1,i[r.groupedFrom[c]]++),i[r.groupedFrom[c]]===r.groupedTo[c]-r.groupedFrom[c]+1)for(let f,y=r.groupedFrom[c];y<=r.groupedTo[c];y++)f=r.sortIndexes[y],!u[f]&&(e.prevIndexes[f]!==-1&&e.prevIndexes[e.prevIndexes[f]]!==-1&&e.prevIndexes[e.prevIndexes[e.prevIndexes[f]]]===f?(b[e.prevIndexes[f]]||(b[e.prevIndexes[f]]=1,i[r.groupedFrom[e.prevIndexes[f]]]++),b[e.nextIndexes[f]]||(b[e.nextIndexes[f]]=1,i[r.groupedFrom[e.nextIndexes[f]]]++),i[r.groupedFrom[e.prevIndexes[f]]]===r.groupedTo[e.prevIndexes[f]]-r.groupedFrom[e.prevIndexes[f]]+1&&i[r.groupedFrom[e.nextIndexes[f]]]===r.groupedTo[e.nextIndexes[f]]-r.groupedFrom[e.nextIndexes[f]]+1&&(u[f]=1,u[e.nextIndexes[f]]=1,u[e.prevIndexes[f]]=1,o-=3,y=r.groupedFrom[c]-1)):(u[f]=1,o--,e.prevIndexes[e.nextIndexes[f]]=e.prevIndexes[f],e.nextIndexes[e.prevIndexes[f]]=e.nextIndexes[f],e.prevIndexes[e.prevIndexes[f]]!==-1&&(d[e.prevIndexes[f]]=J(e.prevIndexes[f],e),p(m,x,e.prevIndexes[f],d,e.coordinates)),e.nextIndexes[e.nextIndexes[f]]!==-1&&(d[e.nextIndexes[f]]=J(e.nextIndexes[f],e),p(m,x,e.nextIndexes[f],d,e.coordinates))))}return u}function I(e,r,t){if(h(e))for(let n=0;n<e.features.length;n++)t=I(e.features[n],r,t);else if(F(e))t=I(e.geometry,r,t);else if(O(e))for(let n=0;n<e.geometries.length;n++)t=I(e.geometries[n],r,t);else if(U(e))t=s(e.coordinates,r,t);else if(G(e))for(let n=0;n<e.coordinates.length;n++)t=s(e.coordinates[n],r,t);else if(g(e)){let n=!1;[t,n]=E(e.coordinates,r,t),n&&e.coordinates.splice(0)}else if(w(e)){let n=0;for(let l=!1,u=0;u<e.coordinates.length;u++)[t,l]=E(e.coordinates[u],r,t),l?n++:n&&(e.coordinates[u-n]=e.coordinates[u]);n&&e.coordinates.splice(e.coordinates.length-n)}return t}function s(e,r,t){let n=0;for(let l=0;l<e.length;l++)r[t]?n++:n&&(e[l-n]=e[l]),t++;return n&&e.splice(e.length-n),t}function E(e,r,t){let n=0;for(let l=!1,u=0;u<e.length;u++)if([t,l]=W(e[u],r,t),l){if(u===0){for(u=1;u<e.length;u++)e[u].length&&(t+=e[u].length-1);return[t,!0]}n++}else n&&(e[u-n]=e[u]);return n&&e.splice(e.length-n),[t,!1]}function W(e,r,t){let n=0;for(let l=0;l<e.length-1;l++)r[t]?n++:n&&(e[l-n]=e[l]),t++;if(n){if(e.length-1-n<3)return[t,!0];e.splice(e.length-1-n,n+1,e[0])}return[t,!1]}function P(e,r){if(h(e))for(let t=0;t<e.features.length;t++)P(e.features[t],r);else if(F(e))P(e.geometry,r);else if(O(e))for(let t=0;t<e.geometries.length;t++)P(e.geometries[t],r);else if(U(e))T(e.coordinates,r);else if(G(e))for(let t=0;t<e.coordinates.length;t++)T(e.coordinates[t],r);else if(g(e))for(let t=0;t<e.coordinates.length;t++)N(e.coordinates[t],r);else if(w(e))for(let t,n=0;n<e.coordinates.length;n++)for(t=0;t<e.coordinates[n].length;t++)N(e.coordinates[n][t],r)}function T(e,r){for(let t=r.coordinates.length,n=e.length,l=0;l<n;l++)r.coordinates.push(e[l]),r.prevIndexes.push(l===0?-1:t+l-1),r.nextIndexes.push(l===n-1?-1:t+l+1)}function N(e,r){for(let t=r.coordinates.length,n=e.length-1,l=0;l<n;l++)r.coordinates.push(e[l]),r.prevIndexes.push(l===0?t+n-1:t+l-1),r.nextIndexes.push(l===n-1?t:t+l+1)}
1
+ "use strict";var v=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var B=(e,r)=>{for(var t in r)v(e,t,{get:r[t],enumerable:!0})},X=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of q(r))!_.call(e,l)&&l!==t&&v(e,l,{get:()=>r[l],enumerable:!(n=$(r,l))||n.enumerable});return e};var Y=e=>X(v({},"__esModule",{value:!0}),e);var W={};B(W,{default:()=>Q});module.exports=Y(W);function A(e){return e!=null&&Number.isFinite(e)&&e>0}function a(e){return typeof e=="object"&&e!==null}function F(e){return a(e)&&e?.type==="Feature"}function h(e){return a(e)&&e?.type==="FeatureCollection"}function U(e){return a(e)&&e?.type==="LineString"}function g(e){return a(e)&&e?.type==="MultiLineString"}function G(e){return a(e)&&e?.type==="Polygon"}function w(e){return a(e)&&e?.type==="MultiPolygon"}function O(e){return a(e)&&e?.type==="GeometryCollection"}function L(e){let r=new Uint32Array(e.length),t=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let l=0;l<e.length;l++)r[l]=l;r.sort((l,u)=>{let o=e[l][0]-e[u][0];if(o)return o<0?-1:1;let c=e[l][1]-e[u][1];return c<0?-1:c>0?1:0}),e.length&&(n[r[e.length-1]]=n.length-1);for(let l=1,u=e.length-2;l<e.length;l++,u--)e[r[l]][0]!==e[r[l-1]][0]||e[r[l]][1]!==e[r[l-1]][1]?t[r[l]]=l:t[r[l]]=t[r[l-1]],e[r[u]][0]!==e[r[u+1]][0]||e[r[u]][1]!==e[r[u+1]][1]?n[r[u]]=u:n[r[u]]=n[r[u+1]];return{sortIndexes:r,groupedFrom:t,groupedTo:n}}function s(e,r){return Math.abs(r.coordinates[e][0]*(r.coordinates[r.prevIndexes[e]][1]-r.coordinates[r.nextIndexes[e]][1])+r.coordinates[r.prevIndexes[e]][0]*(r.coordinates[r.nextIndexes[e]][1]-r.coordinates[e][1])+r.coordinates[r.nextIndexes[e]][0]*(r.coordinates[e][1]-r.coordinates[r.prevIndexes[e]][1]))/2}function J(e,r,t,n){return t[e]-t[r]||n[e][0]-n[r][0]||n[e][1]-n[r][1]}function S(e,r,t,n,l){let u=e[t],o,c,m,i;for(;m=t,i=u,(o=t<<1)<=e[0]&&J(i,e[o],n,l)>0&&(m=o,i=e[o]),(c=o+1)<=e[0]&&J(i,e[c],n,l)>0&&(m=c),t!==m;)e[t]=e[m],r[e[t]]=t,t=m;return e[t]=u,r[u]=t,t}function z(e,r,t,n,l){let u;for(;t>1&&(u=t>>>1,!(t===u||J(e[u],e[t],n,l)<=0));)M(e,r,t,u),t=u;return t}function C(e,r,t,n,l){z(e,r,S(e,r,r[t],n,l),n,l)}function M(e,r,t,n){r[e[t]]=n,r[e[n]]=t,[e[t],e[n]]=[e[n],e[t]]}function H(e,r,t,n){return e[0]>1?(M(e,r,1,e[0]),e[0]--,S(e,r,1,t,n),e[e[0]+1]):e[0]===1?(e[0]--,e[1]):-1}function K(e,r,t,n){for(let l=e[0]>>>1;l>0;l--)S(e,r,l,t,n)}function E(e,r,t,n){let l=e.coordinates.length,u=new Uint8Array(l),o=Math.round(l*n),c=new Uint32Array(l),m=new Uint8Array(l),i=new Uint32Array(l+1),b=new Float64Array(l),x=new Uint32Array(l);for(let f=0;f<l;f++)e.prevIndexes[f]!==-1&&e.nextIndexes[f]!==-1&&(b[f]=s(f,e),i[0]++,i[i[0]]=f,x[f]=i[0]);K(i,x,b,e.coordinates);let d;for(;i[0];)if(d=H(i,x,b,e.coordinates),!u[d]){if(b[d]>=t&&o<=0)break;if(m[d]||(m[d]=1,c[r.groupedFrom[d]]++),c[r.groupedFrom[d]]===r.groupedTo[d]-r.groupedFrom[d]+1)for(let f,y=r.groupedFrom[d];y<=r.groupedTo[d];y++)f=r.sortIndexes[y],!u[f]&&(e.prevIndexes[f]!==-1&&e.prevIndexes[e.prevIndexes[f]]!==-1&&e.prevIndexes[e.prevIndexes[e.prevIndexes[f]]]===f?(m[e.prevIndexes[f]]||(m[e.prevIndexes[f]]=1,c[r.groupedFrom[e.prevIndexes[f]]]++),m[e.nextIndexes[f]]||(m[e.nextIndexes[f]]=1,c[r.groupedFrom[e.nextIndexes[f]]]++),c[r.groupedFrom[e.prevIndexes[f]]]===r.groupedTo[e.prevIndexes[f]]-r.groupedFrom[e.prevIndexes[f]]+1&&c[r.groupedFrom[e.nextIndexes[f]]]===r.groupedTo[e.nextIndexes[f]]-r.groupedFrom[e.nextIndexes[f]]+1&&(u[f]=1,u[e.nextIndexes[f]]=1,u[e.prevIndexes[f]]=1,o-=3,y=r.groupedFrom[d]-1)):(u[f]=1,o--,e.prevIndexes[e.nextIndexes[f]]=e.prevIndexes[f],e.nextIndexes[e.prevIndexes[f]]=e.nextIndexes[f],e.prevIndexes[e.prevIndexes[f]]!==-1&&(b[e.prevIndexes[f]]=s(e.prevIndexes[f],e),C(i,x,e.prevIndexes[f],b,e.coordinates)),e.nextIndexes[e.nextIndexes[f]]!==-1&&(b[e.nextIndexes[f]]=s(e.nextIndexes[f],e),C(i,x,e.nextIndexes[f],b,e.coordinates))))}return u}function Q(e,r={}){if(!a(e))throw new TypeError(`Expected provided GeoJSON to be an object, but received ${e===null?"null":typeof e}.`);let t=0;if(r.tolerance!==void 0){if(!A(r.tolerance))throw new Error(`Expected provided tolerance to be a finite positive number, but received ${r.tolerance}.`);t=r.tolerance}let n=0;if(r.fraction!==void 0){if(!A(r.fraction))throw new Error(`Expected provided fraction to be a finite positive number, but received ${r.fraction}.`);if(r.fraction>1)throw new Error(`Expected provided fraction to be less or equal to 1, but received ${r.fraction}.`);n=r.fraction}let l=!0;if(r.mutate!==void 0&&(l=!!r.mutate),t===0&&n===0)return e;l||(e=structuredClone(e));let u={coordinates:[],nextIndexes:[],prevIndexes:[]};return P(e,u),u.coordinates.length&&I(e,E(u,L(u.coordinates),t,n),0),e}function I(e,r,t){if(h(e))for(let n=0;n<e.features.length;n++)t=I(e.features[n],r,t);else if(F(e))t=I(e.geometry,r,t);else if(O(e))for(let n=0;n<e.geometries.length;n++)t=I(e.geometries[n],r,t);else if(U(e))t=T(e.coordinates,r,t);else if(g(e))for(let n=0;n<e.coordinates.length;n++)t=T(e.coordinates[n],r,t);else if(G(e)){let n=!1;[t,n]=p(e.coordinates,r,t),n&&e.coordinates.splice(0)}else if(w(e)){let n=0;for(let l=!1,u=0;u<e.coordinates.length;u++)[t,l]=p(e.coordinates[u],r,t),l?n++:n&&(e.coordinates[u-n]=e.coordinates[u]);n&&e.coordinates.splice(e.coordinates.length-n)}return t}function T(e,r,t){let n=0;for(let l=0;l<e.length;l++)r[t]?n++:n&&(e[l-n]=e[l]),t++;return n&&e.splice(e.length-n),t}function p(e,r,t){let n=0;for(let l=!1,u=0;u<e.length;u++)if([t,l]=V(e[u],r,t),l){if(u===0){for(u=1;u<e.length;u++)e[u].length&&(t+=e[u].length-1);return[t,!0]}n++}else n&&(e[u-n]=e[u]);return n&&e.splice(e.length-n),[t,!1]}function V(e,r,t){let n=0;for(let l=0;l<e.length-1;l++)r[t]?n++:n&&(e[l-n]=e[l]),t++;if(n){if(e.length-1-n<3)return[t,!0];e.splice(e.length-1-n,n+1,e[0])}return[t,!1]}function P(e,r){if(h(e))for(let t=0;t<e.features.length;t++)P(e.features[t],r);else if(F(e))P(e.geometry,r);else if(O(e))for(let t=0;t<e.geometries.length;t++)P(e.geometries[t],r);else if(U(e))N(e.coordinates,r);else if(g(e))for(let t=0;t<e.coordinates.length;t++)N(e.coordinates[t],r);else if(G(e))for(let t=0;t<e.coordinates.length;t++)k(e.coordinates[t],r);else if(w(e))for(let t,n=0;n<e.coordinates.length;n++)for(t=0;t<e.coordinates[n].length;t++)k(e.coordinates[n][t],r)}function N(e,r){for(let t=r.coordinates.length,n=e.length,l=0;l<n;l++)r.coordinates.push(e[l]),r.prevIndexes.push(l===0?-1:t+l-1),r.nextIndexes.push(l===n-1?-1:t+l+1)}function k(e,r){for(let t=r.coordinates.length,n=e.length-1,l=0;l<n;l++)r.coordinates.push(e[l]),r.prevIndexes.push(l===0?t+n-1:t+l-1),r.nextIndexes.push(l===n-1?t:t+l+1)}
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/lib/typeGuards.ts","../src/lib/functions.ts"],"sourcesContent":["import { GeoJsonObject, Position } from 'geojson'\nimport {\n isObject,\n isFinitePositiveNumber,\n isFeature,\n isFeatureCollection,\n isLineString,\n isMultiLineString,\n isPolygon,\n isMultiPolygon,\n isGeometryCollection,\n} from '@lib/typeGuards'\nimport { groupPositions, type Groups } from '@lib/functions'\n\nexport type SimplifyOptions = {\n tolerance?: number\n fraction?: number\n mutate?: boolean\n}\n\ntype Positions = {\n coordinates: Position[]\n nextIndexes: number[]\n prevIndexes: number[]\n}\n\nexport default function (geojson: GeoJsonObject, options: SimplifyOptions = {}): GeoJsonObject {\n // validate input data\n if (!isObject(geojson)) {\n throw new TypeError(\n `Expected provided GeoJSON to be an object, but received ${geojson === null ? 'null' : typeof geojson}.`,\n )\n }\n\n // validate options\n let tolerance = 0\n if (options.tolerance !== undefined) {\n if (!isFinitePositiveNumber(options.tolerance)) {\n throw new Error(`Expected provided tolerance to be a finite positive number, but received ${options.tolerance}.`)\n }\n tolerance = options.tolerance\n }\n let fraction = 0\n if (options.fraction !== undefined) {\n if (!isFinitePositiveNumber(options.fraction)) {\n throw new Error(`Expected provided fraction to be a finite positive number, but received ${options.fraction}.`)\n }\n if (options.fraction > 1) {\n throw new Error(`Expected provided fraction to be less or equal to 1, but received ${options.fraction}.`)\n }\n fraction = options.fraction\n }\n let mutate = true\n if (options.mutate !== undefined) {\n mutate = !!options.mutate\n }\n\n // exit if no simplification options provided\n if (tolerance === 0 && fraction === 0) {\n return geojson\n }\n\n if (!mutate) {\n geojson = structuredClone(geojson)\n }\n\n const positions: Positions = {\n coordinates: [],\n nextIndexes: [],\n prevIndexes: [],\n }\n collectPositions(geojson, positions)\n\n if (positions.coordinates.length) {\n updatePositions(geojson, deletePositions(positions, groupPositions(positions.coordinates), tolerance, fraction), 0)\n }\n\n return geojson\n}\n\nfunction getPositionArea(i: number, positions: Positions): number {\n return (\n Math.abs(\n positions.coordinates[i][0] *\n (positions.coordinates[positions.prevIndexes[i]][1] - positions.coordinates[positions.nextIndexes[i]][1]) +\n positions.coordinates[positions.prevIndexes[i]][0] *\n (positions.coordinates[positions.nextIndexes[i]][1] - positions.coordinates[i][1]) +\n positions.coordinates[positions.nextIndexes[i]][0] *\n (positions.coordinates[i][1] - positions.coordinates[positions.prevIndexes[i]][1]),\n ) / 2\n )\n}\n\nfunction heapcompare(a: number, b: number, priority: Float64Array, coordinates: Position[]): number {\n return priority[a] - priority[b] || coordinates[a][0] - coordinates[b][0] || coordinates[a][1] - coordinates[b][1]\n}\n\nfunction heapsink(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n let l: number, r: number, t: number\n while (true) {\n t = i\n if ((l = i << 1) <= heap[0] && heapcompare(heap[t], heap[l], priority, coordinates) > 0) t = l\n if ((r = l + 1) <= heap[0] && heapcompare(heap[t], heap[r], priority, coordinates) > 0) t = r\n if (i === t) break\n heapswap(heap, heapRev, i, t)\n i = t\n }\n return i\n}\n\nfunction heapbubble(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n let t: number\n while (i > 1) {\n t = i >>> 1\n if (i === t || heapcompare(heap[t], heap[i], priority, coordinates) <= 0) break\n heapswap(heap, heapRev, i, t)\n i = t\n }\n return i\n}\n\nfunction heapupdate(\n heap: Uint32Array,\n heapRev: Uint32Array,\n val: number,\n priority: Float64Array,\n coordinates: Position[],\n): void {\n heapbubble(heap, heapRev, heapsink(heap, heapRev, heapRev[val], priority, coordinates), priority, coordinates)\n}\n\nfunction heapswap(heap: Uint32Array, heapRev: Uint32Array, i: number, t: number): void {\n heapRev[heap[i]] = t\n heapRev[heap[t]] = i\n ;[heap[i], heap[t]] = [heap[t], heap[i]]\n}\n\nfunction heappop(heap: Uint32Array, heapRev: Uint32Array, priority: Float64Array, coordinates: Position[]): number {\n if (heap[0] > 1) {\n heapswap(heap, heapRev, 1, heap[0])\n heap[0]--\n heapsink(heap, heapRev, 1, priority, coordinates)\n return heap[heap[0] + 1]\n } else if (heap[0] === 1) {\n heap[0]--\n return heap[1]\n }\n return -1\n}\n\nfunction heapify(heap: Uint32Array, heapRev: Uint32Array, priority: Float64Array, coordinates: Position[]): void {\n for (let i = heap[0] >>> 1; i > 0; i--) {\n heapsink(heap, heapRev, i, priority, coordinates)\n }\n}\n\nfunction deletePositions(positions: Positions, groups: Groups, tolerance: number, fraction: number): Uint8Array {\n const n = positions.coordinates.length\n\n const isDeleted = new Uint8Array(n)\n let toDelete = Math.round(n * fraction)\n\n const candidatesByGroupFrom = new Uint32Array(n)\n const isCandidate = new Uint8Array(n)\n\n const heap = new Uint32Array(n + 1)\n const priority = new Float64Array(n)\n const heapRev = new Uint32Array(n)\n\n for (let i = 0; i < n; i++) {\n if (positions.prevIndexes[i] !== -1 && positions.nextIndexes[i] !== -1) {\n priority[i] = getPositionArea(i, positions)\n heap[0]++\n heap[heap[0]] = i\n heapRev[i] = heap[0]\n }\n }\n heapify(heap, heapRev, priority, positions.coordinates)\n\n let i: number\n while (heap[0]) {\n i = heappop(heap, heapRev, priority, positions.coordinates)\n\n // check if position should be skipped\n if (isDeleted[i]) {\n continue\n }\n\n // check if simplification is completed\n if (priority[i] >= tolerance && toDelete <= 0) {\n break\n }\n\n // mark as candidate\n if (!isCandidate[i]) {\n isCandidate[i] = 1\n candidatesByGroupFrom[groups.groupedFrom[i]]++\n }\n\n // check if position is grouped and group is not entirely marked\n if (candidatesByGroupFrom[groups.groupedFrom[i]] !== groups.groupedTo[i] - groups.groupedFrom[i] + 1) {\n continue\n }\n\n // delete all positions from group\n // possible bug: in ring with two idetical positions (!!) test case needed\n for (let k: number, j = groups.groupedFrom[i]; j <= groups.groupedTo[i]; j++) {\n k = groups.sortIndexes[j]\n if (isDeleted[k]) {\n continue\n }\n\n // check if we are about to delete the entire ring or a single position\n if (\n positions.prevIndexes[k] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[k]] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[positions.prevIndexes[k]]] === k\n ) {\n // mark neighbors as candidates if not yet\n if (!isCandidate[positions.prevIndexes[k]]) {\n isCandidate[positions.prevIndexes[k]] = 1\n candidatesByGroupFrom[groups.groupedFrom[positions.prevIndexes[k]]]++\n }\n if (!isCandidate[positions.nextIndexes[k]]) {\n isCandidate[positions.nextIndexes[k]] = 1\n candidatesByGroupFrom[groups.groupedFrom[positions.nextIndexes[k]]]++\n }\n\n // remove entire ring if neighbor groups are entirely marked\n if (\n candidatesByGroupFrom[groups.groupedFrom[positions.prevIndexes[k]]] ===\n groups.groupedTo[positions.prevIndexes[k]] - groups.groupedFrom[positions.prevIndexes[k]] + 1 &&\n candidatesByGroupFrom[groups.groupedFrom[positions.nextIndexes[k]]] ===\n groups.groupedTo[positions.nextIndexes[k]] - groups.groupedFrom[positions.nextIndexes[k]] + 1\n ) {\n isDeleted[k] = 1\n isDeleted[positions.nextIndexes[k]] = 1\n isDeleted[positions.prevIndexes[k]] = 1\n toDelete -= 3\n\n // repeat to delete all matching rings\n // possible optimization\n j = groups.groupedFrom[i] - 1\n }\n } else {\n isDeleted[k] = 1\n toDelete--\n positions.prevIndexes[positions.nextIndexes[k]] = positions.prevIndexes[k]\n positions.nextIndexes[positions.prevIndexes[k]] = positions.nextIndexes[k]\n\n // update neighbors priority and their positions in the heap\n if (positions.prevIndexes[positions.prevIndexes[k]] !== -1) {\n priority[positions.prevIndexes[k]] = getPositionArea(positions.prevIndexes[k], positions)\n heapupdate(heap, heapRev, positions.prevIndexes[k], priority, positions.coordinates)\n }\n if (positions.nextIndexes[positions.nextIndexes[k]] !== -1) {\n priority[positions.nextIndexes[k]] = getPositionArea(positions.nextIndexes[k], positions)\n heapupdate(heap, heapRev, positions.nextIndexes[k], priority, positions.coordinates)\n }\n }\n }\n }\n return isDeleted\n}\n\nfunction updatePositions(geojson: GeoJsonObject, isDeleted: Uint8Array, index: number): number {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n index = updatePositions(geojson.features[i], isDeleted, index)\n }\n } else if (isFeature(geojson)) {\n index = updatePositions(geojson.geometry, isDeleted, index)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n index = updatePositions(geojson.geometries[i], isDeleted, index)\n }\n } else if (isLineString(geojson)) {\n index = updateLinePositions(geojson.coordinates, isDeleted, index)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n index = updateLinePositions(geojson.coordinates[i], isDeleted, index)\n }\n } else if (isPolygon(geojson)) {\n let remove = false\n ;[index, remove] = updateRingsPositions(geojson.coordinates, isDeleted, index)\n if (remove) geojson.coordinates.splice(0)\n } else if (isMultiPolygon(geojson)) {\n let offset = 0\n for (let remove = false, i = 0; i < geojson.coordinates.length; i++) {\n ;[index, remove] = updateRingsPositions(geojson.coordinates[i], isDeleted, index)\n if (remove) {\n offset++\n } else if (offset) {\n geojson.coordinates[i - offset] = geojson.coordinates[i]\n }\n }\n if (offset) geojson.coordinates.splice(geojson.coordinates.length - offset)\n }\n return index\n}\n\nfunction updateLinePositions(coordinates: Position[], isDeleted: Uint8Array, index: number): number {\n let offset = 0\n for (let i = 0; i < coordinates.length; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return index\n}\n\nfunction updateRingsPositions(coordinates: Position[][], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let remove = false, i = 0; i < coordinates.length; i++) {\n ;[index, remove] = updateRingPositions(coordinates[i], isDeleted, index)\n if (remove) {\n // skip interior rings if exterior ring is removed\n if (i === 0) {\n for (i = 1; i < coordinates.length; i++) {\n if (coordinates[i].length) index += coordinates[i].length - 1\n }\n // avoid alternating coordinates array if exterior ring is removed\n return [index, true]\n }\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return [index, false]\n}\n\nfunction updateRingPositions(coordinates: Position[], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let i = 0; i < coordinates.length - 1; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) {\n if (coordinates.length - 1 - offset < 3) {\n // avoid alternating coordinates array if ring is removed\n return [index, true]\n }\n coordinates.splice(coordinates.length - 1 - offset, offset + 1, coordinates[0])\n }\n return [index, false]\n}\n\nfunction collectPositions(geojson: GeoJsonObject, positions: Positions): void {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n collectPositions(geojson.features[i], positions)\n }\n } else if (isFeature(geojson)) {\n collectPositions(geojson.geometry, positions)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n collectPositions(geojson.geometries[i], positions)\n }\n } else if (isLineString(geojson)) {\n collectLinePositions(geojson.coordinates, positions)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectLinePositions(geojson.coordinates[i], positions)\n }\n } else if (isPolygon(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectRingPositions(geojson.coordinates[i], positions)\n }\n } else if (isMultiPolygon(geojson)) {\n for (let j, i = 0; i < geojson.coordinates.length; i++) {\n for (j = 0; j < geojson.coordinates[i].length; j++) {\n collectRingPositions(geojson.coordinates[i][j], positions)\n }\n }\n }\n}\n\nfunction collectLinePositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? -1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? -1 : p + i + 1)\n }\n}\n\nfunction collectRingPositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length - 1, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? p + n - 1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? p : p + i + 1)\n }\n}\n","import {\n GeoJsonObject,\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon,\n GeometryCollection,\n} from 'geojson'\n\nexport type FinitePositiveNumber = number & { readonly __type: unique symbol }\n\nexport function isFinitePositiveNumber(value: number): value is FinitePositiveNumber {\n return value != null && Number.isFinite(value) && value > 0\n}\n\nexport function isObject(value: object): value is object {\n return typeof value === 'object' && value !== null\n}\n\nexport function isFeature(value: GeoJsonObject): value is Feature {\n return isObject(value) && value?.type === 'Feature'\n}\n\nexport function isFeatureCollection(value: GeoJsonObject): value is FeatureCollection {\n return isObject(value) && value?.type === 'FeatureCollection'\n}\n\nexport function isLineString(value: GeoJsonObject): value is LineString {\n return isObject(value) && value?.type === 'LineString'\n}\n\nexport function isMultiLineString(value: GeoJsonObject): value is MultiLineString {\n return isObject(value) && value?.type === 'MultiLineString'\n}\n\nexport function isPolygon(value: GeoJsonObject): value is Polygon {\n return isObject(value) && value?.type === 'Polygon'\n}\n\nexport function isMultiPolygon(value: GeoJsonObject): value is MultiPolygon {\n return isObject(value) && value?.type === 'MultiPolygon'\n}\n\nexport function isGeometryCollection(value: GeoJsonObject): value is GeometryCollection {\n return isObject(value) && value?.type === 'GeometryCollection'\n}\n","import { Position } from 'geojson'\n\nexport type Groups = {\n sortIndexes: Uint32Array\n groupedFrom: Uint32Array\n groupedTo: Uint32Array\n}\n\nexport function groupPositions(coordinates: Position[]): Groups {\n const sortIndexes = new Uint32Array(coordinates.length)\n const groupedFrom = new Uint32Array(coordinates.length)\n const groupedTo = new Uint32Array(coordinates.length)\n for (let i = 0; i < coordinates.length; i++) {\n sortIndexes[i] = i\n }\n sortIndexes.sort((a, b) => {\n return coordinates[a][0] - coordinates[b][0] || coordinates[a][1] - coordinates[b][1]\n })\n if (coordinates.length) {\n groupedTo[sortIndexes[coordinates.length - 1]] = groupedTo.length - 1\n }\n for (let i = 1, j = coordinates.length - 2; i < coordinates.length; i++, j--) {\n if (\n coordinates[sortIndexes[i]][0] !== coordinates[sortIndexes[i - 1]][0] ||\n coordinates[sortIndexes[i]][1] !== coordinates[sortIndexes[i - 1]][1]\n ) {\n groupedFrom[sortIndexes[i]] = i\n } else {\n groupedFrom[sortIndexes[i]] = groupedFrom[sortIndexes[i - 1]]\n }\n if (\n coordinates[sortIndexes[j]][0] !== coordinates[sortIndexes[j + 1]][0] ||\n coordinates[sortIndexes[j]][1] !== coordinates[sortIndexes[j + 1]][1]\n ) {\n groupedTo[sortIndexes[j]] = j\n } else {\n groupedTo[sortIndexes[j]] = groupedTo[sortIndexes[j + 1]]\n }\n }\n return {\n sortIndexes,\n groupedFrom,\n groupedTo,\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAA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a,IAC9CuC,EAAqBpD,EAAQ,YAAYa,CAAC,EAAGN,CAAS,UAE/CuC,EAAU9C,CAAO,EAC1B,QAASa,EAAI,EAAGA,EAAIb,EAAQ,YAAY,OAAQa,IAC9CwC,EAAqBrD,EAAQ,YAAYa,CAAC,EAAGN,CAAS,UAE/C0C,EAAejD,CAAO,EAC/B,QAASsC,EAAGzB,EAAI,EAAGA,EAAIb,EAAQ,YAAY,OAAQa,IACjD,IAAKyB,EAAI,EAAGA,EAAItC,EAAQ,YAAYa,CAAC,EAAE,OAAQyB,IAC7Ce,EAAqBrD,EAAQ,YAAYa,CAAC,EAAEyB,CAAC,EAAG/B,CAAS,CAIjE,CAEA,SAAS6C,EAAqBlC,EAAyBX,EAAsB,CAC3E,QAAS+C,EAAI/C,EAAU,YAAY,OAAQ,EAAIW,EAAY,OAAQL,EAAI,EAAGA,EAAI,EAAGA,IAC/EN,EAAU,YAAY,KAAKW,EAAYL,CAAC,CAAC,EACzCN,EAAU,YAAY,KAAKM,IAAM,EAAI,GAAKyC,EAAIzC,EAAI,CAAC,EACnDN,EAAU,YAAY,KAAKM,IAAM,EAAI,EAAI,GAAKyC,EAAIzC,EAAI,CAAC,CAE3D,CAEA,SAASwC,EAAqBnC,EAAyBX,EAAsB,CAC3E,QAAS+C,EAAI/C,EAAU,YAAY,OAAQ,EAAIW,EAAY,OAAS,EAAGL,EAAI,EAAGA,EAAI,EAAGA,IACnFN,EAAU,YAAY,KAAKW,EAAYL,CAAC,CAAC,EACzCN,EAAU,YAAY,KAAKM,IAAM,EAAIyC,EAAI,EAAI,EAAIA,EAAIzC,EAAI,CAAC,EAC1DN,EAAU,YAAY,KAAKM,IAAM,EAAI,EAAIyC,EAAIA,EAAIzC,EAAI,CAAC,CAE1D","names":["index_exports","__export","index_default","__toCommonJS","isFinitePositiveNumber","value","isObject","isFeature","isFeatureCollection","isLineString","isMultiLineString","isPolygon","isMultiPolygon","isGeometryCollection","groupPositions","coordinates","sortIndexes","groupedFrom","groupedTo","i","a","b","j","index_default","geojson","options","isObject","tolerance","isFinitePositiveNumber","fraction","mutate","positions","collectPositions","updatePositions","deletePositions","groupPositions","getPositionArea","i","heapcompare","a","b","priority","coordinates","heapsink","heap","heapRev","l","r","t","heapswap","heapbubble","heapupdate","val","heappop","heapify","groups","n","isDeleted","toDelete","candidatesByGroupFrom","isCandidate","k","j","index","isFeatureCollection","isFeature","isGeometryCollection","isLineString","updateLinePositions","isMultiLineString","isPolygon","remove","updateRingsPositions","isMultiPolygon","offset","updateRingPositions","collectLinePositions","collectRingPositions","p"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/lib/typeGuards.ts","../src/lib/functions.ts"],"sourcesContent":["import { GeoJsonObject, Position } from 'geojson'\nimport {\n isObject,\n isFinitePositiveNumber,\n isFeature,\n isFeatureCollection,\n isLineString,\n isMultiLineString,\n isPolygon,\n isMultiPolygon,\n isGeometryCollection,\n} from '@lib/typeGuards'\nimport { deletePositions, groupPositions, type Positions } from '@lib/functions'\n\nexport type SimplifyOptions = {\n tolerance?: number\n fraction?: number\n mutate?: boolean\n}\n\nexport default function (geojson: GeoJsonObject, options: SimplifyOptions = {}): GeoJsonObject {\n // validate input data\n if (!isObject(geojson)) {\n throw new TypeError(\n `Expected provided GeoJSON to be an object, but received ${geojson === null ? 'null' : typeof geojson}.`,\n )\n }\n\n // validate options\n let tolerance = 0\n if (options.tolerance !== undefined) {\n if (!isFinitePositiveNumber(options.tolerance)) {\n throw new Error(`Expected provided tolerance to be a finite positive number, but received ${options.tolerance}.`)\n }\n tolerance = options.tolerance\n }\n let fraction = 0\n if (options.fraction !== undefined) {\n if (!isFinitePositiveNumber(options.fraction)) {\n throw new Error(`Expected provided fraction to be a finite positive number, but received ${options.fraction}.`)\n }\n if (options.fraction > 1) {\n throw new Error(`Expected provided fraction to be less or equal to 1, but received ${options.fraction}.`)\n }\n fraction = options.fraction\n }\n let mutate = true\n if (options.mutate !== undefined) {\n mutate = !!options.mutate\n }\n\n // exit if no simplification options provided\n if (tolerance === 0 && fraction === 0) {\n return geojson\n }\n\n if (!mutate) {\n geojson = structuredClone(geojson)\n }\n\n const positions: Positions = {\n coordinates: [],\n nextIndexes: [],\n prevIndexes: [],\n }\n collectPositions(geojson, positions)\n\n if (positions.coordinates.length) {\n updatePositions(geojson, deletePositions(positions, groupPositions(positions.coordinates), tolerance, fraction), 0)\n }\n\n return geojson\n}\nfunction updatePositions(geojson: GeoJsonObject, isDeleted: Uint8Array, index: number): number {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n index = updatePositions(geojson.features[i], isDeleted, index)\n }\n } else if (isFeature(geojson)) {\n index = updatePositions(geojson.geometry, isDeleted, index)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n index = updatePositions(geojson.geometries[i], isDeleted, index)\n }\n } else if (isLineString(geojson)) {\n index = updateLinePositions(geojson.coordinates, isDeleted, index)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n index = updateLinePositions(geojson.coordinates[i], isDeleted, index)\n }\n } else if (isPolygon(geojson)) {\n let remove = false\n ;[index, remove] = updateRingsPositions(geojson.coordinates, isDeleted, index)\n if (remove) geojson.coordinates.splice(0)\n } else if (isMultiPolygon(geojson)) {\n let offset = 0\n for (let remove = false, i = 0; i < geojson.coordinates.length; i++) {\n ;[index, remove] = updateRingsPositions(geojson.coordinates[i], isDeleted, index)\n if (remove) {\n offset++\n } else if (offset) {\n geojson.coordinates[i - offset] = geojson.coordinates[i]\n }\n }\n if (offset) geojson.coordinates.splice(geojson.coordinates.length - offset)\n }\n return index\n}\n\nfunction updateLinePositions(coordinates: Position[], isDeleted: Uint8Array, index: number): number {\n let offset = 0\n for (let i = 0; i < coordinates.length; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return index\n}\n\nfunction updateRingsPositions(coordinates: Position[][], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let remove = false, i = 0; i < coordinates.length; i++) {\n ;[index, remove] = updateRingPositions(coordinates[i], isDeleted, index)\n if (remove) {\n // skip interior rings if exterior ring is removed\n if (i === 0) {\n for (i = 1; i < coordinates.length; i++) {\n if (coordinates[i].length) index += coordinates[i].length - 1\n }\n // avoid alternating coordinates array if exterior ring is removed\n return [index, true]\n }\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return [index, false]\n}\n\nfunction updateRingPositions(coordinates: Position[], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let i = 0; i < coordinates.length - 1; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) {\n if (coordinates.length - 1 - offset < 3) {\n // avoid alternating coordinates array if ring is removed\n return [index, true]\n }\n coordinates.splice(coordinates.length - 1 - offset, offset + 1, coordinates[0])\n }\n return [index, false]\n}\n\nfunction collectPositions(geojson: GeoJsonObject, positions: Positions): void {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n collectPositions(geojson.features[i], positions)\n }\n } else if (isFeature(geojson)) {\n collectPositions(geojson.geometry, positions)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n collectPositions(geojson.geometries[i], positions)\n }\n } else if (isLineString(geojson)) {\n collectLinePositions(geojson.coordinates, positions)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectLinePositions(geojson.coordinates[i], positions)\n }\n } else if (isPolygon(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectRingPositions(geojson.coordinates[i], positions)\n }\n } else if (isMultiPolygon(geojson)) {\n for (let j, i = 0; i < geojson.coordinates.length; i++) {\n for (j = 0; j < geojson.coordinates[i].length; j++) {\n collectRingPositions(geojson.coordinates[i][j], positions)\n }\n }\n }\n}\n\nfunction collectLinePositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? -1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? -1 : p + i + 1)\n }\n}\n\nfunction collectRingPositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length - 1, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? p + n - 1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? p : p + i + 1)\n }\n}\n","import {\n GeoJsonObject,\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon,\n GeometryCollection,\n} from 'geojson'\n\nexport type FinitePositiveNumber = number & { readonly __type: unique symbol }\n\nexport function isFinitePositiveNumber(value: number): value is FinitePositiveNumber {\n return value != null && Number.isFinite(value) && value > 0\n}\n\nexport function isObject(value: object): value is object {\n return typeof value === 'object' && value !== null\n}\n\nexport function isFeature(value: GeoJsonObject): value is Feature {\n return isObject(value) && value?.type === 'Feature'\n}\n\nexport function isFeatureCollection(value: GeoJsonObject): value is FeatureCollection {\n return isObject(value) && value?.type === 'FeatureCollection'\n}\n\nexport function isLineString(value: GeoJsonObject): value is LineString {\n return isObject(value) && value?.type === 'LineString'\n}\n\nexport function isMultiLineString(value: GeoJsonObject): value is MultiLineString {\n return isObject(value) && value?.type === 'MultiLineString'\n}\n\nexport function isPolygon(value: GeoJsonObject): value is Polygon {\n return isObject(value) && value?.type === 'Polygon'\n}\n\nexport function isMultiPolygon(value: GeoJsonObject): value is MultiPolygon {\n return isObject(value) && value?.type === 'MultiPolygon'\n}\n\nexport function isGeometryCollection(value: GeoJsonObject): value is GeometryCollection {\n return isObject(value) && value?.type === 'GeometryCollection'\n}\n","import { Position } from 'geojson'\n\nexport type Positions = {\n coordinates: Position[]\n nextIndexes: number[]\n prevIndexes: number[]\n}\n\nexport type Groups = {\n sortIndexes: Uint32Array\n groupedFrom: Uint32Array\n groupedTo: Uint32Array\n}\n\nexport function groupPositions(coordinates: Position[]): Groups {\n const sortIndexes = new Uint32Array(coordinates.length)\n const groupedFrom = new Uint32Array(coordinates.length)\n const groupedTo = new Uint32Array(coordinates.length)\n for (let i = 0; i < coordinates.length; i++) {\n sortIndexes[i] = i\n }\n sortIndexes.sort((a, b) => {\n const deltaX = coordinates[a][0] - coordinates[b][0]\n if (deltaX) {\n return deltaX < 0 ? -1 : 1\n }\n const deltaY = coordinates[a][1] - coordinates[b][1]\n return deltaY < 0 ? -1 : deltaY > 0 ? 1 : 0\n })\n if (coordinates.length) {\n groupedTo[sortIndexes[coordinates.length - 1]] = groupedTo.length - 1\n }\n for (let i = 1, j = coordinates.length - 2; i < coordinates.length; i++, j--) {\n if (\n coordinates[sortIndexes[i]][0] !== coordinates[sortIndexes[i - 1]][0] ||\n coordinates[sortIndexes[i]][1] !== coordinates[sortIndexes[i - 1]][1]\n ) {\n groupedFrom[sortIndexes[i]] = i\n } else {\n groupedFrom[sortIndexes[i]] = groupedFrom[sortIndexes[i - 1]]\n }\n if (\n coordinates[sortIndexes[j]][0] !== coordinates[sortIndexes[j + 1]][0] ||\n coordinates[sortIndexes[j]][1] !== coordinates[sortIndexes[j + 1]][1]\n ) {\n groupedTo[sortIndexes[j]] = j\n } else {\n groupedTo[sortIndexes[j]] = groupedTo[sortIndexes[j + 1]]\n }\n }\n return {\n sortIndexes,\n groupedFrom,\n groupedTo,\n }\n}\n\nfunction getPositionArea(i: number, positions: Positions): number {\n return (\n Math.abs(\n positions.coordinates[i][0] *\n (positions.coordinates[positions.prevIndexes[i]][1] - positions.coordinates[positions.nextIndexes[i]][1]) +\n positions.coordinates[positions.prevIndexes[i]][0] *\n (positions.coordinates[positions.nextIndexes[i]][1] - positions.coordinates[i][1]) +\n positions.coordinates[positions.nextIndexes[i]][0] *\n (positions.coordinates[i][1] - positions.coordinates[positions.prevIndexes[i]][1]),\n ) / 2\n )\n}\n\nfunction heapcompare(a: number, b: number, priority: Float64Array, coordinates: Position[]): number {\n return priority[a] - priority[b] || coordinates[a][0] - coordinates[b][0] || coordinates[a][1] - coordinates[b][1]\n}\n\nfunction heapsink(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n const value = heap[i]\n let l: number, r: number, t: number\n let selected: number\n while (true) {\n t = i\n selected = value\n if ((l = i << 1) <= heap[0] && heapcompare(selected, heap[l], priority, coordinates) > 0) {\n t = l\n selected = heap[l]\n }\n if ((r = l + 1) <= heap[0] && heapcompare(selected, heap[r], priority, coordinates) > 0) t = r\n if (i === t) break\n heap[i] = heap[t]\n heapRev[heap[i]] = i\n i = t\n }\n heap[i] = value\n heapRev[value] = i\n return i\n}\n\nfunction heapbubble(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n let t: number\n while (i > 1) {\n t = i >>> 1\n if (i === t || heapcompare(heap[t], heap[i], priority, coordinates) <= 0) break\n heapswap(heap, heapRev, i, t)\n i = t\n }\n return i\n}\n\nfunction heapupdate(\n heap: Uint32Array,\n heapRev: Uint32Array,\n val: number,\n priority: Float64Array,\n coordinates: Position[],\n): void {\n heapbubble(heap, heapRev, heapsink(heap, heapRev, heapRev[val], priority, coordinates), priority, coordinates)\n}\n\nfunction heapswap(heap: Uint32Array, heapRev: Uint32Array, i: number, t: number): void {\n heapRev[heap[i]] = t\n heapRev[heap[t]] = i\n ;[heap[i], heap[t]] = [heap[t], heap[i]]\n}\n\nfunction heappop(heap: Uint32Array, heapRev: Uint32Array, priority: Float64Array, coordinates: Position[]): number {\n if (heap[0] > 1) {\n heapswap(heap, heapRev, 1, heap[0])\n heap[0]--\n heapsink(heap, heapRev, 1, priority, coordinates)\n return heap[heap[0] + 1]\n } else if (heap[0] === 1) {\n heap[0]--\n return heap[1]\n }\n return -1\n}\n\nfunction heapify(heap: Uint32Array, heapRev: Uint32Array, priority: Float64Array, coordinates: Position[]): void {\n for (let i = heap[0] >>> 1; i > 0; i--) {\n heapsink(heap, heapRev, i, priority, coordinates)\n }\n}\n\nexport function deletePositions(positions: Positions, groups: Groups, tolerance: number, fraction: number): Uint8Array {\n const n = positions.coordinates.length\n\n const isDeleted = new Uint8Array(n)\n let toDelete = Math.round(n * fraction)\n\n const candidatesByGroupFrom = new Uint32Array(n)\n const isCandidate = new Uint8Array(n)\n\n const heap = new Uint32Array(n + 1)\n const priority = new Float64Array(n)\n const heapRev = new Uint32Array(n)\n\n for (let i = 0; i < n; i++) {\n if (positions.prevIndexes[i] !== -1 && positions.nextIndexes[i] !== -1) {\n priority[i] = getPositionArea(i, positions)\n heap[0]++\n heap[heap[0]] = i\n heapRev[i] = heap[0]\n }\n }\n heapify(heap, heapRev, priority, positions.coordinates)\n\n let i: number\n while (heap[0]) {\n i = heappop(heap, heapRev, priority, positions.coordinates)\n\n if (isDeleted[i]) {\n continue\n }\n\n if (priority[i] >= tolerance && toDelete <= 0) {\n break\n }\n\n if (!isCandidate[i]) {\n isCandidate[i] = 1\n candidatesByGroupFrom[groups.groupedFrom[i]]++\n }\n\n if (candidatesByGroupFrom[groups.groupedFrom[i]] !== groups.groupedTo[i] - groups.groupedFrom[i] + 1) {\n continue\n }\n\n for (let k: number, j = groups.groupedFrom[i]; j <= groups.groupedTo[i]; j++) {\n k = groups.sortIndexes[j]\n if (isDeleted[k]) {\n continue\n }\n\n if (\n positions.prevIndexes[k] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[k]] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[positions.prevIndexes[k]]] === k\n ) {\n if (!isCandidate[positions.prevIndexes[k]]) {\n isCandidate[positions.prevIndexes[k]] = 1\n candidatesByGroupFrom[groups.groupedFrom[positions.prevIndexes[k]]]++\n }\n if (!isCandidate[positions.nextIndexes[k]]) {\n isCandidate[positions.nextIndexes[k]] = 1\n candidatesByGroupFrom[groups.groupedFrom[positions.nextIndexes[k]]]++\n }\n\n if (\n candidatesByGroupFrom[groups.groupedFrom[positions.prevIndexes[k]]] ===\n groups.groupedTo[positions.prevIndexes[k]] - groups.groupedFrom[positions.prevIndexes[k]] + 1 &&\n candidatesByGroupFrom[groups.groupedFrom[positions.nextIndexes[k]]] ===\n groups.groupedTo[positions.nextIndexes[k]] - groups.groupedFrom[positions.nextIndexes[k]] + 1\n ) {\n isDeleted[k] = 1\n isDeleted[positions.nextIndexes[k]] = 1\n isDeleted[positions.prevIndexes[k]] = 1\n toDelete -= 3\n j = groups.groupedFrom[i] - 1\n }\n } else {\n isDeleted[k] = 1\n toDelete--\n positions.prevIndexes[positions.nextIndexes[k]] = positions.prevIndexes[k]\n positions.nextIndexes[positions.prevIndexes[k]] = positions.nextIndexes[k]\n\n if (positions.prevIndexes[positions.prevIndexes[k]] !== -1) {\n priority[positions.prevIndexes[k]] = getPositionArea(positions.prevIndexes[k], positions)\n heapupdate(heap, heapRev, positions.prevIndexes[k], priority, positions.coordinates)\n }\n if (positions.nextIndexes[positions.nextIndexes[k]] !== -1) {\n priority[positions.nextIndexes[k]] = getPositionArea(positions.nextIndexes[k], positions)\n heapupdate(heap, heapRev, positions.nextIndexes[k], priority, positions.coordinates)\n }\n }\n }\n }\n return isDeleted\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GCaO,SAASI,EAAuBC,EAA8C,CACnF,OAAOA,GAAS,MAAQ,OAAO,SAASA,CAAK,GAAKA,EAAQ,CAC5D,CAEO,SAASC,EAASD,EAAgC,CACvD,OAAO,OAAOA,GAAU,UAAYA,IAAU,IAChD,CAEO,SAASE,EAAUF,EAAwC,CAChE,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,SAC5C,CAEO,SAASG,EAAoBH,EAAkD,CACpF,OAAOC,EAASD,C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CAAO,EAC1B,QAASe,EAAI,EAAGA,EAAIf,EAAQ,YAAY,OAAQe,IAC9Cc,EAAqB7B,EAAQ,YAAYe,CAAC,EAAGR,CAAS,UAE/CiB,EAAexB,CAAO,EAC/B,QAAS8B,EAAGf,EAAI,EAAGA,EAAIf,EAAQ,YAAY,OAAQe,IACjD,IAAKe,EAAI,EAAGA,EAAI9B,EAAQ,YAAYe,CAAC,EAAE,OAAQe,IAC7CD,EAAqB7B,EAAQ,YAAYe,CAAC,EAAEe,CAAC,EAAGvB,CAAS,CAIjE,CAEA,SAASqB,EAAqBF,EAAyBnB,EAAsB,CAC3E,QAASwB,EAAIxB,EAAU,YAAY,OAAQ,EAAImB,EAAY,OAAQX,EAAI,EAAGA,EAAI,EAAGA,IAC/ER,EAAU,YAAY,KAAKmB,EAAYX,CAAC,CAAC,EACzCR,EAAU,YAAY,KAAKQ,IAAM,EAAI,GAAKgB,EAAIhB,EAAI,CAAC,EACnDR,EAAU,YAAY,KAAKQ,IAAM,EAAI,EAAI,GAAKgB,EAAIhB,EAAI,CAAC,CAE3D,CAEA,SAASc,EAAqBH,EAAyBnB,EAAsB,CAC3E,QAASwB,EAAIxB,EAAU,YAAY,OAAQ,EAAImB,EAAY,OAAS,EAAGX,EAAI,EAAGA,EAAI,EAAGA,IACnFR,EAAU,YAAY,KAAKmB,EAAYX,CAAC,CAAC,EACzCR,EAAU,YAAY,KAAKQ,IAAM,EAAIgB,EAAI,EAAI,EAAIA,EAAIhB,EAAI,CAAC,EAC1DR,EAAU,YAAY,KAAKQ,IAAM,EAAI,EAAIgB,EAAIA,EAAIhB,EAAI,CAAC,CAE1D","names":["index_exports","__export","index_default","__toCommonJS","isFinitePositiveNumber","value","isObject","isFeature","isFeatureCollection","isLineString","isMultiLineString","isPolygon","isMultiPolygon","isGeometryCollection","groupPositions","coordinates","sortIndexes","groupedFrom","groupedTo","i","a","b","deltaX","deltaY","j","getPositionArea","positions","heapcompare","priority","heapsink","heap","heapRev","value","l","r","t","selected","heapbubble","heapswap","heapupdate","val","heappop","heapify","deletePositions","groups","tolerance","fraction","n","isDeleted","toDelete","candidatesByGroupFrom","isCandidate","k","index_default","geojson","options","isObject","tolerance","isFinitePositiveNumber","fraction","mutate","positions","collectPositions","updatePositions","deletePositions","groupPositions","isDeleted","index","isFeatureCollection","i","isFeature","isGeometryCollection","isLineString","updateLinePositions","isMultiLineString","isPolygon","remove","updateRingsPositions","isMultiPolygon","offset","coordinates","updateRingPositions","collectLinePositions","collectRingPositions","j","p"]}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- function v(e){return e!=null&&Number.isFinite(e)&&e>0}function a(e){return typeof e=="object"&&e!==null}function A(e){return a(e)&&e?.type==="Feature"}function F(e){return a(e)&&e?.type==="FeatureCollection"}function h(e){return a(e)&&e?.type==="LineString"}function U(e){return a(e)&&e?.type==="MultiLineString"}function G(e){return a(e)&&e?.type==="Polygon"}function g(e){return a(e)&&e?.type==="MultiPolygon"}function w(e){return a(e)&&e?.type==="GeometryCollection"}function L(e){let r=new Uint32Array(e.length),t=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let l=0;l<e.length;l++)r[l]=l;r.sort((l,u)=>e[l][0]-e[u][0]||e[l][1]-e[u][1]),e.length&&(n[r[e.length-1]]=n.length-1);for(let l=1,u=e.length-2;l<e.length;l++,u--)e[r[l]][0]!==e[r[l-1]][0]||e[r[l]][1]!==e[r[l-1]][1]?t[r[l]]=l:t[r[l]]=t[r[l-1]],e[r[u]][0]!==e[r[u+1]][0]||e[r[u]][1]!==e[r[u+1]][1]?n[r[u]]=u:n[r[u]]=n[r[u+1]];return{sortIndexes:r,groupedFrom:t,groupedTo:n}}function Q(e,r={}){if(!a(e))throw new TypeError(`Expected provided GeoJSON to be an object, but received ${e===null?"null":typeof e}.`);let t=0;if(r.tolerance!==void 0){if(!v(r.tolerance))throw new Error(`Expected provided tolerance to be a finite positive number, but received ${r.tolerance}.`);t=r.tolerance}let n=0;if(r.fraction!==void 0){if(!v(r.fraction))throw new Error(`Expected provided fraction to be a finite positive number, but received ${r.fraction}.`);if(r.fraction>1)throw new Error(`Expected provided fraction to be less or equal to 1, but received ${r.fraction}.`);n=r.fraction}let l=!0;if(r.mutate!==void 0&&(l=!!r.mutate),t===0&&n===0)return e;l||(e=structuredClone(e));let u={coordinates:[],nextIndexes:[],prevIndexes:[]};return P(e,u),u.coordinates.length&&I(e,q(u,L(u.coordinates),t,n),0),e}function O(e,r){return Math.abs(r.coordinates[e][0]*(r.coordinates[r.prevIndexes[e]][1]-r.coordinates[r.nextIndexes[e]][1])+r.coordinates[r.prevIndexes[e]][0]*(r.coordinates[r.nextIndexes[e]][1]-r.coordinates[e][1])+r.coordinates[r.nextIndexes[e]][0]*(r.coordinates[e][1]-r.coordinates[r.prevIndexes[e]][1]))/2}function J(e,r,t,n){return t[e]-t[r]||n[e][0]-n[r][0]||n[e][1]-n[r][1]}function S(e,r,t,n,l){let u,o,i;for(;i=t,(u=t<<1)<=e[0]&&J(e[i],e[u],n,l)>0&&(i=u),(o=u+1)<=e[0]&&J(e[i],e[o],n,l)>0&&(i=o),t!==i;)C(e,r,t,i),t=i;return t}function N(e,r,t,n,l){let u;for(;t>1&&(u=t>>>1,!(t===u||J(e[u],e[t],n,l)<=0));)C(e,r,t,u),t=u;return t}function M(e,r,t,n,l){N(e,r,S(e,r,r[t],n,l),n,l)}function C(e,r,t,n){r[e[t]]=n,r[e[n]]=t,[e[t],e[n]]=[e[n],e[t]]}function k(e,r,t,n){return e[0]>1?(C(e,r,1,e[0]),e[0]--,S(e,r,1,t,n),e[e[0]+1]):e[0]===1?(e[0]--,e[1]):-1}function $(e,r,t,n){for(let l=e[0]>>>1;l>0;l--)S(e,r,l,t,n)}function q(e,r,t,n){let l=e.coordinates.length,u=new Uint8Array(l),o=Math.round(l*n),i=new Uint32Array(l),b=new Uint8Array(l),m=new Uint32Array(l+1),d=new Float64Array(l),x=new Uint32Array(l);for(let f=0;f<l;f++)e.prevIndexes[f]!==-1&&e.nextIndexes[f]!==-1&&(d[f]=O(f,e),m[0]++,m[m[0]]=f,x[f]=m[0]);$(m,x,d,e.coordinates);let c;for(;m[0];)if(c=k(m,x,d,e.coordinates),!u[c]){if(d[c]>=t&&o<=0)break;if(b[c]||(b[c]=1,i[r.groupedFrom[c]]++),i[r.groupedFrom[c]]===r.groupedTo[c]-r.groupedFrom[c]+1)for(let f,y=r.groupedFrom[c];y<=r.groupedTo[c];y++)f=r.sortIndexes[y],!u[f]&&(e.prevIndexes[f]!==-1&&e.prevIndexes[e.prevIndexes[f]]!==-1&&e.prevIndexes[e.prevIndexes[e.prevIndexes[f]]]===f?(b[e.prevIndexes[f]]||(b[e.prevIndexes[f]]=1,i[r.groupedFrom[e.prevIndexes[f]]]++),b[e.nextIndexes[f]]||(b[e.nextIndexes[f]]=1,i[r.groupedFrom[e.nextIndexes[f]]]++),i[r.groupedFrom[e.prevIndexes[f]]]===r.groupedTo[e.prevIndexes[f]]-r.groupedFrom[e.prevIndexes[f]]+1&&i[r.groupedFrom[e.nextIndexes[f]]]===r.groupedTo[e.nextIndexes[f]]-r.groupedFrom[e.nextIndexes[f]]+1&&(u[f]=1,u[e.nextIndexes[f]]=1,u[e.prevIndexes[f]]=1,o-=3,y=r.groupedFrom[c]-1)):(u[f]=1,o--,e.prevIndexes[e.nextIndexes[f]]=e.prevIndexes[f],e.nextIndexes[e.prevIndexes[f]]=e.nextIndexes[f],e.prevIndexes[e.prevIndexes[f]]!==-1&&(d[e.prevIndexes[f]]=O(e.prevIndexes[f],e),M(m,x,e.prevIndexes[f],d,e.coordinates)),e.nextIndexes[e.nextIndexes[f]]!==-1&&(d[e.nextIndexes[f]]=O(e.nextIndexes[f],e),M(m,x,e.nextIndexes[f],d,e.coordinates))))}return u}function I(e,r,t){if(F(e))for(let n=0;n<e.features.length;n++)t=I(e.features[n],r,t);else if(A(e))t=I(e.geometry,r,t);else if(w(e))for(let n=0;n<e.geometries.length;n++)t=I(e.geometries[n],r,t);else if(h(e))t=p(e.coordinates,r,t);else if(U(e))for(let n=0;n<e.coordinates.length;n++)t=p(e.coordinates[n],r,t);else if(G(e)){let n=!1;[t,n]=s(e.coordinates,r,t),n&&e.coordinates.splice(0)}else if(g(e)){let n=0;for(let l=!1,u=0;u<e.coordinates.length;u++)[t,l]=s(e.coordinates[u],r,t),l?n++:n&&(e.coordinates[u-n]=e.coordinates[u]);n&&e.coordinates.splice(e.coordinates.length-n)}return t}function p(e,r,t){let n=0;for(let l=0;l<e.length;l++)r[t]?n++:n&&(e[l-n]=e[l]),t++;return n&&e.splice(e.length-n),t}function s(e,r,t){let n=0;for(let l=!1,u=0;u<e.length;u++)if([t,l]=_(e[u],r,t),l){if(u===0){for(u=1;u<e.length;u++)e[u].length&&(t+=e[u].length-1);return[t,!0]}n++}else n&&(e[u-n]=e[u]);return n&&e.splice(e.length-n),[t,!1]}function _(e,r,t){let n=0;for(let l=0;l<e.length-1;l++)r[t]?n++:n&&(e[l-n]=e[l]),t++;if(n){if(e.length-1-n<3)return[t,!0];e.splice(e.length-1-n,n+1,e[0])}return[t,!1]}function P(e,r){if(F(e))for(let t=0;t<e.features.length;t++)P(e.features[t],r);else if(A(e))P(e.geometry,r);else if(w(e))for(let t=0;t<e.geometries.length;t++)P(e.geometries[t],r);else if(h(e))E(e.coordinates,r);else if(U(e))for(let t=0;t<e.coordinates.length;t++)E(e.coordinates[t],r);else if(G(e))for(let t=0;t<e.coordinates.length;t++)T(e.coordinates[t],r);else if(g(e))for(let t,n=0;n<e.coordinates.length;n++)for(t=0;t<e.coordinates[n].length;t++)T(e.coordinates[n][t],r)}function E(e,r){for(let t=r.coordinates.length,n=e.length,l=0;l<n;l++)r.coordinates.push(e[l]),r.prevIndexes.push(l===0?-1:t+l-1),r.nextIndexes.push(l===n-1?-1:t+l+1)}function T(e,r){for(let t=r.coordinates.length,n=e.length-1,l=0;l<n;l++)r.coordinates.push(e[l]),r.prevIndexes.push(l===0?t+n-1:t+l-1),r.nextIndexes.push(l===n-1?t:t+l+1)}export{Q as default};
1
+ function v(e){return e!=null&&Number.isFinite(e)&&e>0}function a(e){return typeof e=="object"&&e!==null}function A(e){return a(e)&&e?.type==="Feature"}function F(e){return a(e)&&e?.type==="FeatureCollection"}function h(e){return a(e)&&e?.type==="LineString"}function U(e){return a(e)&&e?.type==="MultiLineString"}function g(e){return a(e)&&e?.type==="Polygon"}function G(e){return a(e)&&e?.type==="MultiPolygon"}function w(e){return a(e)&&e?.type==="GeometryCollection"}function C(e){let r=new Uint32Array(e.length),t=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let l=0;l<e.length;l++)r[l]=l;r.sort((l,u)=>{let o=e[l][0]-e[u][0];if(o)return o<0?-1:1;let c=e[l][1]-e[u][1];return c<0?-1:c>0?1:0}),e.length&&(n[r[e.length-1]]=n.length-1);for(let l=1,u=e.length-2;l<e.length;l++,u--)e[r[l]][0]!==e[r[l-1]][0]||e[r[l]][1]!==e[r[l-1]][1]?t[r[l]]=l:t[r[l]]=t[r[l-1]],e[r[u]][0]!==e[r[u+1]][0]||e[r[u]][1]!==e[r[u+1]][1]?n[r[u]]=u:n[r[u]]=n[r[u+1]];return{sortIndexes:r,groupedFrom:t,groupedTo:n}}function O(e,r){return Math.abs(r.coordinates[e][0]*(r.coordinates[r.prevIndexes[e]][1]-r.coordinates[r.nextIndexes[e]][1])+r.coordinates[r.prevIndexes[e]][0]*(r.coordinates[r.nextIndexes[e]][1]-r.coordinates[e][1])+r.coordinates[r.nextIndexes[e]][0]*(r.coordinates[e][1]-r.coordinates[r.prevIndexes[e]][1]))/2}function s(e,r,t,n){return t[e]-t[r]||n[e][0]-n[r][0]||n[e][1]-n[r][1]}function J(e,r,t,n,l){let u=e[t],o,c,m,i;for(;m=t,i=u,(o=t<<1)<=e[0]&&s(i,e[o],n,l)>0&&(m=o,i=e[o]),(c=o+1)<=e[0]&&s(i,e[c],n,l)>0&&(m=c),t!==m;)e[t]=e[m],r[e[t]]=t,t=m;return e[t]=u,r[u]=t,t}function k(e,r,t,n,l){let u;for(;t>1&&(u=t>>>1,!(t===u||s(e[u],e[t],n,l)<=0));)L(e,r,t,u),t=u;return t}function S(e,r,t,n,l){k(e,r,J(e,r,r[t],n,l),n,l)}function L(e,r,t,n){r[e[t]]=n,r[e[n]]=t,[e[t],e[n]]=[e[n],e[t]]}function $(e,r,t,n){return e[0]>1?(L(e,r,1,e[0]),e[0]--,J(e,r,1,t,n),e[e[0]+1]):e[0]===1?(e[0]--,e[1]):-1}function q(e,r,t,n){for(let l=e[0]>>>1;l>0;l--)J(e,r,l,t,n)}function M(e,r,t,n){let l=e.coordinates.length,u=new Uint8Array(l),o=Math.round(l*n),c=new Uint32Array(l),m=new Uint8Array(l),i=new Uint32Array(l+1),b=new Float64Array(l),x=new Uint32Array(l);for(let f=0;f<l;f++)e.prevIndexes[f]!==-1&&e.nextIndexes[f]!==-1&&(b[f]=O(f,e),i[0]++,i[i[0]]=f,x[f]=i[0]);q(i,x,b,e.coordinates);let d;for(;i[0];)if(d=$(i,x,b,e.coordinates),!u[d]){if(b[d]>=t&&o<=0)break;if(m[d]||(m[d]=1,c[r.groupedFrom[d]]++),c[r.groupedFrom[d]]===r.groupedTo[d]-r.groupedFrom[d]+1)for(let f,y=r.groupedFrom[d];y<=r.groupedTo[d];y++)f=r.sortIndexes[y],!u[f]&&(e.prevIndexes[f]!==-1&&e.prevIndexes[e.prevIndexes[f]]!==-1&&e.prevIndexes[e.prevIndexes[e.prevIndexes[f]]]===f?(m[e.prevIndexes[f]]||(m[e.prevIndexes[f]]=1,c[r.groupedFrom[e.prevIndexes[f]]]++),m[e.nextIndexes[f]]||(m[e.nextIndexes[f]]=1,c[r.groupedFrom[e.nextIndexes[f]]]++),c[r.groupedFrom[e.prevIndexes[f]]]===r.groupedTo[e.prevIndexes[f]]-r.groupedFrom[e.prevIndexes[f]]+1&&c[r.groupedFrom[e.nextIndexes[f]]]===r.groupedTo[e.nextIndexes[f]]-r.groupedFrom[e.nextIndexes[f]]+1&&(u[f]=1,u[e.nextIndexes[f]]=1,u[e.prevIndexes[f]]=1,o-=3,y=r.groupedFrom[d]-1)):(u[f]=1,o--,e.prevIndexes[e.nextIndexes[f]]=e.prevIndexes[f],e.nextIndexes[e.prevIndexes[f]]=e.nextIndexes[f],e.prevIndexes[e.prevIndexes[f]]!==-1&&(b[e.prevIndexes[f]]=O(e.prevIndexes[f],e),S(i,x,e.prevIndexes[f],b,e.coordinates)),e.nextIndexes[e.nextIndexes[f]]!==-1&&(b[e.nextIndexes[f]]=O(e.nextIndexes[f],e),S(i,x,e.nextIndexes[f],b,e.coordinates))))}return u}function H(e,r={}){if(!a(e))throw new TypeError(`Expected provided GeoJSON to be an object, but received ${e===null?"null":typeof e}.`);let t=0;if(r.tolerance!==void 0){if(!v(r.tolerance))throw new Error(`Expected provided tolerance to be a finite positive number, but received ${r.tolerance}.`);t=r.tolerance}let n=0;if(r.fraction!==void 0){if(!v(r.fraction))throw new Error(`Expected provided fraction to be a finite positive number, but received ${r.fraction}.`);if(r.fraction>1)throw new Error(`Expected provided fraction to be less or equal to 1, but received ${r.fraction}.`);n=r.fraction}let l=!0;if(r.mutate!==void 0&&(l=!!r.mutate),t===0&&n===0)return e;l||(e=structuredClone(e));let u={coordinates:[],nextIndexes:[],prevIndexes:[]};return P(e,u),u.coordinates.length&&I(e,M(u,C(u.coordinates),t,n),0),e}function I(e,r,t){if(F(e))for(let n=0;n<e.features.length;n++)t=I(e.features[n],r,t);else if(A(e))t=I(e.geometry,r,t);else if(w(e))for(let n=0;n<e.geometries.length;n++)t=I(e.geometries[n],r,t);else if(h(e))t=E(e.coordinates,r,t);else if(U(e))for(let n=0;n<e.coordinates.length;n++)t=E(e.coordinates[n],r,t);else if(g(e)){let n=!1;[t,n]=T(e.coordinates,r,t),n&&e.coordinates.splice(0)}else if(G(e)){let n=0;for(let l=!1,u=0;u<e.coordinates.length;u++)[t,l]=T(e.coordinates[u],r,t),l?n++:n&&(e.coordinates[u-n]=e.coordinates[u]);n&&e.coordinates.splice(e.coordinates.length-n)}return t}function E(e,r,t){let n=0;for(let l=0;l<e.length;l++)r[t]?n++:n&&(e[l-n]=e[l]),t++;return n&&e.splice(e.length-n),t}function T(e,r,t){let n=0;for(let l=!1,u=0;u<e.length;u++)if([t,l]=_(e[u],r,t),l){if(u===0){for(u=1;u<e.length;u++)e[u].length&&(t+=e[u].length-1);return[t,!0]}n++}else n&&(e[u-n]=e[u]);return n&&e.splice(e.length-n),[t,!1]}function _(e,r,t){let n=0;for(let l=0;l<e.length-1;l++)r[t]?n++:n&&(e[l-n]=e[l]),t++;if(n){if(e.length-1-n<3)return[t,!0];e.splice(e.length-1-n,n+1,e[0])}return[t,!1]}function P(e,r){if(F(e))for(let t=0;t<e.features.length;t++)P(e.features[t],r);else if(A(e))P(e.geometry,r);else if(w(e))for(let t=0;t<e.geometries.length;t++)P(e.geometries[t],r);else if(h(e))p(e.coordinates,r);else if(U(e))for(let t=0;t<e.coordinates.length;t++)p(e.coordinates[t],r);else if(g(e))for(let t=0;t<e.coordinates.length;t++)N(e.coordinates[t],r);else if(G(e))for(let t,n=0;n<e.coordinates.length;n++)for(t=0;t<e.coordinates[n].length;t++)N(e.coordinates[n][t],r)}function p(e,r){for(let t=r.coordinates.length,n=e.length,l=0;l<n;l++)r.coordinates.push(e[l]),r.prevIndexes.push(l===0?-1:t+l-1),r.nextIndexes.push(l===n-1?-1:t+l+1)}function N(e,r){for(let t=r.coordinates.length,n=e.length-1,l=0;l<n;l++)r.coordinates.push(e[l]),r.prevIndexes.push(l===0?t+n-1:t+l-1),r.nextIndexes.push(l===n-1?t:t+l+1)}export{H as default};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lib/typeGuards.ts","../src/lib/functions.ts","../src/index.ts"],"sourcesContent":["import {\n GeoJsonObject,\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon,\n GeometryCollection,\n} from 'geojson'\n\nexport type FinitePositiveNumber = number & { readonly __type: unique symbol }\n\nexport function isFinitePositiveNumber(value: number): value is FinitePositiveNumber {\n return value != null && Number.isFinite(value) && value > 0\n}\n\nexport function isObject(value: object): value is object {\n return typeof value === 'object' && value !== null\n}\n\nexport function isFeature(value: GeoJsonObject): value is Feature {\n return isObject(value) && value?.type === 'Feature'\n}\n\nexport function isFeatureCollection(value: GeoJsonObject): value is FeatureCollection {\n return isObject(value) && value?.type === 'FeatureCollection'\n}\n\nexport function isLineString(value: GeoJsonObject): value is LineString {\n return isObject(value) && value?.type === 'LineString'\n}\n\nexport function isMultiLineString(value: GeoJsonObject): value is MultiLineString {\n return isObject(value) && value?.type === 'MultiLineString'\n}\n\nexport function isPolygon(value: GeoJsonObject): value is Polygon {\n return isObject(value) && value?.type === 'Polygon'\n}\n\nexport function isMultiPolygon(value: GeoJsonObject): value is MultiPolygon {\n return isObject(value) && value?.type === 'MultiPolygon'\n}\n\nexport function isGeometryCollection(value: GeoJsonObject): value is GeometryCollection {\n return isObject(value) && value?.type === 'GeometryCollection'\n}\n","import { Position } from 'geojson'\n\nexport type Groups = {\n sortIndexes: Uint32Array\n groupedFrom: Uint32Array\n groupedTo: Uint32Array\n}\n\nexport function groupPositions(coordinates: Position[]): Groups {\n const sortIndexes = new Uint32Array(coordinates.length)\n const groupedFrom = new Uint32Array(coordinates.length)\n const groupedTo = new Uint32Array(coordinates.length)\n for (let i = 0; i < coordinates.length; i++) {\n sortIndexes[i] = i\n }\n sortIndexes.sort((a, b) => {\n return coordinates[a][0] - coordinates[b][0] || coordinates[a][1] - coordinates[b][1]\n })\n if (coordinates.length) {\n groupedTo[sortIndexes[coordinates.length - 1]] = groupedTo.length - 1\n }\n for (let i = 1, j = coordinates.length - 2; i < coordinates.length; i++, j--) {\n if (\n coordinates[sortIndexes[i]][0] !== coordinates[sortIndexes[i - 1]][0] ||\n coordinates[sortIndexes[i]][1] !== coordinates[sortIndexes[i - 1]][1]\n ) {\n groupedFrom[sortIndexes[i]] = i\n } else {\n groupedFrom[sortIndexes[i]] = groupedFrom[sortIndexes[i - 1]]\n }\n if (\n coordinates[sortIndexes[j]][0] !== coordinates[sortIndexes[j + 1]][0] ||\n coordinates[sortIndexes[j]][1] !== coordinates[sortIndexes[j + 1]][1]\n ) {\n groupedTo[sortIndexes[j]] = j\n } else {\n groupedTo[sortIndexes[j]] = groupedTo[sortIndexes[j + 1]]\n }\n }\n return {\n sortIndexes,\n groupedFrom,\n groupedTo,\n }\n}\n","import { GeoJsonObject, Position } from 'geojson'\nimport {\n isObject,\n isFinitePositiveNumber,\n isFeature,\n isFeatureCollection,\n isLineString,\n isMultiLineString,\n isPolygon,\n isMultiPolygon,\n isGeometryCollection,\n} from '@lib/typeGuards'\nimport { groupPositions, type Groups } from '@lib/functions'\n\nexport type SimplifyOptions = {\n tolerance?: number\n fraction?: number\n mutate?: boolean\n}\n\ntype Positions = {\n coordinates: Position[]\n nextIndexes: number[]\n prevIndexes: number[]\n}\n\nexport default function (geojson: GeoJsonObject, options: SimplifyOptions = {}): GeoJsonObject {\n // validate input data\n if (!isObject(geojson)) {\n throw new TypeError(\n `Expected provided GeoJSON to be an object, but received ${geojson === null ? 'null' : typeof geojson}.`,\n )\n }\n\n // validate options\n let tolerance = 0\n if (options.tolerance !== undefined) {\n if (!isFinitePositiveNumber(options.tolerance)) {\n throw new Error(`Expected provided tolerance to be a finite positive number, but received ${options.tolerance}.`)\n }\n tolerance = options.tolerance\n }\n let fraction = 0\n if (options.fraction !== undefined) {\n if (!isFinitePositiveNumber(options.fraction)) {\n throw new Error(`Expected provided fraction to be a finite positive number, but received ${options.fraction}.`)\n }\n if (options.fraction > 1) {\n throw new Error(`Expected provided fraction to be less or equal to 1, but received ${options.fraction}.`)\n }\n fraction = options.fraction\n }\n let mutate = true\n if (options.mutate !== undefined) {\n mutate = !!options.mutate\n }\n\n // exit if no simplification options provided\n if (tolerance === 0 && fraction === 0) {\n return geojson\n }\n\n if (!mutate) {\n geojson = structuredClone(geojson)\n }\n\n const positions: Positions = {\n coordinates: [],\n nextIndexes: [],\n prevIndexes: [],\n }\n collectPositions(geojson, positions)\n\n if (positions.coordinates.length) {\n updatePositions(geojson, deletePositions(positions, groupPositions(positions.coordinates), tolerance, fraction), 0)\n }\n\n return geojson\n}\n\nfunction getPositionArea(i: number, positions: Positions): number {\n return (\n Math.abs(\n positions.coordinates[i][0] *\n (positions.coordinates[positions.prevIndexes[i]][1] - positions.coordinates[positions.nextIndexes[i]][1]) +\n positions.coordinates[positions.prevIndexes[i]][0] *\n (positions.coordinates[positions.nextIndexes[i]][1] - positions.coordinates[i][1]) +\n positions.coordinates[positions.nextIndexes[i]][0] *\n (positions.coordinates[i][1] - positions.coordinates[positions.prevIndexes[i]][1]),\n ) / 2\n )\n}\n\nfunction heapcompare(a: number, b: number, priority: Float64Array, coordinates: Position[]): number {\n return priority[a] - priority[b] || coordinates[a][0] - coordinates[b][0] || coordinates[a][1] - coordinates[b][1]\n}\n\nfunction heapsink(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n let l: number, r: number, t: number\n while (true) {\n t = i\n if ((l = i << 1) <= heap[0] && heapcompare(heap[t], heap[l], priority, coordinates) > 0) t = l\n if ((r = l + 1) <= heap[0] && heapcompare(heap[t], heap[r], priority, coordinates) > 0) t = r\n if (i === t) break\n heapswap(heap, heapRev, i, t)\n i = t\n }\n return i\n}\n\nfunction heapbubble(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n let t: number\n while (i > 1) {\n t = i >>> 1\n if (i === t || heapcompare(heap[t], heap[i], priority, coordinates) <= 0) break\n heapswap(heap, heapRev, i, t)\n i = t\n }\n return i\n}\n\nfunction heapupdate(\n heap: Uint32Array,\n heapRev: Uint32Array,\n val: number,\n priority: Float64Array,\n coordinates: Position[],\n): void {\n heapbubble(heap, heapRev, heapsink(heap, heapRev, heapRev[val], priority, coordinates), priority, coordinates)\n}\n\nfunction heapswap(heap: Uint32Array, heapRev: Uint32Array, i: number, t: number): void {\n heapRev[heap[i]] = t\n heapRev[heap[t]] = i\n ;[heap[i], heap[t]] = [heap[t], heap[i]]\n}\n\nfunction heappop(heap: Uint32Array, heapRev: Uint32Array, priority: Float64Array, coordinates: Position[]): number {\n if (heap[0] > 1) {\n heapswap(heap, heapRev, 1, heap[0])\n heap[0]--\n heapsink(heap, heapRev, 1, priority, coordinates)\n return heap[heap[0] + 1]\n } else if (heap[0] === 1) {\n heap[0]--\n return heap[1]\n }\n return -1\n}\n\nfunction heapify(heap: Uint32Array, heapRev: Uint32Array, priority: Float64Array, coordinates: Position[]): void {\n for (let i = heap[0] >>> 1; i > 0; i--) {\n heapsink(heap, heapRev, i, priority, coordinates)\n }\n}\n\nfunction deletePositions(positions: Positions, groups: Groups, tolerance: number, fraction: number): Uint8Array {\n const n = positions.coordinates.length\n\n const isDeleted = new Uint8Array(n)\n let toDelete = Math.round(n * fraction)\n\n const candidatesByGroupFrom = new Uint32Array(n)\n const isCandidate = new Uint8Array(n)\n\n const heap = new Uint32Array(n + 1)\n const priority = new Float64Array(n)\n const heapRev = new Uint32Array(n)\n\n for (let i = 0; i < n; i++) {\n if (positions.prevIndexes[i] !== -1 && positions.nextIndexes[i] !== -1) {\n priority[i] = getPositionArea(i, positions)\n heap[0]++\n heap[heap[0]] = i\n heapRev[i] = heap[0]\n }\n }\n heapify(heap, heapRev, priority, positions.coordinates)\n\n let i: number\n while (heap[0]) {\n i = heappop(heap, heapRev, priority, positions.coordinates)\n\n // check if position should be skipped\n if (isDeleted[i]) {\n continue\n }\n\n // check if simplification is completed\n if (priority[i] >= tolerance && toDelete <= 0) {\n break\n }\n\n // mark as candidate\n if (!isCandidate[i]) {\n isCandidate[i] = 1\n candidatesByGroupFrom[groups.groupedFrom[i]]++\n }\n\n // check if position is grouped and group is not entirely marked\n if (candidatesByGroupFrom[groups.groupedFrom[i]] !== groups.groupedTo[i] - groups.groupedFrom[i] + 1) {\n continue\n }\n\n // delete all positions from group\n // possible bug: in ring with two idetical positions (!!) test case needed\n for (let k: number, j = groups.groupedFrom[i]; j <= groups.groupedTo[i]; j++) {\n k = groups.sortIndexes[j]\n if (isDeleted[k]) {\n continue\n }\n\n // check if we are about to delete the entire ring or a single position\n if (\n positions.prevIndexes[k] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[k]] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[positions.prevIndexes[k]]] === k\n ) {\n // mark neighbors as candidates if not yet\n if (!isCandidate[positions.prevIndexes[k]]) {\n isCandidate[positions.prevIndexes[k]] = 1\n candidatesByGroupFrom[groups.groupedFrom[positions.prevIndexes[k]]]++\n }\n if (!isCandidate[positions.nextIndexes[k]]) {\n isCandidate[positions.nextIndexes[k]] = 1\n candidatesByGroupFrom[groups.groupedFrom[positions.nextIndexes[k]]]++\n }\n\n // remove entire ring if neighbor groups are entirely marked\n if (\n candidatesByGroupFrom[groups.groupedFrom[positions.prevIndexes[k]]] ===\n groups.groupedTo[positions.prevIndexes[k]] - groups.groupedFrom[positions.prevIndexes[k]] + 1 &&\n candidatesByGroupFrom[groups.groupedFrom[positions.nextIndexes[k]]] ===\n groups.groupedTo[positions.nextIndexes[k]] - groups.groupedFrom[positions.nextIndexes[k]] + 1\n ) {\n isDeleted[k] = 1\n isDeleted[positions.nextIndexes[k]] = 1\n isDeleted[positions.prevIndexes[k]] = 1\n toDelete -= 3\n\n // repeat to delete all matching rings\n // possible optimization\n j = groups.groupedFrom[i] - 1\n }\n } else {\n isDeleted[k] = 1\n toDelete--\n positions.prevIndexes[positions.nextIndexes[k]] = positions.prevIndexes[k]\n positions.nextIndexes[positions.prevIndexes[k]] = positions.nextIndexes[k]\n\n // update neighbors priority and their positions in the heap\n if (positions.prevIndexes[positions.prevIndexes[k]] !== -1) {\n priority[positions.prevIndexes[k]] = getPositionArea(positions.prevIndexes[k], positions)\n heapupdate(heap, heapRev, positions.prevIndexes[k], priority, positions.coordinates)\n }\n if (positions.nextIndexes[positions.nextIndexes[k]] !== -1) {\n priority[positions.nextIndexes[k]] = getPositionArea(positions.nextIndexes[k], positions)\n heapupdate(heap, heapRev, positions.nextIndexes[k], priority, positions.coordinates)\n }\n }\n }\n }\n return isDeleted\n}\n\nfunction updatePositions(geojson: GeoJsonObject, isDeleted: Uint8Array, index: number): number {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n index = updatePositions(geojson.features[i], isDeleted, index)\n }\n } else if (isFeature(geojson)) {\n index = updatePositions(geojson.geometry, isDeleted, index)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n index = updatePositions(geojson.geometries[i], isDeleted, index)\n }\n } else if (isLineString(geojson)) {\n index = updateLinePositions(geojson.coordinates, isDeleted, index)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n index = updateLinePositions(geojson.coordinates[i], isDeleted, index)\n }\n } else if (isPolygon(geojson)) {\n let remove = false\n ;[index, remove] = updateRingsPositions(geojson.coordinates, isDeleted, index)\n if (remove) geojson.coordinates.splice(0)\n } else if (isMultiPolygon(geojson)) {\n let offset = 0\n for (let remove = false, i = 0; i < geojson.coordinates.length; i++) {\n ;[index, remove] = updateRingsPositions(geojson.coordinates[i], isDeleted, index)\n if (remove) {\n offset++\n } else if (offset) {\n geojson.coordinates[i - offset] = geojson.coordinates[i]\n }\n }\n if (offset) geojson.coordinates.splice(geojson.coordinates.length - offset)\n }\n return index\n}\n\nfunction updateLinePositions(coordinates: Position[], isDeleted: Uint8Array, index: number): number {\n let offset = 0\n for (let i = 0; i < coordinates.length; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return index\n}\n\nfunction updateRingsPositions(coordinates: Position[][], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let remove = false, i = 0; i < coordinates.length; i++) {\n ;[index, remove] = updateRingPositions(coordinates[i], isDeleted, index)\n if (remove) {\n // skip interior rings if exterior ring is removed\n if (i === 0) {\n for (i = 1; i < coordinates.length; i++) {\n if (coordinates[i].length) index += coordinates[i].length - 1\n }\n // avoid alternating coordinates array if exterior ring is removed\n return [index, true]\n }\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return [index, false]\n}\n\nfunction updateRingPositions(coordinates: Position[], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let i = 0; i < coordinates.length - 1; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) {\n if (coordinates.length - 1 - offset < 3) {\n // avoid alternating coordinates array if ring is removed\n return [index, true]\n }\n coordinates.splice(coordinates.length - 1 - offset, offset + 1, coordinates[0])\n }\n return [index, false]\n}\n\nfunction collectPositions(geojson: GeoJsonObject, positions: Positions): void {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n collectPositions(geojson.features[i], positions)\n }\n } else if (isFeature(geojson)) {\n collectPositions(geojson.geometry, positions)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n collectPositions(geojson.geometries[i], positions)\n }\n } else if (isLineString(geojson)) {\n collectLinePositions(geojson.coordinates, positions)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectLinePositions(geojson.coordinates[i], positions)\n }\n } else if (isPolygon(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectRingPositions(geojson.coordinates[i], positions)\n }\n } else if (isMultiPolygon(geojson)) {\n for (let j, i = 0; i < geojson.coordinates.length; i++) {\n for (j = 0; j < geojson.coordinates[i].length; j++) {\n collectRingPositions(geojson.coordinates[i][j], positions)\n }\n }\n }\n}\n\nfunction collectLinePositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? -1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? -1 : p + i + 1)\n }\n}\n\nfunction collectRingPositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length - 1, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? p + n - 1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? p : p + i + 1)\n }\n}\n"],"mappings":"AAaO,SAASA,EAAuBC,EAA8C,CACnF,OAAOA,GAAS,MAAQ,OAAO,SAASA,CAAK,GAAKA,EAAQ,CAC5D,CAEO,SAASC,EAASD,EAAgC,CACvD,OAAO,OAAOA,GAAU,UAAYA,IAAU,IAChD,CAEO,SAASE,EAAUF,EAAwC,CAChE,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,SAC5C,CAEO,SAASG,EAAoBH,EAAkD,CACpF,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,mBAC5C,CAEO,SAASI,EAAaJ,EAA2C,CACtE,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,YAC5C,CAEO,SAASK,EAAkBL,EAAgD,CAChF,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,iBAC5C,CAEO,SAASM,EAAUN,EAAwC,CAChE,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,SAC5C,CAEO,SAASO,EAAeP,EAA6C,CAC1E,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,cAC5C,CAEO,SAASQ,EAAqBR,EAAmD,CACtF,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,oBAC5C,CCvCO,SAASS,EAAeC,EAAiC,CAC9D,IAAMC,EAAc,IAAI,YAAYD,EAAY,MAAM,EAChDE,EAAc,IAAI,YAAYF,EAAY,MAAM,EACh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AS,EAAGL,EAAI,EAAGA,EAAI,EAAGA,IACnFN,EAAU,YAAY,KAAKW,EAAYL,CAAC,CAAC,EACzCN,EAAU,YAAY,KAAKM,IAAM,EAAIyC,EAAI,EAAI,EAAIA,EAAIzC,EAAI,CAAC,EAC1DN,EAAU,YAAY,KAAKM,IAAM,EAAI,EAAIyC,EAAIA,EAAIzC,EAAI,CAAC,CAE1D","names":["isFinitePositiveNumber","value","isObject","isFeature","isFeatureCollection","isLineString","isMultiLineString","isPolygon","isMultiPolygon","isGeometryCollection","groupPositions","coordinates","sortIndexes","groupedFrom","groupedTo","i","a","b","j","index_default","geojson","options","isObject","tolerance","isFinitePositiveNumber","fraction","mutate","positions","collectPositions","updatePositions","deletePositions","groupPositions","getPositionArea","i","heapcompare","a","b","priority","coordinates","heapsink","heap","heapRev","l","r","t","heapswap","heapbubble","heapupdate","val","heappop","heapify","groups","n","isDeleted","toDelete","candidatesByGroupFrom","isCandidate","k","j","index","isFeatureCollection","isFeature","isGeometryCollection","isLineString","updateLinePositions","isMultiLineString","isPolygon","remove","updateRingsPositions","isMultiPolygon","offset","updateRingPositions","collectLinePositions","collectRingPositions","p"]}
1
+ {"version":3,"sources":["../src/lib/typeGuards.ts","../src/lib/functions.ts","../src/index.ts"],"sourcesContent":["import {\n GeoJsonObject,\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon,\n GeometryCollection,\n} from 'geojson'\n\nexport type FinitePositiveNumber = number & { readonly __type: unique symbol }\n\nexport function isFinitePositiveNumber(value: number): value is FinitePositiveNumber {\n return value != null && Number.isFinite(value) && value > 0\n}\n\nexport function isObject(value: object): value is object {\n return typeof value === 'object' && value !== null\n}\n\nexport function isFeature(value: GeoJsonObject): value is Feature {\n return isObject(value) && value?.type === 'Feature'\n}\n\nexport function isFeatureCollection(value: GeoJsonObject): value is FeatureCollection {\n return isObject(value) && value?.type === 'FeatureCollection'\n}\n\nexport function isLineString(value: GeoJsonObject): value is LineString {\n return isObject(value) && value?.type === 'LineString'\n}\n\nexport function isMultiLineString(value: GeoJsonObject): value is MultiLineString {\n return isObject(value) && value?.type === 'MultiLineString'\n}\n\nexport function isPolygon(value: GeoJsonObject): value is Polygon {\n return isObject(value) && value?.type === 'Polygon'\n}\n\nexport function isMultiPolygon(value: GeoJsonObject): value is MultiPolygon {\n return isObject(value) && value?.type === 'MultiPolygon'\n}\n\nexport function isGeometryCollection(value: GeoJsonObject): value is GeometryCollection {\n return isObject(value) && value?.type === 'GeometryCollection'\n}\n","import { Position } from 'geojson'\n\nexport type Positions = {\n coordinates: Position[]\n nextIndexes: number[]\n prevIndexes: number[]\n}\n\nexport type Groups = {\n sortIndexes: Uint32Array\n groupedFrom: Uint32Array\n groupedTo: Uint32Array\n}\n\nexport function groupPositions(coordinates: Position[]): Groups {\n const sortIndexes = new Uint32Array(coordinates.length)\n const groupedFrom = new Uint32Array(coordinates.length)\n const groupedTo = new Uint32Array(coordinates.length)\n for (let i = 0; i < coordinates.length; i++) {\n sortIndexes[i] = i\n }\n sortIndexes.sort((a, b) => {\n const deltaX = coordinates[a][0] - coordinates[b][0]\n if (deltaX) {\n return deltaX < 0 ? -1 : 1\n }\n const deltaY = coordinates[a][1] - coordinates[b][1]\n return deltaY < 0 ? -1 : deltaY > 0 ? 1 : 0\n })\n if (coordinates.length) {\n groupedTo[sortIndexes[coordinates.length - 1]] = groupedTo.length - 1\n }\n for (let i = 1, j = coordinates.length - 2; i < coordinates.length; i++, j--) {\n if (\n coordinates[sortIndexes[i]][0] !== coordinates[sortIndexes[i - 1]][0] ||\n coordinates[sortIndexes[i]][1] !== coordinates[sortIndexes[i - 1]][1]\n ) {\n groupedFrom[sortIndexes[i]] = i\n } else {\n groupedFrom[sortIndexes[i]] = groupedFrom[sortIndexes[i - 1]]\n }\n if (\n coordinates[sortIndexes[j]][0] !== coordinates[sortIndexes[j + 1]][0] ||\n coordinates[sortIndexes[j]][1] !== coordinates[sortIndexes[j + 1]][1]\n ) {\n groupedTo[sortIndexes[j]] = j\n } else {\n groupedTo[sortIndexes[j]] = groupedTo[sortIndexes[j + 1]]\n }\n }\n return {\n sortIndexes,\n groupedFrom,\n groupedTo,\n }\n}\n\nfunction getPositionArea(i: number, positions: Positions): number {\n return (\n Math.abs(\n positions.coordinates[i][0] *\n (positions.coordinates[positions.prevIndexes[i]][1] - positions.coordinates[positions.nextIndexes[i]][1]) +\n positions.coordinates[positions.prevIndexes[i]][0] *\n (positions.coordinates[positions.nextIndexes[i]][1] - positions.coordinates[i][1]) +\n positions.coordinates[positions.nextIndexes[i]][0] *\n (positions.coordinates[i][1] - positions.coordinates[positions.prevIndexes[i]][1]),\n ) / 2\n )\n}\n\nfunction heapcompare(a: number, b: number, priority: Float64Array, coordinates: Position[]): number {\n return priority[a] - priority[b] || coordinates[a][0] - coordinates[b][0] || coordinates[a][1] - coordinates[b][1]\n}\n\nfunction heapsink(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n const value = heap[i]\n let l: number, r: number, t: number\n let selected: number\n while (true) {\n t = i\n selected = value\n if ((l = i << 1) <= heap[0] && heapcompare(selected, heap[l], priority, coordinates) > 0) {\n t = l\n selected = heap[l]\n }\n if ((r = l + 1) <= heap[0] && heapcompare(selected, heap[r], priority, coordinates) > 0) t = r\n if (i === t) break\n heap[i] = heap[t]\n heapRev[heap[i]] = i\n i = t\n }\n heap[i] = value\n heapRev[value] = i\n return i\n}\n\nfunction heapbubble(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n let t: number\n while (i > 1) {\n t = i >>> 1\n if (i === t || heapcompare(heap[t], heap[i], priority, coordinates) <= 0) break\n heapswap(heap, heapRev, i, t)\n i = t\n }\n return i\n}\n\nfunction heapupdate(\n heap: Uint32Array,\n heapRev: Uint32Array,\n val: number,\n priority: Float64Array,\n coordinates: Position[],\n): void {\n heapbubble(heap, heapRev, heapsink(heap, heapRev, heapRev[val], priority, coordinates), priority, coordinates)\n}\n\nfunction heapswap(heap: Uint32Array, heapRev: Uint32Array, i: number, t: number): void {\n heapRev[heap[i]] = t\n heapRev[heap[t]] = i\n ;[heap[i], heap[t]] = [heap[t], heap[i]]\n}\n\nfunction heappop(heap: Uint32Array, heapRev: Uint32Array, priority: Float64Array, coordinates: Position[]): number {\n if (heap[0] > 1) {\n heapswap(heap, heapRev, 1, heap[0])\n heap[0]--\n heapsink(heap, heapRev, 1, priority, coordinates)\n return heap[heap[0] + 1]\n } else if (heap[0] === 1) {\n heap[0]--\n return heap[1]\n }\n return -1\n}\n\nfunction heapify(heap: Uint32Array, heapRev: Uint32Array, priority: Float64Array, coordinates: Position[]): void {\n for (let i = heap[0] >>> 1; i > 0; i--) {\n heapsink(heap, heapRev, i, priority, coordinates)\n }\n}\n\nexport function deletePositions(positions: Positions, groups: Groups, tolerance: number, fraction: number): Uint8Array {\n const n = positions.coordinates.length\n\n const isDeleted = new Uint8Array(n)\n let toDelete = Math.round(n * fraction)\n\n const candidatesByGroupFrom = new Uint32Array(n)\n const isCandidate = new Uint8Array(n)\n\n const heap = new Uint32Array(n + 1)\n const priority = new Float64Array(n)\n const heapRev = new Uint32Array(n)\n\n for (let i = 0; i < n; i++) {\n if (positions.prevIndexes[i] !== -1 && positions.nextIndexes[i] !== -1) {\n priority[i] = getPositionArea(i, positions)\n heap[0]++\n heap[heap[0]] = i\n heapRev[i] = heap[0]\n }\n }\n heapify(heap, heapRev, priority, positions.coordinates)\n\n let i: number\n while (heap[0]) {\n i = heappop(heap, heapRev, priority, positions.coordinates)\n\n if (isDeleted[i]) {\n continue\n }\n\n if (priority[i] >= tolerance && toDelete <= 0) {\n break\n }\n\n if (!isCandidate[i]) {\n isCandidate[i] = 1\n candidatesByGroupFrom[groups.groupedFrom[i]]++\n }\n\n if (candidatesByGroupFrom[groups.groupedFrom[i]] !== groups.groupedTo[i] - groups.groupedFrom[i] + 1) {\n continue\n }\n\n for (let k: number, j = groups.groupedFrom[i]; j <= groups.groupedTo[i]; j++) {\n k = groups.sortIndexes[j]\n if (isDeleted[k]) {\n continue\n }\n\n if (\n positions.prevIndexes[k] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[k]] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[positions.prevIndexes[k]]] === k\n ) {\n if (!isCandidate[positions.prevIndexes[k]]) {\n isCandidate[positions.prevIndexes[k]] = 1\n candidatesByGroupFrom[groups.groupedFrom[positions.prevIndexes[k]]]++\n }\n if (!isCandidate[positions.nextIndexes[k]]) {\n isCandidate[positions.nextIndexes[k]] = 1\n candidatesByGroupFrom[groups.groupedFrom[positions.nextIndexes[k]]]++\n }\n\n if (\n candidatesByGroupFrom[groups.groupedFrom[positions.prevIndexes[k]]] ===\n groups.groupedTo[positions.prevIndexes[k]] - groups.groupedFrom[positions.prevIndexes[k]] + 1 &&\n candidatesByGroupFrom[groups.groupedFrom[positions.nextIndexes[k]]] ===\n groups.groupedTo[positions.nextIndexes[k]] - groups.groupedFrom[positions.nextIndexes[k]] + 1\n ) {\n isDeleted[k] = 1\n isDeleted[positions.nextIndexes[k]] = 1\n isDeleted[positions.prevIndexes[k]] = 1\n toDelete -= 3\n j = groups.groupedFrom[i] - 1\n }\n } else {\n isDeleted[k] = 1\n toDelete--\n positions.prevIndexes[positions.nextIndexes[k]] = positions.prevIndexes[k]\n positions.nextIndexes[positions.prevIndexes[k]] = positions.nextIndexes[k]\n\n if (positions.prevIndexes[positions.prevIndexes[k]] !== -1) {\n priority[positions.prevIndexes[k]] = getPositionArea(positions.prevIndexes[k], positions)\n heapupdate(heap, heapRev, positions.prevIndexes[k], priority, positions.coordinates)\n }\n if (positions.nextIndexes[positions.nextIndexes[k]] !== -1) {\n priority[positions.nextIndexes[k]] = getPositionArea(positions.nextIndexes[k], positions)\n heapupdate(heap, heapRev, positions.nextIndexes[k], priority, positions.coordinates)\n }\n }\n }\n }\n return isDeleted\n}\n","import { GeoJsonObject, Position } from 'geojson'\nimport {\n isObject,\n isFinitePositiveNumber,\n isFeature,\n isFeatureCollection,\n isLineString,\n isMultiLineString,\n isPolygon,\n isMultiPolygon,\n isGeometryCollection,\n} from '@lib/typeGuards'\nimport { deletePositions, groupPositions, type Positions } from '@lib/functions'\n\nexport type SimplifyOptions = {\n tolerance?: number\n fraction?: number\n mutate?: boolean\n}\n\nexport default function (geojson: GeoJsonObject, options: SimplifyOptions = {}): GeoJsonObject {\n // validate input data\n if (!isObject(geojson)) {\n throw new TypeError(\n `Expected provided GeoJSON to be an object, but received ${geojson === null ? 'null' : typeof geojson}.`,\n )\n }\n\n // validate options\n let tolerance = 0\n if (options.tolerance !== undefined) {\n if (!isFinitePositiveNumber(options.tolerance)) {\n throw new Error(`Expected provided tolerance to be a finite positive number, but received ${options.tolerance}.`)\n }\n tolerance = options.tolerance\n }\n let fraction = 0\n if (options.fraction !== undefined) {\n if (!isFinitePositiveNumber(options.fraction)) {\n throw new Error(`Expected provided fraction to be a finite positive number, but received ${options.fraction}.`)\n }\n if (options.fraction > 1) {\n throw new Error(`Expected provided fraction to be less or equal to 1, but received ${options.fraction}.`)\n }\n fraction = options.fraction\n }\n let mutate = true\n if (options.mutate !== undefined) {\n mutate = !!options.mutate\n }\n\n // exit if no simplification options provided\n if (tolerance === 0 && fraction === 0) {\n return geojson\n }\n\n if (!mutate) {\n geojson = structuredClone(geojson)\n }\n\n const positions: Positions = {\n coordinates: [],\n nextIndexes: [],\n prevIndexes: [],\n }\n collectPositions(geojson, positions)\n\n if (positions.coordinates.length) {\n updatePositions(geojson, deletePositions(positions, groupPositions(positions.coordinates), tolerance, fraction), 0)\n }\n\n return geojson\n}\nfunction updatePositions(geojson: GeoJsonObject, isDeleted: Uint8Array, index: number): number {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n index = updatePositions(geojson.features[i], isDeleted, index)\n }\n } else if (isFeature(geojson)) {\n index = updatePositions(geojson.geometry, isDeleted, index)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n index = updatePositions(geojson.geometries[i], isDeleted, index)\n }\n } else if (isLineString(geojson)) {\n index = updateLinePositions(geojson.coordinates, isDeleted, index)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n index = updateLinePositions(geojson.coordinates[i], isDeleted, index)\n }\n } else if (isPolygon(geojson)) {\n let remove = false\n ;[index, remove] = updateRingsPositions(geojson.coordinates, isDeleted, index)\n if (remove) geojson.coordinates.splice(0)\n } else if (isMultiPolygon(geojson)) {\n let offset = 0\n for (let remove = false, i = 0; i < geojson.coordinates.length; i++) {\n ;[index, remove] = updateRingsPositions(geojson.coordinates[i], isDeleted, index)\n if (remove) {\n offset++\n } else if (offset) {\n geojson.coordinates[i - offset] = geojson.coordinates[i]\n }\n }\n if (offset) geojson.coordinates.splice(geojson.coordinates.length - offset)\n }\n return index\n}\n\nfunction updateLinePositions(coordinates: Position[], isDeleted: Uint8Array, index: number): number {\n let offset = 0\n for (let i = 0; i < coordinates.length; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return index\n}\n\nfunction updateRingsPositions(coordinates: Position[][], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let remove = false, i = 0; i < coordinates.length; i++) {\n ;[index, remove] = updateRingPositions(coordinates[i], isDeleted, index)\n if (remove) {\n // skip interior rings if exterior ring is removed\n if (i === 0) {\n for (i = 1; i < coordinates.length; i++) {\n if (coordinates[i].length) index += coordinates[i].length - 1\n }\n // avoid alternating coordinates array if exterior ring is removed\n return [index, true]\n }\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return [index, false]\n}\n\nfunction updateRingPositions(coordinates: Position[], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let i = 0; i < coordinates.length - 1; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) {\n if (coordinates.length - 1 - offset < 3) {\n // avoid alternating coordinates array if ring is removed\n return [index, true]\n }\n coordinates.splice(coordinates.length - 1 - offset, offset + 1, coordinates[0])\n }\n return [index, false]\n}\n\nfunction collectPositions(geojson: GeoJsonObject, positions: Positions): void {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n collectPositions(geojson.features[i], positions)\n }\n } else if (isFeature(geojson)) {\n collectPositions(geojson.geometry, positions)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n collectPositions(geojson.geometries[i], positions)\n }\n } else if (isLineString(geojson)) {\n collectLinePositions(geojson.coordinates, positions)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectLinePositions(geojson.coordinates[i], positions)\n }\n } else if (isPolygon(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectRingPositions(geojson.coordinates[i], positions)\n }\n } else if (isMultiPolygon(geojson)) {\n for (let j, i = 0; i < geojson.coordinates.length; i++) {\n for (j = 0; j < geojson.coordinates[i].length; j++) {\n collectRingPositions(geojson.coordinates[i][j], positions)\n }\n }\n }\n}\n\nfunction collectLinePositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? -1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? -1 : p + i + 1)\n }\n}\n\nfunction collectRingPositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length - 1, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? p + n - 1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? p : p + i + 1)\n }\n}\n"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DR,EAAU,YAAY,KAAKQ,IAAM,EAAI,EAAIgB,EAAIA,EAAIhB,EAAI,CAAC,CAE1D","names":["isFinitePositiveNumber","value","isObject","isFeature","isFeatureCollection","isLineString","isMultiLineString","isPolygon","isMultiPolygon","isGeometryCollection","groupPositions","coordinates","sortIndexes","groupedFrom","groupedTo","i","a","b","deltaX","deltaY","j","getPositionArea","positions","heapcompare","priority","heapsink","heap","heapRev","value","l","r","t","selected","heapbubble","heapswap","heapupdate","val","heappop","heapify","deletePositions","groups","tolerance","fraction","n","isDeleted","toDelete","candidatesByGroupFrom","isCandidate","k","index_default","geojson","options","isObject","tolerance","isFinitePositiveNumber","fraction","mutate","positions","collectPositions","updatePositions","deletePositions","groupPositions","isDeleted","index","isFeatureCollection","i","isFeature","isGeometryCollection","isLineString","updateLinePositions","isMultiLineString","isPolygon","remove","updateRingsPositions","isMultiPolygon","offset","coordinates","updateRingPositions","collectLinePositions","collectRingPositions","j","p"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplify-geojson-visvalingam",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "GeoJSON simplification library using the Visvalingam algorithm for efficient point reduction and geometry preservation.",
5
5
  "author": "Alexander Kolobov",
6
6
  "license": "MIT",
@@ -45,7 +45,11 @@
45
45
  "lint:fix": "eslint . --fix",
46
46
  "format": "prettier '**/*.{ts,js,json}' --ignore-path .prettierignore --write",
47
47
  "build": "npm run lint && npm run typecheck && npm run test && tsup",
48
- "playground": "npx tsx watch playground/index.ts"
48
+ "playground": "npx tsx watch playground/index.ts",
49
+ "bench:prepare": "tsup && tsup --config bench/tsup.config.ts",
50
+ "bench": "npm run bench:prepare && node .bench-build/run.js",
51
+ "bench:memory": "npm run bench:prepare && node .bench-build/run.js --mode memory",
52
+ "bench:compare": "node --import tsx bench/compare.ts"
49
53
  },
50
54
  "repository": {
51
55
  "type": "git",
@@ -55,11 +59,13 @@
55
59
  "@types/assert": "^1.5.11",
56
60
  "@types/geojson": "^7946.0.16",
57
61
  "@types/mocha": "^10.0.10",
62
+ "@types/node": "^24.19.1",
58
63
  "eslint": "^9.25.0",
59
64
  "eslint-config-prettier": "^10.1.2",
60
65
  "eslint-plugin-prettier": "^5.2.6",
61
66
  "mocha": "^11.1.0",
62
67
  "prettier": "3.5.3",
68
+ "tinybench": "^6.2.0",
63
69
  "tsup": "^8.4.0",
64
70
  "tsx": "^4.19.3",
65
71
  "typescript": "^5.8.3",