simplify-geojson-visvalingam 1.2.1 → 1.2.3

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/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var P=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var h=(e,t)=>{for(var r in t)P(e,r,{get:t[r],enumerable:!0})},_=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of k(t))!E.call(e,u)&&u!==r&&P(e,u,{get:()=>t[u],enumerable:!(n=N(t,u))||n.enumerable});return e};var $=e=>_(P({},"__esModule",{value:!0}),e);var V={};h(V,{default:()=>q});module.exports=$(V);function J(e){return e!=null&&Number.isFinite(e)&&e>0}function m(e){return typeof e=="object"&&e!==null}function v(e){return m(e)&&e?.type==="Feature"}function g(e){return m(e)&&e?.type==="FeatureCollection"}function F(e){return m(e)&&e?.type==="LineString"}function A(e){return m(e)&&e?.type==="MultiLineString"}function U(e){return m(e)&&e?.type==="Polygon"}function o(e){return m(e)&&e?.type==="MultiPolygon"}function G(e){return m(e)&&e?.type==="GeometryCollection"}function q(e,t={}){if(!m(e))throw new TypeError(`Expected provided GeoJSON to be an object, but received ${e===null?"null":typeof e}.`);let r;if(t.tolerance===void 0||!J(t.tolerance))throw new Error(`Expected provided tolerance to be a finite positive number, but received ${t.tolerance}.`);r=t.tolerance;let n=!0;t.mutate!==void 0&&(n=!!t.mutate),n||(e=structuredClone(e));let u={coordinates:[],nextIndexes:[],prevIndexes:[],sortIndexes:[],groupedFrom:[],groupedTo:[]};if(y(e,u),u.coordinates.length){B(u);let l=new Uint8Array(u.coordinates.length);Q(u,r,l),a(e,l,0)}return e}function B(e){e.sortIndexes=[...new Array(e.coordinates.length).keys()],e.sortIndexes.sort((t,r)=>e.coordinates[t][0]-e.coordinates[r][0]||e.coordinates[t][1]-e.coordinates[r][1]),e.groupedFrom=new Array(e.coordinates.length).fill(0),e.groupedTo=new Array(e.coordinates.length).fill(e.sortIndexes.length-1);for(let t=1,r=e.sortIndexes.length-2;t<e.sortIndexes.length;t++,r--)e.coordinates[e.sortIndexes[t]][0]!==e.coordinates[e.sortIndexes[t-1]][0]||e.coordinates[e.sortIndexes[t]][1]!==e.coordinates[e.sortIndexes[t-1]][1]?e.groupedFrom[e.sortIndexes[t]]=t:e.groupedFrom[e.sortIndexes[t]]=e.groupedFrom[e.sortIndexes[t-1]],e.coordinates[e.sortIndexes[r]][0]!==e.coordinates[e.sortIndexes[r+1]][0]||e.coordinates[e.sortIndexes[r]][1]!==e.coordinates[e.sortIndexes[r+1]][1]?e.groupedTo[e.sortIndexes[r]]=r:e.groupedTo[e.sortIndexes[r]]=e.groupedTo[e.sortIndexes[r+1]]}function i(e,t){return Math.abs(t.coordinates[e][0]*(t.coordinates[t.prevIndexes[e]][1]-t.coordinates[t.nextIndexes[e]][1])+t.coordinates[t.prevIndexes[e]][0]*(t.coordinates[t.nextIndexes[e]][1]-t.coordinates[e][1])+t.coordinates[t.nextIndexes[e]][0]*(t.coordinates[e][1]-t.coordinates[t.prevIndexes[e]][1]))/2}function O(e,t,r,n,u){let l,c,d;for(;l=r<<1,c=l+1,d=r,l<=e[0]&&(n[e[d]]>n[e[l]]||n[e[d]]===n[e[l]]&&(u[e[d]][0]>u[e[l]][0]||u[e[d]][0]===u[e[l]][0]&&u[e[d]][1]>u[e[l]][1]))&&(d=l),c<=e[0]&&(n[e[d]]>n[e[c]]||n[e[d]]===n[e[c]]&&(u[e[d]][0]>u[e[c]][0]||u[e[d]][0]===u[e[c]][0]&&u[e[d]][1]>u[e[c]][1]))&&(d=c),r!==d;)w(e,t,r,d),r=d;return r}function z(e,t,r,n,u){let l;for(;r>1&&(l=r>>>1,!(r===l||n[e[l]]<n[e[r]]||n[e[l]]===n[e[r]]&&(u[e[l]][0]<u[e[r]][0]||u[e[l]][0]===u[e[r]][0]&&u[e[l]][1]<u[e[r]][1])));)w(e,t,r,l),r=l;return r}function S(e,t,r,n,u){z(e,t,O(e,t,t[r],n,u),n,u)}function w(e,t,r,n){t[e[r]]=n,t[e[n]]=r,[e[r],e[n]]=[e[n],e[r]]}function H(e,t,r,n){return e[0]>1?(w(e,t,1,e[0]),e[0]--,O(e,t,1,r,n),e[e[0]+1]):e[0]===1?(e[0]--,e[1]):-1}function K(e,t,r,n){for(let u=e[0]>>>1;u>0;u--)O(e,t,u,r,n)}function Q(e,t,r){let n=e.coordinates.length,u=new Uint32Array(n),l=new Uint8Array(n),c=new Uint32Array(n+1),d=new Float64Array(n),b=new Uint32Array(n);for(let f=0;f<n;f++)e.prevIndexes[f]!==-1&&e.nextIndexes[f]!==-1&&(d[f]=i(f,e),c[0]++,c[c[0]]=f,b[f]=c[0]);K(c,b,d,e.coordinates);let x;for(;c[0];)if(x=H(c,b,d,e.coordinates),!r[x]){if(d[x]>=t)break;if(l[x]||(l[x]=1,u[e.groupedFrom[x]]++),u[e.groupedFrom[x]]===e.groupedTo[x]-e.groupedFrom[x]+1)for(let f,I=e.groupedFrom[x];I<=e.groupedTo[x];I++)f=e.sortIndexes[I],!r[f]&&(e.prevIndexes[f]!==-1&&e.prevIndexes[e.prevIndexes[f]]!==-1&&e.prevIndexes[e.prevIndexes[e.prevIndexes[f]]]===f?(l[e.prevIndexes[f]]||(l[e.prevIndexes[f]]=1,u[e.groupedFrom[e.prevIndexes[f]]]++),l[e.nextIndexes[f]]||(l[e.nextIndexes[f]]=1,u[e.groupedFrom[e.nextIndexes[f]]]++),u[e.groupedFrom[e.prevIndexes[f]]]===e.groupedTo[e.prevIndexes[f]]-e.groupedFrom[e.prevIndexes[f]]+1&&u[e.groupedFrom[e.nextIndexes[f]]]===e.groupedTo[e.nextIndexes[f]]-e.groupedFrom[e.nextIndexes[f]]+1&&(r[f]=1,r[e.nextIndexes[f]]=1,r[e.prevIndexes[f]]=1,I=e.groupedFrom[x]-1)):(r[f]=1,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]]=i(e.prevIndexes[f],e),S(c,b,e.prevIndexes[f],d,e.coordinates)),e.nextIndexes[e.nextIndexes[f]]!==-1&&(d[e.nextIndexes[f]]=i(e.nextIndexes[f],e),S(c,b,e.nextIndexes[f],d,e.coordinates))))}}function a(e,t,r){if(g(e))for(let n=0;n<e.features.length;n++)r=a(e.features[n],t,r);else if(v(e))r=a(e.geometry,t,r);else if(G(e))for(let n=0;n<e.geometries.length;n++)r=a(e.geometries[n],t,r);else if(F(e))r=C(e.coordinates,t,r);else if(A(e))for(let n=0;n<e.coordinates.length;n++)r=C(e.coordinates[n],t,r);else if(U(e)){let n=!1;[r,n]=L(e.coordinates,t,r),n&&e.coordinates.splice(0)}else if(o(e)){let n=0;for(let u=!1,l=0;l<e.coordinates.length;l++)[r,u]=L(e.coordinates[l],t,r),u?n++:n&&(e.coordinates[l-n]=e.coordinates[l]);n&&e.coordinates.splice(e.coordinates.length-n)}return r}function C(e,t,r){let n=0;for(let u=0;u<e.length;u++)t[r]?n++:n&&(e[u-n]=e[u]),r++;return n&&e.splice(e.length-n),r}function L(e,t,r){let n=0;for(let u=!1,l=0;l<e.length;l++)if([r,u]=R(e[l],t,r),u){if(l===0){for(l=1;l<e.length;l++)e[l].length&&(r+=e[l].length-1);return[r,!0]}n++}else n&&(e[l-n]=e[l]);return n&&e.splice(e.length-n),[r,!1]}function R(e,t,r){let n=0;for(let u=0;u<e.length-1;u++)t[r]?n++:n&&(e[u-n]=e[u]),r++;if(n){if(e.length-1-n<3)return[r,!0];e.splice(e.length-1-n,n+1,e[0])}return[r,!1]}function y(e,t){if(g(e))for(let r=0;r<e.features.length;r++)y(e.features[r],t);else if(v(e))y(e.geometry,t);else if(G(e))for(let r=0;r<e.geometries.length;r++)y(e.geometries[r],t);else if(F(e))M(e.coordinates,t);else if(A(e))for(let r=0;r<e.coordinates.length;r++)M(e.coordinates[r],t);else if(U(e))for(let r=0;r<e.coordinates.length;r++)T(e.coordinates[r],t);else if(o(e))for(let r,n=0;n<e.coordinates.length;n++)for(r=0;r<e.coordinates[n].length;r++)T(e.coordinates[n][r],t)}function M(e,t){for(let r=t.coordinates.length,n=e.length,u=0;u<n;u++)t.coordinates.push(e[u]),t.prevIndexes.push(u===0?-1:r+u-1),t.nextIndexes.push(u===n-1?-1:r+u+1)}function T(e,t){for(let r=t.coordinates.length,n=e.length-1,u=0;u<n;u++)t.coordinates.push(e[u]),t.prevIndexes.push(u===0?r+n-1:r+u-1),t.nextIndexes.push(u===n-1?r:r+u+1)}
1
+ "use strict";var I=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var p=(e,r)=>{for(var t in r)I(e,t,{get:r[t],enumerable:!0})},_=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of k(r))!E.call(e,l)&&l!==t&&I(e,l,{get:()=>r[l],enumerable:!(n=T(r,l))||n.enumerable});return e};var $=e=>_(I({},"__esModule",{value:!0}),e);var V={};p(V,{default:()=>q});module.exports=$(V);function S(e){return e!=null&&Number.isFinite(e)&&e>0}function d(e){return typeof e=="object"&&e!==null}function P(e){return d(e)&&e?.type==="Feature"}function v(e){return d(e)&&e?.type==="FeatureCollection"}function F(e){return d(e)&&e?.type==="LineString"}function A(e){return d(e)&&e?.type==="MultiLineString"}function U(e){return d(e)&&e?.type==="Polygon"}function h(e){return d(e)&&e?.type==="MultiPolygon"}function G(e){return d(e)&&e?.type==="GeometryCollection"}function q(e,r={}){if(!d(e))throw new TypeError(`Expected provided GeoJSON to be an object, but received ${e===null?"null":typeof e}.`);let t;if(r.tolerance!==void 0&&!S(r.tolerance))throw new Error(`Expected provided tolerance to be a finite positive number, but received ${r.tolerance}.`);if(r.tolerance===void 0)return e;t=r.tolerance;let n=!0;r.mutate!==void 0&&(n=!!r.mutate),n||(e=structuredClone(e));let l={coordinates:[],nextIndexes:[],prevIndexes:[]};return o(e,l),l.coordinates.length&&x(e,Q(l,B(l.coordinates),t),0),e}function B(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]),n[0]=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 g(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 O(e,r,t,n){return t[e]-t[r]||n[e][0]-n[r][0]||n[e][1]-n[r][1]}function w(e,r,t,n,l){let u,m,f;for(;f=t,(u=t<<1)<=e[0]&&O(e[f],e[u],n,l)>0&&(f=u),(m=u+1)<=e[0]&&O(e[f],e[m],n,l)>0&&(f=m),t!==f;)J(e,r,t,f),t=f;return t}function z(e,r,t,n,l){let u;for(;t>1&&(u=t>>>1,!(t===u||O(e[u],e[t],n,l)<=0));)J(e,r,t,u),t=u;return t}function s(e,r,t,n,l){z(e,r,w(e,r,r[t],n,l),n,l)}function J(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?(J(e,r,1,e[0]),e[0]--,w(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--)w(e,r,l,t,n)}function Q(e,r,t){let n=e.coordinates.length,l=new Uint8Array(n),u=new Uint32Array(n),m=new Uint8Array(n),f=new Uint32Array(n+1),a=new Float64Array(n),b=new Uint32Array(n);for(let i=0;i<n;i++)e.prevIndexes[i]!==-1&&e.nextIndexes[i]!==-1&&(a[i]=g(i,e),f[0]++,f[f[0]]=i,b[i]=f[0]);K(f,b,a,e.coordinates);let c;for(;f[0];)if(c=H(f,b,a,e.coordinates),!l[c]){if(a[c]>=t)break;if(m[c]||(m[c]=1,u[r.groupedFrom[c]]++),u[r.groupedFrom[c]]===r.groupedTo[c]-r.groupedFrom[c]+1)for(let i,y=r.groupedFrom[c];y<=r.groupedTo[c];y++)i=r.sortIndexes[y],!l[i]&&(e.prevIndexes[i]!==-1&&e.prevIndexes[e.prevIndexes[i]]!==-1&&e.prevIndexes[e.prevIndexes[e.prevIndexes[i]]]===i?(m[e.prevIndexes[i]]||(m[e.prevIndexes[i]]=1,u[r.groupedFrom[e.prevIndexes[i]]]++),m[e.nextIndexes[i]]||(m[e.nextIndexes[i]]=1,u[r.groupedFrom[e.nextIndexes[i]]]++),u[r.groupedFrom[e.prevIndexes[i]]]===r.groupedTo[e.prevIndexes[i]]-r.groupedFrom[e.prevIndexes[i]]+1&&u[r.groupedFrom[e.nextIndexes[i]]]===r.groupedTo[e.nextIndexes[i]]-r.groupedFrom[e.nextIndexes[i]]+1&&(l[i]=1,l[e.nextIndexes[i]]=1,l[e.prevIndexes[i]]=1,y=r.groupedFrom[c]-1)):(l[i]=1,e.prevIndexes[e.nextIndexes[i]]=e.prevIndexes[i],e.nextIndexes[e.prevIndexes[i]]=e.nextIndexes[i],e.prevIndexes[e.prevIndexes[i]]!==-1&&(a[e.prevIndexes[i]]=g(e.prevIndexes[i],e),s(f,b,e.prevIndexes[i],a,e.coordinates)),e.nextIndexes[e.nextIndexes[i]]!==-1&&(a[e.nextIndexes[i]]=g(e.nextIndexes[i],e),s(f,b,e.nextIndexes[i],a,e.coordinates))))}return l}function x(e,r,t){if(v(e))for(let n=0;n<e.features.length;n++)t=x(e.features[n],r,t);else if(P(e))t=x(e.geometry,r,t);else if(G(e))for(let n=0;n<e.geometries.length;n++)t=x(e.geometries[n],r,t);else if(F(e))t=C(e.coordinates,r,t);else if(A(e))for(let n=0;n<e.coordinates.length;n++)t=C(e.coordinates[n],r,t);else if(U(e)){let n=!1;[t,n]=L(e.coordinates,r,t),n&&e.coordinates.splice(0)}else if(h(e)){let n=0;for(let l=!1,u=0;u<e.coordinates.length;u++)[t,l]=L(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 C(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 L(e,r,t){let n=0;for(let l=!1,u=0;u<e.length;u++)if([t,l]=R(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 R(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 o(e,r){if(v(e))for(let t=0;t<e.features.length;t++)o(e.features[t],r);else if(P(e))o(e.geometry,r);else if(G(e))for(let t=0;t<e.geometries.length;t++)o(e.geometries[t],r);else if(F(e))M(e.coordinates,r);else if(A(e))for(let t=0;t<e.coordinates.length;t++)M(e.coordinates[t],r);else if(U(e))for(let t=0;t<e.coordinates.length;t++)N(e.coordinates[t],r);else if(h(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 M(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)}
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/lib/typeGuards.ts"],"sourcesContent":["import { GeoJsonObject, Position } from 'geojson'\nimport {\n isObject,\n FinitePositiveNumber,\n isFinitePositiveNumber,\n isFeature,\n isFeatureCollection,\n isLineString,\n isMultiLineString,\n isPolygon,\n isMultiPolygon,\n isGeometryCollection,\n} from '@lib/typeGuards'\n\nexport type SimplifyOptions = {\n tolerance?: number\n mutate?: boolean\n}\n\ntype Positions = {\n coordinates: Position[]\n nextIndexes: number[]\n prevIndexes: number[]\n sortIndexes: number[]\n groupedFrom: number[]\n groupedTo: 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: FinitePositiveNumber\n if (options.tolerance === undefined || !isFinitePositiveNumber(options.tolerance)) {\n throw new Error(`Expected provided tolerance to be a finite positive number, but received ${options.tolerance}.`)\n } else {\n tolerance = options.tolerance\n }\n let mutate = true\n if (options.mutate !== undefined) {\n mutate = !!options.mutate\n }\n\n if (!mutate) {\n geojson = structuredClone(geojson)\n }\n\n const positions: Positions = {\n coordinates: [],\n nextIndexes: [],\n prevIndexes: [],\n sortIndexes: [],\n groupedFrom: [],\n groupedTo: [],\n }\n\n collectPositions(geojson, positions)\n if (positions.coordinates.length) {\n groupPositions(positions)\n const isDeleted: Uint8Array = new Uint8Array(positions.coordinates.length)\n deletePositions(positions, tolerance, isDeleted)\n updatePositions(geojson, isDeleted, 0)\n }\n\n return geojson\n}\n\nfunction groupPositions(positions: Positions): void {\n positions.sortIndexes = [...new Array(positions.coordinates.length).keys()]\n positions.sortIndexes.sort((a, b) => {\n return (\n positions.coordinates[a][0] - positions.coordinates[b][0] ||\n positions.coordinates[a][1] - positions.coordinates[b][1]\n )\n })\n\n positions.groupedFrom = new Array(positions.coordinates.length).fill(0)\n positions.groupedTo = new Array(positions.coordinates.length).fill(positions.sortIndexes.length - 1)\n for (let i = 1, j = positions.sortIndexes.length - 2; i < positions.sortIndexes.length; i++, j--) {\n if (\n positions.coordinates[positions.sortIndexes[i]][0] !== positions.coordinates[positions.sortIndexes[i - 1]][0] ||\n positions.coordinates[positions.sortIndexes[i]][1] !== positions.coordinates[positions.sortIndexes[i - 1]][1]\n ) {\n positions.groupedFrom[positions.sortIndexes[i]] = i\n } else {\n positions.groupedFrom[positions.sortIndexes[i]] = positions.groupedFrom[positions.sortIndexes[i - 1]]\n }\n if (\n positions.coordinates[positions.sortIndexes[j]][0] !== positions.coordinates[positions.sortIndexes[j + 1]][0] ||\n positions.coordinates[positions.sortIndexes[j]][1] !== positions.coordinates[positions.sortIndexes[j + 1]][1]\n ) {\n positions.groupedTo[positions.sortIndexes[j]] = j\n } else {\n positions.groupedTo[positions.sortIndexes[j]] = positions.groupedTo[positions.sortIndexes[j + 1]]\n }\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 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 l = i << 1\n r = l + 1\n t = i\n if (\n l <= heap[0] &&\n (priority[heap[t]] > priority[heap[l]] ||\n (priority[heap[t]] === priority[heap[l]] &&\n (coordinates[heap[t]][0] > coordinates[heap[l]][0] ||\n (coordinates[heap[t]][0] === coordinates[heap[l]][0] &&\n coordinates[heap[t]][1] > coordinates[heap[l]][1]))))\n ) {\n t = l\n }\n if (\n r <= heap[0] &&\n (priority[heap[t]] > priority[heap[r]] ||\n (priority[heap[t]] === priority[heap[r]] &&\n (coordinates[heap[t]][0] > coordinates[heap[r]][0] ||\n (coordinates[heap[t]][0] === coordinates[heap[r]][0] &&\n coordinates[heap[t]][1] > coordinates[heap[r]][1]))))\n ) {\n t = r\n }\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 (\n i === t ||\n priority[heap[t]] < priority[heap[i]] ||\n (priority[heap[t]] === priority[heap[i]] &&\n (coordinates[heap[t]][0] < coordinates[heap[i]][0] ||\n (coordinates[heap[t]][0] === coordinates[heap[i]][0] && coordinates[heap[t]][1] < coordinates[heap[i]][1])))\n ) {\n break\n }\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, tolerance: FinitePositiveNumber, isDeleted: Uint8Array): void {\n const n = positions.coordinates.length\n\n const candidatesByGroupFrom: Uint32Array = new Uint32Array(n)\n const isCandidate: Uint8Array = new Uint8Array(n)\n\n const heap: Uint32Array = new Uint32Array(n + 1)\n const priority: Float64Array = new Float64Array(n)\n const heapRev: Uint32Array = new Uint32Array(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) {\n break\n }\n\n // mark as candidate\n if (!isCandidate[i]) {\n isCandidate[i] = 1\n candidatesByGroupFrom[positions.groupedFrom[i]]++\n }\n\n // check if position is grouped and group is not entirely marked\n if (candidatesByGroupFrom[positions.groupedFrom[i]] !== positions.groupedTo[i] - positions.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 = positions.groupedFrom[i]; j <= positions.groupedTo[i]; j++) {\n k = positions.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[positions.groupedFrom[positions.prevIndexes[k]]]++\n }\n if (!isCandidate[positions.nextIndexes[k]]) {\n isCandidate[positions.nextIndexes[k]] = 1\n candidatesByGroupFrom[positions.groupedFrom[positions.nextIndexes[k]]]++\n }\n\n // remove entire ring if neighbor groups are entirely marked\n if (\n candidatesByGroupFrom[positions.groupedFrom[positions.prevIndexes[k]]] ===\n positions.groupedTo[positions.prevIndexes[k]] - positions.groupedFrom[positions.prevIndexes[k]] + 1 &&\n candidatesByGroupFrom[positions.groupedFrom[positions.nextIndexes[k]]] ===\n positions.groupedTo[positions.nextIndexes[k]] - positions.groupedFrom[positions.nextIndexes[k]] + 1\n ) {\n isDeleted[k] = 1\n isDeleted[positions.nextIndexes[k]] = 1\n isDeleted[positions.prevIndexes[k]] = 1\n\n // repeat to delete all matching rings\n // possible optimization\n j = positions.groupedFrom[i] - 1\n }\n } else {\n isDeleted[k] = 1\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}\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"],"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,CACp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,EAAI,EAAIA,EAAIlC,EAAI,CAAC,EAC1DR,EAAU,YAAY,KAAKQ,IAAM,EAAI,EAAIkC,EAAIA,EAAIlC,EAAI,CAAC,CAE1D","names":["index_exports","__export","index_default","__toCommonJS","isFinitePositiveNumber","value","isObject","isFeature","isFeatureCollection","isLineString","isMultiLineString","isPolygon","isMultiPolygon","isGeometryCollection","index_default","geojson","options","isObject","tolerance","isFinitePositiveNumber","mutate","positions","collectPositions","groupPositions","isDeleted","deletePositions","updatePositions","a","b","i","j","getPositionArea","heapsink","heap","heapRev","priority","coordinates","r","t","heapswap","heapbubble","heapupdate","val","heappop","heapify","candidatesByGroupFrom","isCandidate","k","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"],"sourcesContent":["import { GeoJsonObject, Position } from 'geojson'\nimport {\n isObject,\n FinitePositiveNumber,\n isFinitePositiveNumber,\n isFeature,\n isFeatureCollection,\n isLineString,\n isMultiLineString,\n isPolygon,\n isMultiPolygon,\n isGeometryCollection,\n} from '@lib/typeGuards'\n\nexport type SimplifyOptions = {\n tolerance?: number\n mutate?: boolean\n}\n\ntype Positions = {\n coordinates: Position[]\n nextIndexes: number[]\n prevIndexes: number[]\n}\n\ntype Groups = {\n sortIndexes: Uint32Array\n groupedFrom: Uint32Array\n groupedTo: Uint32Array\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: FinitePositiveNumber\n if (options.tolerance !== undefined && !isFinitePositiveNumber(options.tolerance)) {\n throw new Error(`Expected provided tolerance to be a finite positive number, but received ${options.tolerance}.`)\n } else {\n // exit if no simplification options provided\n if (options.tolerance === undefined) return geojson\n tolerance = options.tolerance\n }\n let mutate = true\n if (options.mutate !== undefined) {\n mutate = !!options.mutate\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), 0)\n }\n\n return geojson\n}\n\nfunction 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 groupedTo[0] = groupedTo.length - 1\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 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: FinitePositiveNumber): Uint8Array {\n const n = positions.coordinates.length\n\n const isDeleted = new Uint8Array(n)\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) {\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\n // repeat to delete all matching rings\n // possible optimization\n j = groups.groupedFrom[i] - 1\n }\n } else {\n isDeleted[k] = 1\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"],"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,CAAK,GAAKA,GAAO,OAAS,mBAC5C,CAEO,SAASI,EAAaJ,EAA2C,CACtE,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,YAC5C,CAEO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EAAY,OAAS,EAAGI,EAAI,EAAGA,EAAI,EAAGA,IACnFT,EAAU,YAAY,KAAKK,EAAYI,CAAC,CAAC,EACzCT,EAAU,YAAY,KAAKS,IAAM,EAAIuC,EAAI,EAAI,EAAIA,EAAIvC,EAAI,CAAC,EAC1DT,EAAU,YAAY,KAAKS,IAAM,EAAI,EAAIuC,EAAIA,EAAIvC,EAAI,CAAC,CAE1D","names":["index_exports","__export","index_default","__toCommonJS","isFinitePositiveNumber","value","isObject","isFeature","isFeatureCollection","isLineString","isMultiLineString","isPolygon","isMultiPolygon","isGeometryCollection","index_default","geojson","options","isObject","tolerance","isFinitePositiveNumber","mutate","positions","collectPositions","updatePositions","deletePositions","groupPositions","coordinates","sortIndexes","groupedFrom","groupedTo","i","a","b","j","getPositionArea","heapcompare","priority","heapsink","heap","heapRev","l","r","t","heapswap","heapbubble","heapupdate","val","heappop","heapify","groups","isDeleted","candidatesByGroupFrom","isCandidate","k","index","isFeatureCollection","isFeature","isGeometryCollection","isLineString","updateLinePositions","isMultiLineString","isPolygon","remove","updateRingsPositions","isMultiPolygon","offset","updateRingPositions","collectLinePositions","collectRingPositions","p"]}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- function w(e){return e!=null&&Number.isFinite(e)&&e>0}function m(e){return typeof e=="object"&&e!==null}function P(e){return m(e)&&e?.type==="Feature"}function v(e){return m(e)&&e?.type==="FeatureCollection"}function g(e){return m(e)&&e?.type==="LineString"}function F(e){return m(e)&&e?.type==="MultiLineString"}function A(e){return m(e)&&e?.type==="Polygon"}function U(e){return m(e)&&e?.type==="MultiPolygon"}function o(e){return m(e)&&e?.type==="GeometryCollection"}function z(e,n={}){if(!m(e))throw new TypeError(`Expected provided GeoJSON to be an object, but received ${e===null?"null":typeof e}.`);let r;if(n.tolerance===void 0||!w(n.tolerance))throw new Error(`Expected provided tolerance to be a finite positive number, but received ${n.tolerance}.`);r=n.tolerance;let t=!0;n.mutate!==void 0&&(t=!!n.mutate),t||(e=structuredClone(e));let u={coordinates:[],nextIndexes:[],prevIndexes:[],sortIndexes:[],groupedFrom:[],groupedTo:[]};if(y(e,u),u.coordinates.length){T(u);let l=new Uint8Array(u.coordinates.length);h(u,r,l),a(e,l,0)}return e}function T(e){e.sortIndexes=[...new Array(e.coordinates.length).keys()],e.sortIndexes.sort((n,r)=>e.coordinates[n][0]-e.coordinates[r][0]||e.coordinates[n][1]-e.coordinates[r][1]),e.groupedFrom=new Array(e.coordinates.length).fill(0),e.groupedTo=new Array(e.coordinates.length).fill(e.sortIndexes.length-1);for(let n=1,r=e.sortIndexes.length-2;n<e.sortIndexes.length;n++,r--)e.coordinates[e.sortIndexes[n]][0]!==e.coordinates[e.sortIndexes[n-1]][0]||e.coordinates[e.sortIndexes[n]][1]!==e.coordinates[e.sortIndexes[n-1]][1]?e.groupedFrom[e.sortIndexes[n]]=n:e.groupedFrom[e.sortIndexes[n]]=e.groupedFrom[e.sortIndexes[n-1]],e.coordinates[e.sortIndexes[r]][0]!==e.coordinates[e.sortIndexes[r+1]][0]||e.coordinates[e.sortIndexes[r]][1]!==e.coordinates[e.sortIndexes[r+1]][1]?e.groupedTo[e.sortIndexes[r]]=r:e.groupedTo[e.sortIndexes[r]]=e.groupedTo[e.sortIndexes[r+1]]}function G(e,n){return Math.abs(n.coordinates[e][0]*(n.coordinates[n.prevIndexes[e]][1]-n.coordinates[n.nextIndexes[e]][1])+n.coordinates[n.prevIndexes[e]][0]*(n.coordinates[n.nextIndexes[e]][1]-n.coordinates[e][1])+n.coordinates[n.nextIndexes[e]][0]*(n.coordinates[e][1]-n.coordinates[n.prevIndexes[e]][1]))/2}function i(e,n,r,t,u){let l,c,d;for(;l=r<<1,c=l+1,d=r,l<=e[0]&&(t[e[d]]>t[e[l]]||t[e[d]]===t[e[l]]&&(u[e[d]][0]>u[e[l]][0]||u[e[d]][0]===u[e[l]][0]&&u[e[d]][1]>u[e[l]][1]))&&(d=l),c<=e[0]&&(t[e[d]]>t[e[c]]||t[e[d]]===t[e[c]]&&(u[e[d]][0]>u[e[c]][0]||u[e[d]][0]===u[e[c]][0]&&u[e[d]][1]>u[e[c]][1]))&&(d=c),r!==d;)O(e,n,r,d),r=d;return r}function N(e,n,r,t,u){let l;for(;r>1&&(l=r>>>1,!(r===l||t[e[l]]<t[e[r]]||t[e[l]]===t[e[r]]&&(u[e[l]][0]<u[e[r]][0]||u[e[l]][0]===u[e[r]][0]&&u[e[l]][1]<u[e[r]][1])));)O(e,n,r,l),r=l;return r}function J(e,n,r,t,u){N(e,n,i(e,n,n[r],t,u),t,u)}function O(e,n,r,t){n[e[r]]=t,n[e[t]]=r,[e[r],e[t]]=[e[t],e[r]]}function k(e,n,r,t){return e[0]>1?(O(e,n,1,e[0]),e[0]--,i(e,n,1,r,t),e[e[0]+1]):e[0]===1?(e[0]--,e[1]):-1}function E(e,n,r,t){for(let u=e[0]>>>1;u>0;u--)i(e,n,u,r,t)}function h(e,n,r){let t=e.coordinates.length,u=new Uint32Array(t),l=new Uint8Array(t),c=new Uint32Array(t+1),d=new Float64Array(t),b=new Uint32Array(t);for(let f=0;f<t;f++)e.prevIndexes[f]!==-1&&e.nextIndexes[f]!==-1&&(d[f]=G(f,e),c[0]++,c[c[0]]=f,b[f]=c[0]);E(c,b,d,e.coordinates);let x;for(;c[0];)if(x=k(c,b,d,e.coordinates),!r[x]){if(d[x]>=n)break;if(l[x]||(l[x]=1,u[e.groupedFrom[x]]++),u[e.groupedFrom[x]]===e.groupedTo[x]-e.groupedFrom[x]+1)for(let f,I=e.groupedFrom[x];I<=e.groupedTo[x];I++)f=e.sortIndexes[I],!r[f]&&(e.prevIndexes[f]!==-1&&e.prevIndexes[e.prevIndexes[f]]!==-1&&e.prevIndexes[e.prevIndexes[e.prevIndexes[f]]]===f?(l[e.prevIndexes[f]]||(l[e.prevIndexes[f]]=1,u[e.groupedFrom[e.prevIndexes[f]]]++),l[e.nextIndexes[f]]||(l[e.nextIndexes[f]]=1,u[e.groupedFrom[e.nextIndexes[f]]]++),u[e.groupedFrom[e.prevIndexes[f]]]===e.groupedTo[e.prevIndexes[f]]-e.groupedFrom[e.prevIndexes[f]]+1&&u[e.groupedFrom[e.nextIndexes[f]]]===e.groupedTo[e.nextIndexes[f]]-e.groupedFrom[e.nextIndexes[f]]+1&&(r[f]=1,r[e.nextIndexes[f]]=1,r[e.prevIndexes[f]]=1,I=e.groupedFrom[x]-1)):(r[f]=1,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]]=G(e.prevIndexes[f],e),J(c,b,e.prevIndexes[f],d,e.coordinates)),e.nextIndexes[e.nextIndexes[f]]!==-1&&(d[e.nextIndexes[f]]=G(e.nextIndexes[f],e),J(c,b,e.nextIndexes[f],d,e.coordinates))))}}function a(e,n,r){if(v(e))for(let t=0;t<e.features.length;t++)r=a(e.features[t],n,r);else if(P(e))r=a(e.geometry,n,r);else if(o(e))for(let t=0;t<e.geometries.length;t++)r=a(e.geometries[t],n,r);else if(g(e))r=S(e.coordinates,n,r);else if(F(e))for(let t=0;t<e.coordinates.length;t++)r=S(e.coordinates[t],n,r);else if(A(e)){let t=!1;[r,t]=C(e.coordinates,n,r),t&&e.coordinates.splice(0)}else if(U(e)){let t=0;for(let u=!1,l=0;l<e.coordinates.length;l++)[r,u]=C(e.coordinates[l],n,r),u?t++:t&&(e.coordinates[l-t]=e.coordinates[l]);t&&e.coordinates.splice(e.coordinates.length-t)}return r}function S(e,n,r){let t=0;for(let u=0;u<e.length;u++)n[r]?t++:t&&(e[u-t]=e[u]),r++;return t&&e.splice(e.length-t),r}function C(e,n,r){let t=0;for(let u=!1,l=0;l<e.length;l++)if([r,u]=_(e[l],n,r),u){if(l===0){for(l=1;l<e.length;l++)e[l].length&&(r+=e[l].length-1);return[r,!0]}t++}else t&&(e[l-t]=e[l]);return t&&e.splice(e.length-t),[r,!1]}function _(e,n,r){let t=0;for(let u=0;u<e.length-1;u++)n[r]?t++:t&&(e[u-t]=e[u]),r++;if(t){if(e.length-1-t<3)return[r,!0];e.splice(e.length-1-t,t+1,e[0])}return[r,!1]}function y(e,n){if(v(e))for(let r=0;r<e.features.length;r++)y(e.features[r],n);else if(P(e))y(e.geometry,n);else if(o(e))for(let r=0;r<e.geometries.length;r++)y(e.geometries[r],n);else if(g(e))L(e.coordinates,n);else if(F(e))for(let r=0;r<e.coordinates.length;r++)L(e.coordinates[r],n);else if(A(e))for(let r=0;r<e.coordinates.length;r++)M(e.coordinates[r],n);else if(U(e))for(let r,t=0;t<e.coordinates.length;t++)for(r=0;r<e.coordinates[t].length;r++)M(e.coordinates[t][r],n)}function L(e,n){for(let r=n.coordinates.length,t=e.length,u=0;u<t;u++)n.coordinates.push(e[u]),n.prevIndexes.push(u===0?-1:r+u-1),n.nextIndexes.push(u===t-1?-1:r+u+1)}function M(e,n){for(let r=n.coordinates.length,t=e.length-1,u=0;u<t;u++)n.coordinates.push(e[u]),n.prevIndexes.push(u===0?r+t-1:r+u-1),n.nextIndexes.push(u===t-1?r:r+u+1)}export{z as default};
1
+ function J(e){return e!=null&&Number.isFinite(e)&&e>0}function d(e){return typeof e=="object"&&e!==null}function I(e){return d(e)&&e?.type==="Feature"}function P(e){return d(e)&&e?.type==="FeatureCollection"}function v(e){return d(e)&&e?.type==="LineString"}function F(e){return d(e)&&e?.type==="MultiLineString"}function A(e){return d(e)&&e?.type==="Polygon"}function U(e){return d(e)&&e?.type==="MultiPolygon"}function h(e){return d(e)&&e?.type==="GeometryCollection"}function z(e,r={}){if(!d(e))throw new TypeError(`Expected provided GeoJSON to be an object, but received ${e===null?"null":typeof e}.`);let t;if(r.tolerance!==void 0&&!J(r.tolerance))throw new Error(`Expected provided tolerance to be a finite positive number, but received ${r.tolerance}.`);if(r.tolerance===void 0)return e;t=r.tolerance;let n=!0;r.mutate!==void 0&&(n=!!r.mutate),n||(e=structuredClone(e));let l={coordinates:[],nextIndexes:[],prevIndexes:[]};return o(e,l),l.coordinates.length&&x(e,p(l,N(l.coordinates),t),0),e}function N(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]),n[0]=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 G(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 g(e,r,t,n){return t[e]-t[r]||n[e][0]-n[r][0]||n[e][1]-n[r][1]}function O(e,r,t,n,l){let u,m,f;for(;f=t,(u=t<<1)<=e[0]&&g(e[f],e[u],n,l)>0&&(f=u),(m=u+1)<=e[0]&&g(e[f],e[m],n,l)>0&&(f=m),t!==f;)w(e,r,t,f),t=f;return t}function T(e,r,t,n,l){let u;for(;t>1&&(u=t>>>1,!(t===u||g(e[u],e[t],n,l)<=0));)w(e,r,t,u),t=u;return t}function S(e,r,t,n,l){T(e,r,O(e,r,r[t],n,l),n,l)}function w(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?(w(e,r,1,e[0]),e[0]--,O(e,r,1,t,n),e[e[0]+1]):e[0]===1?(e[0]--,e[1]):-1}function E(e,r,t,n){for(let l=e[0]>>>1;l>0;l--)O(e,r,l,t,n)}function p(e,r,t){let n=e.coordinates.length,l=new Uint8Array(n),u=new Uint32Array(n),m=new Uint8Array(n),f=new Uint32Array(n+1),a=new Float64Array(n),b=new Uint32Array(n);for(let i=0;i<n;i++)e.prevIndexes[i]!==-1&&e.nextIndexes[i]!==-1&&(a[i]=G(i,e),f[0]++,f[f[0]]=i,b[i]=f[0]);E(f,b,a,e.coordinates);let c;for(;f[0];)if(c=k(f,b,a,e.coordinates),!l[c]){if(a[c]>=t)break;if(m[c]||(m[c]=1,u[r.groupedFrom[c]]++),u[r.groupedFrom[c]]===r.groupedTo[c]-r.groupedFrom[c]+1)for(let i,y=r.groupedFrom[c];y<=r.groupedTo[c];y++)i=r.sortIndexes[y],!l[i]&&(e.prevIndexes[i]!==-1&&e.prevIndexes[e.prevIndexes[i]]!==-1&&e.prevIndexes[e.prevIndexes[e.prevIndexes[i]]]===i?(m[e.prevIndexes[i]]||(m[e.prevIndexes[i]]=1,u[r.groupedFrom[e.prevIndexes[i]]]++),m[e.nextIndexes[i]]||(m[e.nextIndexes[i]]=1,u[r.groupedFrom[e.nextIndexes[i]]]++),u[r.groupedFrom[e.prevIndexes[i]]]===r.groupedTo[e.prevIndexes[i]]-r.groupedFrom[e.prevIndexes[i]]+1&&u[r.groupedFrom[e.nextIndexes[i]]]===r.groupedTo[e.nextIndexes[i]]-r.groupedFrom[e.nextIndexes[i]]+1&&(l[i]=1,l[e.nextIndexes[i]]=1,l[e.prevIndexes[i]]=1,y=r.groupedFrom[c]-1)):(l[i]=1,e.prevIndexes[e.nextIndexes[i]]=e.prevIndexes[i],e.nextIndexes[e.prevIndexes[i]]=e.nextIndexes[i],e.prevIndexes[e.prevIndexes[i]]!==-1&&(a[e.prevIndexes[i]]=G(e.prevIndexes[i],e),S(f,b,e.prevIndexes[i],a,e.coordinates)),e.nextIndexes[e.nextIndexes[i]]!==-1&&(a[e.nextIndexes[i]]=G(e.nextIndexes[i],e),S(f,b,e.nextIndexes[i],a,e.coordinates))))}return l}function x(e,r,t){if(P(e))for(let n=0;n<e.features.length;n++)t=x(e.features[n],r,t);else if(I(e))t=x(e.geometry,r,t);else if(h(e))for(let n=0;n<e.geometries.length;n++)t=x(e.geometries[n],r,t);else if(v(e))t=s(e.coordinates,r,t);else if(F(e))for(let n=0;n<e.coordinates.length;n++)t=s(e.coordinates[n],r,t);else if(A(e)){let n=!1;[t,n]=C(e.coordinates,r,t),n&&e.coordinates.splice(0)}else if(U(e)){let n=0;for(let l=!1,u=0;u<e.coordinates.length;u++)[t,l]=C(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 C(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 o(e,r){if(P(e))for(let t=0;t<e.features.length;t++)o(e.features[t],r);else if(I(e))o(e.geometry,r);else if(h(e))for(let t=0;t<e.geometries.length;t++)o(e.geometries[t],r);else if(v(e))L(e.coordinates,r);else if(F(e))for(let t=0;t<e.coordinates.length;t++)L(e.coordinates[t],r);else if(A(e))for(let t=0;t<e.coordinates.length;t++)M(e.coordinates[t],r);else if(U(e))for(let t,n=0;n<e.coordinates.length;n++)for(t=0;t<e.coordinates[n].length;t++)M(e.coordinates[n][t],r)}function L(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 M(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{z 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/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 { GeoJsonObject, Position } from 'geojson'\nimport {\n isObject,\n FinitePositiveNumber,\n isFinitePositiveNumber,\n isFeature,\n isFeatureCollection,\n isLineString,\n isMultiLineString,\n isPolygon,\n isMultiPolygon,\n isGeometryCollection,\n} from '@lib/typeGuards'\n\nexport type SimplifyOptions = {\n tolerance?: number\n mutate?: boolean\n}\n\ntype Positions = {\n coordinates: Position[]\n nextIndexes: number[]\n prevIndexes: number[]\n sortIndexes: number[]\n groupedFrom: number[]\n groupedTo: 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: FinitePositiveNumber\n if (options.tolerance === undefined || !isFinitePositiveNumber(options.tolerance)) {\n throw new Error(`Expected provided tolerance to be a finite positive number, but received ${options.tolerance}.`)\n } else {\n tolerance = options.tolerance\n }\n let mutate = true\n if (options.mutate !== undefined) {\n mutate = !!options.mutate\n }\n\n if (!mutate) {\n geojson = structuredClone(geojson)\n }\n\n const positions: Positions = {\n coordinates: [],\n nextIndexes: [],\n prevIndexes: [],\n sortIndexes: [],\n groupedFrom: [],\n groupedTo: [],\n }\n\n collectPositions(geojson, positions)\n if (positions.coordinates.length) {\n groupPositions(positions)\n const isDeleted: Uint8Array = new Uint8Array(positions.coordinates.length)\n deletePositions(positions, tolerance, isDeleted)\n updatePositions(geojson, isDeleted, 0)\n }\n\n return geojson\n}\n\nfunction groupPositions(positions: Positions): void {\n positions.sortIndexes = [...new Array(positions.coordinates.length).keys()]\n positions.sortIndexes.sort((a, b) => {\n return (\n positions.coordinates[a][0] - positions.coordinates[b][0] ||\n positions.coordinates[a][1] - positions.coordinates[b][1]\n )\n })\n\n positions.groupedFrom = new Array(positions.coordinates.length).fill(0)\n positions.groupedTo = new Array(positions.coordinates.length).fill(positions.sortIndexes.length - 1)\n for (let i = 1, j = positions.sortIndexes.length - 2; i < positions.sortIndexes.length; i++, j--) {\n if (\n positions.coordinates[positions.sortIndexes[i]][0] !== positions.coordinates[positions.sortIndexes[i - 1]][0] ||\n positions.coordinates[positions.sortIndexes[i]][1] !== positions.coordinates[positions.sortIndexes[i - 1]][1]\n ) {\n positions.groupedFrom[positions.sortIndexes[i]] = i\n } else {\n positions.groupedFrom[positions.sortIndexes[i]] = positions.groupedFrom[positions.sortIndexes[i - 1]]\n }\n if (\n positions.coordinates[positions.sortIndexes[j]][0] !== positions.coordinates[positions.sortIndexes[j + 1]][0] ||\n positions.coordinates[positions.sortIndexes[j]][1] !== positions.coordinates[positions.sortIndexes[j + 1]][1]\n ) {\n positions.groupedTo[positions.sortIndexes[j]] = j\n } else {\n positions.groupedTo[positions.sortIndexes[j]] = positions.groupedTo[positions.sortIndexes[j + 1]]\n }\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 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 l = i << 1\n r = l + 1\n t = i\n if (\n l <= heap[0] &&\n (priority[heap[t]] > priority[heap[l]] ||\n (priority[heap[t]] === priority[heap[l]] &&\n (coordinates[heap[t]][0] > coordinates[heap[l]][0] ||\n (coordinates[heap[t]][0] === coordinates[heap[l]][0] &&\n coordinates[heap[t]][1] > coordinates[heap[l]][1]))))\n ) {\n t = l\n }\n if (\n r <= heap[0] &&\n (priority[heap[t]] > priority[heap[r]] ||\n (priority[heap[t]] === priority[heap[r]] &&\n (coordinates[heap[t]][0] > coordinates[heap[r]][0] ||\n (coordinates[heap[t]][0] === coordinates[heap[r]][0] &&\n coordinates[heap[t]][1] > coordinates[heap[r]][1]))))\n ) {\n t = r\n }\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 (\n i === t ||\n priority[heap[t]] < priority[heap[i]] ||\n (priority[heap[t]] === priority[heap[i]] &&\n (coordinates[heap[t]][0] < coordinates[heap[i]][0] ||\n (coordinates[heap[t]][0] === coordinates[heap[i]][0] && coordinates[heap[t]][1] < coordinates[heap[i]][1])))\n ) {\n break\n }\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, tolerance: FinitePositiveNumber, isDeleted: Uint8Array): void {\n const n = positions.coordinates.length\n\n const candidatesByGroupFrom: Uint32Array = new Uint32Array(n)\n const isCandidate: Uint8Array = new Uint8Array(n)\n\n const heap: Uint32Array = new Uint32Array(n + 1)\n const priority: Float64Array = new Float64Array(n)\n const heapRev: Uint32Array = new Uint32Array(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) {\n break\n }\n\n // mark as candidate\n if (!isCandidate[i]) {\n isCandidate[i] = 1\n candidatesByGroupFrom[positions.groupedFrom[i]]++\n }\n\n // check if position is grouped and group is not entirely marked\n if (candidatesByGroupFrom[positions.groupedFrom[i]] !== positions.groupedTo[i] - positions.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 = positions.groupedFrom[i]; j <= positions.groupedTo[i]; j++) {\n k = positions.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[positions.groupedFrom[positions.prevIndexes[k]]]++\n }\n if (!isCandidate[positions.nextIndexes[k]]) {\n isCandidate[positions.nextIndexes[k]] = 1\n candidatesByGroupFrom[positions.groupedFrom[positions.nextIndexes[k]]]++\n }\n\n // remove entire ring if neighbor groups are entirely marked\n if (\n candidatesByGroupFrom[positions.groupedFrom[positions.prevIndexes[k]]] ===\n positions.groupedTo[positions.prevIndexes[k]] - positions.groupedFrom[positions.prevIndexes[k]] + 1 &&\n candidatesByGroupFrom[positions.groupedFrom[positions.nextIndexes[k]]] ===\n positions.groupedTo[positions.nextIndexes[k]] - positions.groupedFrom[positions.nextIndexes[k]] + 1\n ) {\n isDeleted[k] = 1\n isDeleted[positions.nextIndexes[k]] = 1\n isDeleted[positions.prevIndexes[k]] = 1\n\n // repeat to delete all matching rings\n // possible optimization\n j = positions.groupedFrom[i] - 1\n }\n } else {\n isDeleted[k] = 1\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}\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,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AAIA,EAAInC,EAAI,CAAC,CAE1D","names":["isFinitePositiveNumber","value","isObject","isFeature","isFeatureCollection","isLineString","isMultiLineString","isPolygon","isMultiPolygon","isGeometryCollection","index_default","geojson","options","isObject","tolerance","isFinitePositiveNumber","mutate","positions","collectPositions","groupPositions","isDeleted","deletePositions","updatePositions","a","b","i","j","getPositionArea","heapsink","heap","heapRev","priority","coordinates","r","t","heapswap","heapbubble","heapupdate","val","heappop","heapify","n","candidatesByGroupFrom","isCandidate","k","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/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 { GeoJsonObject, Position } from 'geojson'\nimport {\n isObject,\n FinitePositiveNumber,\n isFinitePositiveNumber,\n isFeature,\n isFeatureCollection,\n isLineString,\n isMultiLineString,\n isPolygon,\n isMultiPolygon,\n isGeometryCollection,\n} from '@lib/typeGuards'\n\nexport type SimplifyOptions = {\n tolerance?: number\n mutate?: boolean\n}\n\ntype Positions = {\n coordinates: Position[]\n nextIndexes: number[]\n prevIndexes: number[]\n}\n\ntype Groups = {\n sortIndexes: Uint32Array\n groupedFrom: Uint32Array\n groupedTo: Uint32Array\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: FinitePositiveNumber\n if (options.tolerance !== undefined && !isFinitePositiveNumber(options.tolerance)) {\n throw new Error(`Expected provided tolerance to be a finite positive number, but received ${options.tolerance}.`)\n } else {\n // exit if no simplification options provided\n if (options.tolerance === undefined) return geojson\n tolerance = options.tolerance\n }\n let mutate = true\n if (options.mutate !== undefined) {\n mutate = !!options.mutate\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), 0)\n }\n\n return geojson\n}\n\nfunction 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 groupedTo[0] = groupedTo.length - 1\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 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: FinitePositiveNumber): Uint8Array {\n const n = positions.coordinates.length\n\n const isDeleted = new Uint8Array(n)\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) {\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\n // repeat to delete all matching rings\n // possible optimization\n j = groups.groupedFrom[i] - 1\n }\n } else {\n isDeleted[k] = 1\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,EAA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T,EAAU,YAAY,KAAKS,IAAM,EAAI,EAAIuC,EAAIA,EAAIvC,EAAI,CAAC,CAE1D","names":["isFinitePositiveNumber","value","isObject","isFeature","isFeatureCollection","isLineString","isMultiLineString","isPolygon","isMultiPolygon","isGeometryCollection","index_default","geojson","options","isObject","tolerance","isFinitePositiveNumber","mutate","positions","collectPositions","updatePositions","deletePositions","groupPositions","coordinates","sortIndexes","groupedFrom","groupedTo","i","a","b","j","getPositionArea","heapcompare","priority","heapsink","heap","heapRev","l","r","t","heapswap","heapbubble","heapupdate","val","heappop","heapify","groups","isDeleted","candidatesByGroupFrom","isCandidate","k","index","isFeatureCollection","isFeature","isGeometryCollection","isLineString","updateLinePositions","isMultiLineString","isPolygon","remove","updateRingsPositions","isMultiPolygon","offset","updateRingPositions","collectLinePositions","collectRingPositions","p"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplify-geojson-visvalingam",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
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",