simplify-geojson-visvalingam 1.3.7 → 1.3.9

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 v=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var B=(e,r)=>{for(var t in r)v(e,t,{get:r[t],enumerable:!0})},X=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of q(r))!_.call(e,l)&&l!==t&&v(e,l,{get:()=>r[l],enumerable:!(n=$(r,l))||n.enumerable});return e};var Y=e=>X(v({},"__esModule",{value:!0}),e);var V={};B(V,{default:()=>Q});module.exports=Y(V);function A(e){return e!=null&&Number.isFinite(e)&&e>0}function d(e){return typeof e=="object"&&e!==null}function F(e){return d(e)&&e?.type==="Feature"}function h(e){return d(e)&&e?.type==="FeatureCollection"}function U(e){return d(e)&&e?.type==="LineString"}function g(e){return d(e)&&e?.type==="MultiLineString"}function G(e){return d(e)&&e?.type==="Polygon"}function w(e){return d(e)&&e?.type==="MultiPolygon"}function O(e){return d(e)&&e?.type==="GeometryCollection"}function M(e){let r=new Uint32Array(e.length),t=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let l=0;l<e.length;l++)r[l]=l;r.sort((l,u)=>{let m=e[l][0]-e[u][0];if(m)return m<0?-1:1;let f=e[l][1]-e[u][1];return f<0?-1:f>0?1:0}),e.length&&(n[r[e.length-1]]=n.length-1);for(let l=1,u=e.length-2;l<e.length;l++,u--)e[r[l]][0]!==e[r[l-1]][0]||e[r[l]][1]!==e[r[l-1]][1]?t[r[l]]=l:t[r[l]]=t[r[l-1]],e[r[u]][0]!==e[r[u+1]][0]||e[r[u]][1]!==e[r[u+1]][1]?n[r[u]]=u:n[r[u]]=n[r[u+1]];return{sortIndexes:r,groupedFrom:t,groupedTo:n}}function J(e,r){return Math.abs(r.coordinates[e][0]*(r.coordinates[r.prevIndexes[e]][1]-r.coordinates[r.nextIndexes[e]][1])+r.coordinates[r.prevIndexes[e]][0]*(r.coordinates[r.nextIndexes[e]][1]-r.coordinates[e][1])+r.coordinates[r.nextIndexes[e]][0]*(r.coordinates[e][1]-r.coordinates[r.prevIndexes[e]][1]))/2}function s(e,r,t,n){return t[e]-t[r]||n[e][0]-n[r][0]||n[e][1]-n[r][1]}function S(e,r,t,n,l){let u,m,f;for(;f=t,(u=t<<1)<=e[0]&&s(e[f],e[u],n,l)>0&&(f=u),(m=u+1)<=e[0]&&s(e[f],e[m],n,l)>0&&(f=m),t!==f;)C(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||s(e[u],e[t],n,l)<=0));)C(e,r,t,u),t=u;return t}function L(e,r,t,n,l){z(e,r,S(e,r,r[t],n,l),n,l)}function C(e,r,t,n){r[e[t]]=n,r[e[n]]=t,[e[t],e[n]]=[e[n],e[t]]}function H(e,r,t,n){return e[0]>1?(C(e,r,1,e[0]),e[0]--,S(e,r,1,t,n),e[e[0]+1]):e[0]===1?(e[0]--,e[1]):-1}function K(e,r,t,n){for(let l=e[0]>>>1;l>0;l--)S(e,r,l,t,n)}function p(e,r,t,n){let l=e.coordinates.length,u=new Uint8Array(l),m=Math.round(l*n),f=new Uint32Array(l),b=new Uint8Array(l),o=new Uint32Array(l+1),a=new Float64Array(l),x=new Uint32Array(l);for(let i=0;i<l;i++)e.prevIndexes[i]!==-1&&e.nextIndexes[i]!==-1&&(a[i]=J(i,e),o[0]++,o[o[0]]=i,x[i]=o[0]);K(o,x,a,e.coordinates);let c;for(;o[0];)if(c=H(o,x,a,e.coordinates),!u[c]){if(a[c]>=t&&m<=0)break;if(b[c]||(b[c]=1,f[r.groupedFrom[c]]++),f[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],!u[i]&&(e.prevIndexes[i]!==-1&&e.prevIndexes[e.prevIndexes[i]]!==-1&&e.prevIndexes[e.prevIndexes[e.prevIndexes[i]]]===i?(b[e.prevIndexes[i]]||(b[e.prevIndexes[i]]=1,f[r.groupedFrom[e.prevIndexes[i]]]++),b[e.nextIndexes[i]]||(b[e.nextIndexes[i]]=1,f[r.groupedFrom[e.nextIndexes[i]]]++),f[r.groupedFrom[e.prevIndexes[i]]]===r.groupedTo[e.prevIndexes[i]]-r.groupedFrom[e.prevIndexes[i]]+1&&f[r.groupedFrom[e.nextIndexes[i]]]===r.groupedTo[e.nextIndexes[i]]-r.groupedFrom[e.nextIndexes[i]]+1&&(u[i]=1,u[e.nextIndexes[i]]=1,u[e.prevIndexes[i]]=1,m-=3,y=r.groupedFrom[c]-1)):(u[i]=1,m--,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]]=J(e.prevIndexes[i],e),L(o,x,e.prevIndexes[i],a,e.coordinates)),e.nextIndexes[e.nextIndexes[i]]!==-1&&(a[e.nextIndexes[i]]=J(e.nextIndexes[i],e),L(o,x,e.nextIndexes[i],a,e.coordinates))))}return u}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=0;if(r.tolerance!==void 0){if(!A(r.tolerance))throw new Error(`Expected provided tolerance to be a finite positive number, but received ${r.tolerance}.`);t=r.tolerance}let n=0;if(r.fraction!==void 0){if(!A(r.fraction))throw new Error(`Expected provided fraction to be a finite positive number, but received ${r.fraction}.`);if(r.fraction>1)throw new Error(`Expected provided fraction to be less or equal to 1, but received ${r.fraction}.`);n=r.fraction}let l=!0;if(r.mutate!==void 0&&(l=!!r.mutate),t===0&&n===0)return e;l||(e=structuredClone(e));let u={coordinates:[],nextIndexes:[],prevIndexes:[]};return P(e,u),u.coordinates.length&&I(e,p(u,M(u.coordinates),t,n),0),e}function I(e,r,t){if(h(e))for(let n=0;n<e.features.length;n++)t=I(e.features[n],r,t);else if(F(e))t=I(e.geometry,r,t);else if(O(e))for(let n=0;n<e.geometries.length;n++)t=I(e.geometries[n],r,t);else if(U(e))t=E(e.coordinates,r,t);else if(g(e))for(let n=0;n<e.coordinates.length;n++)t=E(e.coordinates[n],r,t);else if(G(e)){let n=!1;[t,n]=T(e.coordinates,r,t),n&&e.coordinates.splice(0)}else if(w(e)){let n=0;for(let l=!1,u=0;u<e.coordinates.length;u++)[t,l]=T(e.coordinates[u],r,t),l?n++:n&&(e.coordinates[u-n]=e.coordinates[u]);n&&e.coordinates.splice(e.coordinates.length-n)}return t}function E(e,r,t){let n=0;for(let l=0;l<e.length;l++)r[t]?n++:n&&(e[l-n]=e[l]),t++;return n&&e.splice(e.length-n),t}function T(e,r,t){let n=0;for(let l=!1,u=0;u<e.length;u++)if([t,l]=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 P(e,r){if(h(e))for(let t=0;t<e.features.length;t++)P(e.features[t],r);else if(F(e))P(e.geometry,r);else if(O(e))for(let t=0;t<e.geometries.length;t++)P(e.geometries[t],r);else if(U(e))N(e.coordinates,r);else if(g(e))for(let t=0;t<e.coordinates.length;t++)N(e.coordinates[t],r);else if(G(e))for(let t=0;t<e.coordinates.length;t++)k(e.coordinates[t],r);else if(w(e))for(let t,n=0;n<e.coordinates.length;n++)for(t=0;t<e.coordinates[n].length;t++)k(e.coordinates[n][t],r)}function N(e,r){for(let t=r.coordinates.length,n=e.length,l=0;l<n;l++)r.coordinates.push(e[l]),r.prevIndexes.push(l===0?-1:t+l-1),r.nextIndexes.push(l===n-1?-1:t+l+1)}function k(e,r){for(let t=r.coordinates.length,n=e.length-1,l=0;l<n;l++)r.coordinates.push(e[l]),r.prevIndexes.push(l===0?t+n-1:t+l-1),r.nextIndexes.push(l===n-1?t:t+l+1)}
1
+ "use strict";var v=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var T=(e,r)=>{for(var t in r)v(e,t,{get:r[t],enumerable:!0})},X=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let u of q(r))!B.call(e,u)&&u!==t&&v(e,u,{get:()=>r[u],enumerable:!(n=$(r,u))||n.enumerable});return e};var _=e=>X(v({},"__esModule",{value:!0}),e);var W={};T(W,{default:()=>Q});module.exports=_(W);function s(e){return e!=null&&Number.isFinite(e)&&e>0}function d(e){return typeof e=="object"&&e!==null}function A(e){return d(e)&&e?.type==="Feature"}function U(e){return d(e)&&e?.type==="FeatureCollection"}function G(e){return d(e)&&e?.type==="LineString"}function O(e){return d(e)&&e?.type==="MultiLineString"}function h(e){return d(e)&&e?.type==="Polygon"}function g(e){return d(e)&&e?.type==="MultiPolygon"}function w(e){return d(e)&&e?.type==="GeometryCollection"}function J(e){let r=new Uint32Array(e.length),t=new Uint32Array(e.length),n=new Uint32Array(e.length),u=new Uint32Array(e.length),l=new Map;for(let f=0;f<e.length;f++){let b=e[f][0],a=e[f][1],c=l.get(b),o;if(c===void 0)o=f,l.set(b,f);else if(typeof c=="number")if(e[c][1]===a)o=c;else{o=f;let y=new Map;y.set(e[c][1],c),y.set(a,f),l.set(b,y)}else{let y=c.get(a);y===void 0?(o=f,c.set(a,f)):o=y}r[f]=o,o===f?(t[o]=1,u[o]=f):(t[o]++,n[u[o]]=f,u[o]=f),n[f]=e.length}return{groupOf:r,groupSize:t,nextInGroup:n}}function F(e,r){return Math.abs(r.coordinates[e][0]*(r.coordinates[r.prevIndexes[e]][1]-r.coordinates[r.nextIndexes[e]][1])+r.coordinates[r.prevIndexes[e]][0]*(r.coordinates[r.nextIndexes[e]][1]-r.coordinates[e][1])+r.coordinates[r.nextIndexes[e]][0]*(r.coordinates[e][1]-r.coordinates[r.prevIndexes[e]][1]))/2}function S(e,r,t,n){return t[e]-t[r]||n[e][0]-n[r][0]||n[e][1]-n[r][1]}function p(e,r,t,n,u){let l=e[t],f,b,a,c;for(;a=t,c=l,(f=t<<1)<=e[0]&&S(c,e[f],n,u)>0&&(a=f,c=e[f]),(b=f+1)<=e[0]&&S(c,e[b],n,u)>0&&(a=b),t!==a;)e[t]=e[a],r[e[t]]=t,t=a;return e[t]=l,r[l]=t,t}function Y(e,r,t,n,u){let l;for(;t>1&&(l=t>>>1,!(t===l||S(e[l],e[t],n,u)<=0));)C(e,r,t,l),t=l;return t}function M(e,r,t,n,u){Y(e,r,p(e,r,r[t],n,u),n,u)}function C(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?(C(e,r,1,e[0]),e[0]--,p(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 u=e[0]>>>1;u>0;u--)p(e,r,u,t,n)}function L(e,r,t,n){let u=e.coordinates.length,l=new Uint8Array(u),f=Math.round(u*n),b=new Uint32Array(u),a=new Uint8Array(u),c=new Uint32Array(u+1),o=new Float64Array(u),y=new Uint32Array(u);for(let m=0;m<u;m++)e.prevIndexes[m]!==-1&&e.nextIndexes[m]!==-1&&(o[m]=F(m,e),c[0]++,c[c[0]]=m,y[m]=c[0]);K(c,y,o,e.coordinates);let x;for(;c[0];){if(x=H(c,y,o,e.coordinates),l[x])continue;if(o[x]>=t&&f<=0)break;let m=r.groupOf[x];if(a[x]||(a[x]=1,b[m]++),b[m]!==r.groupSize[m])continue;let i=m;for(;i<u;){if(l[i]){i=r.nextInGroup[i];continue}if(e.prevIndexes[i]!==-1&&e.prevIndexes[e.prevIndexes[i]]!==-1&&e.prevIndexes[e.prevIndexes[e.prevIndexes[i]]]===i){if(a[e.prevIndexes[i]]||(a[e.prevIndexes[i]]=1,b[r.groupOf[e.prevIndexes[i]]]++),a[e.nextIndexes[i]]||(a[e.nextIndexes[i]]=1,b[r.groupOf[e.nextIndexes[i]]]++),b[r.groupOf[e.prevIndexes[i]]]===r.groupSize[r.groupOf[e.prevIndexes[i]]]&&b[r.groupOf[e.nextIndexes[i]]]===r.groupSize[r.groupOf[e.nextIndexes[i]]]){l[i]=1,l[e.nextIndexes[i]]=1,l[e.prevIndexes[i]]=1,f-=3,i=m;continue}}else l[i]=1,f--,e.prevIndexes[e.nextIndexes[i]]=e.prevIndexes[i],e.nextIndexes[e.prevIndexes[i]]=e.nextIndexes[i],e.prevIndexes[e.prevIndexes[i]]!==-1&&(o[e.prevIndexes[i]]=F(e.prevIndexes[i],e),M(c,y,e.prevIndexes[i],o,e.coordinates)),e.nextIndexes[e.nextIndexes[i]]!==-1&&(o[e.nextIndexes[i]]=F(e.nextIndexes[i],e),M(c,y,e.nextIndexes[i],o,e.coordinates));i=r.nextInGroup[i]}}return l}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=0;if(r.tolerance!==void 0){if(!s(r.tolerance))throw new Error(`Expected provided tolerance to be a finite positive number, but received ${r.tolerance}.`);t=r.tolerance}let n=0;if(r.fraction!==void 0){if(!s(r.fraction))throw new Error(`Expected provided fraction to be a finite positive number, but received ${r.fraction}.`);if(r.fraction>1)throw new Error(`Expected provided fraction to be less or equal to 1, but received ${r.fraction}.`);n=r.fraction}let u=!0;if(r.mutate!==void 0&&(u=!!r.mutate),t===0&&n===0)return e;u||(e=structuredClone(e));let l={coordinates:[],nextIndexes:[],prevIndexes:[]};return P(e,l),l.coordinates.length&&I(e,L(l,J(l.coordinates),t,n),0),e}function I(e,r,t){if(U(e))for(let n=0;n<e.features.length;n++)t=I(e.features[n],r,t);else if(A(e))t=I(e.geometry,r,t);else if(w(e))for(let n=0;n<e.geometries.length;n++)t=I(e.geometries[n],r,t);else if(G(e))t=E(e.coordinates,r,t);else if(O(e))for(let n=0;n<e.coordinates.length;n++)t=E(e.coordinates[n],r,t);else if(h(e)){let n=!1;[t,n]=N(e.coordinates,r,t),n&&e.coordinates.splice(0)}else if(g(e)){let n=0;for(let u=!1,l=0;l<e.coordinates.length;l++)[t,u]=N(e.coordinates[l],r,t),u?n++:n&&(e.coordinates[l-n]=e.coordinates[l]);n&&e.coordinates.splice(e.coordinates.length-n)}return t}function E(e,r,t){let n=0;for(let u=0;u<e.length;u++)r[t]?n++:n&&(e[u-n]=e[u]),t++;return n&&e.splice(e.length-n),t}function N(e,r,t){let n=0;for(let u=!1,l=0;l<e.length;l++)if([t,u]=V(e[l],r,t),u){if(l===0){for(l=1;l<e.length;l++)e[l].length&&(t+=e[l].length-1);return[t,!0]}n++}else n&&(e[l-n]=e[l]);return n&&e.splice(e.length-n),[t,!1]}function V(e,r,t){let n=0;for(let u=0;u<e.length-1;u++)r[t]?n++:n&&(e[u-n]=e[u]),t++;if(n){if(e.length-1-n<3)return[t,!0];e.splice(e.length-1-n,n+1,e[0])}return[t,!1]}function P(e,r){if(U(e))for(let t=0;t<e.features.length;t++)P(e.features[t],r);else if(A(e))P(e.geometry,r);else if(w(e))for(let t=0;t<e.geometries.length;t++)P(e.geometries[t],r);else if(G(e))k(e.coordinates,r);else if(O(e))for(let t=0;t<e.coordinates.length;t++)k(e.coordinates[t],r);else if(h(e))for(let t=0;t<e.coordinates.length;t++)z(e.coordinates[t],r);else if(g(e))for(let t,n=0;n<e.coordinates.length;n++)for(t=0;t<e.coordinates[n].length;t++)z(e.coordinates[n][t],r)}function k(e,r){for(let t=r.coordinates.length,n=e.length,u=0;u<n;u++)r.coordinates.push(e[u]),r.prevIndexes.push(u===0?-1:t+u-1),r.nextIndexes.push(u===n-1?-1:t+u+1)}function z(e,r){for(let t=r.coordinates.length,n=e.length-1,u=0;u<n;u++)r.coordinates.push(e[u]),r.prevIndexes.push(u===0?t+n-1:t+u-1),r.nextIndexes.push(u===n-1?t:t+u+1)}
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/lib/typeGuards.ts","../src/lib/functions.ts"],"sourcesContent":["import { GeoJsonObject, Position } from 'geojson'\nimport {\n isObject,\n isFinitePositiveNumber,\n isFeature,\n isFeatureCollection,\n isLineString,\n isMultiLineString,\n isPolygon,\n isMultiPolygon,\n isGeometryCollection,\n} from '@lib/typeGuards'\nimport { deletePositions, groupPositions, type Positions } from '@lib/functions'\n\nexport type SimplifyOptions = {\n tolerance?: number\n fraction?: number\n mutate?: boolean\n}\n\nexport default function (geojson: GeoJsonObject, options: SimplifyOptions = {}): GeoJsonObject {\n // validate input data\n if (!isObject(geojson)) {\n throw new TypeError(\n `Expected provided GeoJSON to be an object, but received ${geojson === null ? 'null' : typeof geojson}.`,\n )\n }\n\n // validate options\n let tolerance = 0\n if (options.tolerance !== undefined) {\n if (!isFinitePositiveNumber(options.tolerance)) {\n throw new Error(`Expected provided tolerance to be a finite positive number, but received ${options.tolerance}.`)\n }\n tolerance = options.tolerance\n }\n let fraction = 0\n if (options.fraction !== undefined) {\n if (!isFinitePositiveNumber(options.fraction)) {\n throw new Error(`Expected provided fraction to be a finite positive number, but received ${options.fraction}.`)\n }\n if (options.fraction > 1) {\n throw new Error(`Expected provided fraction to be less or equal to 1, but received ${options.fraction}.`)\n }\n fraction = options.fraction\n }\n let mutate = true\n if (options.mutate !== undefined) {\n mutate = !!options.mutate\n }\n\n // exit if no simplification options provided\n if (tolerance === 0 && fraction === 0) {\n return geojson\n }\n\n if (!mutate) {\n geojson = structuredClone(geojson)\n }\n\n const positions: Positions = {\n coordinates: [],\n nextIndexes: [],\n prevIndexes: [],\n }\n collectPositions(geojson, positions)\n\n if (positions.coordinates.length) {\n updatePositions(geojson, deletePositions(positions, groupPositions(positions.coordinates), tolerance, fraction), 0)\n }\n\n return geojson\n}\nfunction updatePositions(geojson: GeoJsonObject, isDeleted: Uint8Array, index: number): number {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n index = updatePositions(geojson.features[i], isDeleted, index)\n }\n } else if (isFeature(geojson)) {\n index = updatePositions(geojson.geometry, isDeleted, index)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n index = updatePositions(geojson.geometries[i], isDeleted, index)\n }\n } else if (isLineString(geojson)) {\n index = updateLinePositions(geojson.coordinates, isDeleted, index)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n index = updateLinePositions(geojson.coordinates[i], isDeleted, index)\n }\n } else if (isPolygon(geojson)) {\n let remove = false\n ;[index, remove] = updateRingsPositions(geojson.coordinates, isDeleted, index)\n if (remove) geojson.coordinates.splice(0)\n } else if (isMultiPolygon(geojson)) {\n let offset = 0\n for (let remove = false, i = 0; i < geojson.coordinates.length; i++) {\n ;[index, remove] = updateRingsPositions(geojson.coordinates[i], isDeleted, index)\n if (remove) {\n offset++\n } else if (offset) {\n geojson.coordinates[i - offset] = geojson.coordinates[i]\n }\n }\n if (offset) geojson.coordinates.splice(geojson.coordinates.length - offset)\n }\n return index\n}\n\nfunction updateLinePositions(coordinates: Position[], isDeleted: Uint8Array, index: number): number {\n let offset = 0\n for (let i = 0; i < coordinates.length; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return index\n}\n\nfunction updateRingsPositions(coordinates: Position[][], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let remove = false, i = 0; i < coordinates.length; i++) {\n ;[index, remove] = updateRingPositions(coordinates[i], isDeleted, index)\n if (remove) {\n // skip interior rings if exterior ring is removed\n if (i === 0) {\n for (i = 1; i < coordinates.length; i++) {\n if (coordinates[i].length) index += coordinates[i].length - 1\n }\n // avoid alternating coordinates array if exterior ring is removed\n return [index, true]\n }\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return [index, false]\n}\n\nfunction updateRingPositions(coordinates: Position[], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let i = 0; i < coordinates.length - 1; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) {\n if (coordinates.length - 1 - offset < 3) {\n // avoid alternating coordinates array if ring is removed\n return [index, true]\n }\n coordinates.splice(coordinates.length - 1 - offset, offset + 1, coordinates[0])\n }\n return [index, false]\n}\n\nfunction collectPositions(geojson: GeoJsonObject, positions: Positions): void {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n collectPositions(geojson.features[i], positions)\n }\n } else if (isFeature(geojson)) {\n collectPositions(geojson.geometry, positions)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n collectPositions(geojson.geometries[i], positions)\n }\n } else if (isLineString(geojson)) {\n collectLinePositions(geojson.coordinates, positions)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectLinePositions(geojson.coordinates[i], positions)\n }\n } else if (isPolygon(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectRingPositions(geojson.coordinates[i], positions)\n }\n } else if (isMultiPolygon(geojson)) {\n for (let j, i = 0; i < geojson.coordinates.length; i++) {\n for (j = 0; j < geojson.coordinates[i].length; j++) {\n collectRingPositions(geojson.coordinates[i][j], positions)\n }\n }\n }\n}\n\nfunction collectLinePositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? -1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? -1 : p + i + 1)\n }\n}\n\nfunction collectRingPositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length - 1, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? p + n - 1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? p : p + i + 1)\n }\n}\n","import {\n GeoJsonObject,\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon,\n GeometryCollection,\n} from 'geojson'\n\nexport type FinitePositiveNumber = number & { readonly __type: unique symbol }\n\nexport function isFinitePositiveNumber(value: number): value is FinitePositiveNumber {\n return value != null && Number.isFinite(value) && value > 0\n}\n\nexport function isObject(value: object): value is object {\n return typeof value === 'object' && value !== null\n}\n\nexport function isFeature(value: GeoJsonObject): value is Feature {\n return isObject(value) && value?.type === 'Feature'\n}\n\nexport function isFeatureCollection(value: GeoJsonObject): value is FeatureCollection {\n return isObject(value) && value?.type === 'FeatureCollection'\n}\n\nexport function isLineString(value: GeoJsonObject): value is LineString {\n return isObject(value) && value?.type === 'LineString'\n}\n\nexport function isMultiLineString(value: GeoJsonObject): value is MultiLineString {\n return isObject(value) && value?.type === 'MultiLineString'\n}\n\nexport function isPolygon(value: GeoJsonObject): value is Polygon {\n return isObject(value) && value?.type === 'Polygon'\n}\n\nexport function isMultiPolygon(value: GeoJsonObject): value is MultiPolygon {\n return isObject(value) && value?.type === 'MultiPolygon'\n}\n\nexport function isGeometryCollection(value: GeoJsonObject): value is GeometryCollection {\n return isObject(value) && value?.type === 'GeometryCollection'\n}\n","import { Position } from 'geojson'\n\nexport type Positions = {\n coordinates: Position[]\n nextIndexes: number[]\n prevIndexes: number[]\n}\n\nexport type Groups = {\n sortIndexes: Uint32Array\n groupedFrom: Uint32Array\n groupedTo: Uint32Array\n}\n\nexport function groupPositions(coordinates: Position[]): Groups {\n const sortIndexes = new Uint32Array(coordinates.length)\n const groupedFrom = new Uint32Array(coordinates.length)\n const groupedTo = new Uint32Array(coordinates.length)\n for (let i = 0; i < coordinates.length; i++) {\n sortIndexes[i] = i\n }\n sortIndexes.sort((a, b) => {\n const deltaX = coordinates[a][0] - coordinates[b][0]\n if (deltaX) {\n return deltaX < 0 ? -1 : 1\n }\n const deltaY = coordinates[a][1] - coordinates[b][1]\n return deltaY < 0 ? -1 : deltaY > 0 ? 1 : 0\n })\n if (coordinates.length) {\n groupedTo[sortIndexes[coordinates.length - 1]] = groupedTo.length - 1\n }\n for (let i = 1, j = coordinates.length - 2; i < coordinates.length; i++, j--) {\n if (\n coordinates[sortIndexes[i]][0] !== coordinates[sortIndexes[i - 1]][0] ||\n coordinates[sortIndexes[i]][1] !== coordinates[sortIndexes[i - 1]][1]\n ) {\n groupedFrom[sortIndexes[i]] = i\n } else {\n groupedFrom[sortIndexes[i]] = groupedFrom[sortIndexes[i - 1]]\n }\n if (\n coordinates[sortIndexes[j]][0] !== coordinates[sortIndexes[j + 1]][0] ||\n coordinates[sortIndexes[j]][1] !== coordinates[sortIndexes[j + 1]][1]\n ) {\n groupedTo[sortIndexes[j]] = j\n } else {\n groupedTo[sortIndexes[j]] = groupedTo[sortIndexes[j + 1]]\n }\n }\n return {\n sortIndexes,\n groupedFrom,\n groupedTo,\n }\n}\n\nfunction getPositionArea(i: number, positions: Positions): number {\n return (\n Math.abs(\n positions.coordinates[i][0] *\n (positions.coordinates[positions.prevIndexes[i]][1] - positions.coordinates[positions.nextIndexes[i]][1]) +\n positions.coordinates[positions.prevIndexes[i]][0] *\n (positions.coordinates[positions.nextIndexes[i]][1] - positions.coordinates[i][1]) +\n positions.coordinates[positions.nextIndexes[i]][0] *\n (positions.coordinates[i][1] - positions.coordinates[positions.prevIndexes[i]][1]),\n ) / 2\n )\n}\n\nfunction heapcompare(a: number, b: number, priority: Float64Array, coordinates: Position[]): number {\n return priority[a] - priority[b] || coordinates[a][0] - coordinates[b][0] || coordinates[a][1] - coordinates[b][1]\n}\n\nfunction heapsink(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n 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\nexport function deletePositions(positions: Positions, groups: Groups, tolerance: number, fraction: number): Uint8Array {\n const n = positions.coordinates.length\n\n const isDeleted = new Uint8Array(n)\n let toDelete = Math.round(n * fraction)\n\n const candidatesByGroupFrom = new Uint32Array(n)\n const isCandidate = new Uint8Array(n)\n\n const heap = new Uint32Array(n + 1)\n const priority = new Float64Array(n)\n const heapRev = new Uint32Array(n)\n\n for (let i = 0; i < n; i++) {\n if (positions.prevIndexes[i] !== -1 && positions.nextIndexes[i] !== -1) {\n priority[i] = getPositionArea(i, positions)\n heap[0]++\n heap[heap[0]] = i\n heapRev[i] = heap[0]\n }\n }\n heapify(heap, heapRev, priority, positions.coordinates)\n\n let i: number\n while (heap[0]) {\n i = heappop(heap, heapRev, priority, positions.coordinates)\n\n if (isDeleted[i]) {\n continue\n }\n\n if (priority[i] >= tolerance && toDelete <= 0) {\n break\n }\n\n if (!isCandidate[i]) {\n isCandidate[i] = 1\n candidatesByGroupFrom[groups.groupedFrom[i]]++\n }\n\n if (candidatesByGroupFrom[groups.groupedFrom[i]] !== groups.groupedTo[i] - groups.groupedFrom[i] + 1) {\n continue\n }\n\n for (let k: number, j = groups.groupedFrom[i]; j <= groups.groupedTo[i]; j++) {\n k = groups.sortIndexes[j]\n if (isDeleted[k]) {\n continue\n }\n\n if (\n positions.prevIndexes[k] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[k]] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[positions.prevIndexes[k]]] === k\n ) {\n if (!isCandidate[positions.prevIndexes[k]]) {\n isCandidate[positions.prevIndexes[k]] = 1\n candidatesByGroupFrom[groups.groupedFrom[positions.prevIndexes[k]]]++\n }\n if (!isCandidate[positions.nextIndexes[k]]) {\n isCandidate[positions.nextIndexes[k]] = 1\n candidatesByGroupFrom[groups.groupedFrom[positions.nextIndexes[k]]]++\n }\n\n if (\n candidatesByGroupFrom[groups.groupedFrom[positions.prevIndexes[k]]] ===\n groups.groupedTo[positions.prevIndexes[k]] - groups.groupedFrom[positions.prevIndexes[k]] + 1 &&\n candidatesByGroupFrom[groups.groupedFrom[positions.nextIndexes[k]]] ===\n groups.groupedTo[positions.nextIndexes[k]] - groups.groupedFrom[positions.nextIndexes[k]] + 1\n ) {\n isDeleted[k] = 1\n isDeleted[positions.nextIndexes[k]] = 1\n isDeleted[positions.prevIndexes[k]] = 1\n toDelete -= 3\n j = groups.groupedFrom[i] - 1\n }\n } else {\n isDeleted[k] = 1\n toDelete--\n positions.prevIndexes[positions.nextIndexes[k]] = positions.prevIndexes[k]\n positions.nextIndexes[positions.prevIndexes[k]] = positions.nextIndexes[k]\n\n if (positions.prevIndexes[positions.prevIndexes[k]] !== -1) {\n priority[positions.prevIndexes[k]] = getPositionArea(positions.prevIndexes[k], positions)\n heapupdate(heap, heapRev, positions.prevIndexes[k], priority, positions.coordinates)\n }\n if (positions.nextIndexes[positions.nextIndexes[k]] !== -1) {\n priority[positions.nextIndexes[k]] = getPositionArea(positions.nextIndexes[k], positions)\n heapupdate(heap, heapRev, positions.nextIndexes[k], priority, positions.coordinates)\n }\n }\n }\n }\n return isDeleted\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GCaO,SAASI,EAAuBC,EAA8C,CACnF,OAAOA,GAAS,MAAQ,OAAO,SAASA,CAAK,GAAKA,EAAQ,CAC5D,CAEO,SAASC,EAASD,EAAgC,CACvD,OAAO,OAAOA,GAAU,UAAYA,IAAU,IAChD,CAEO,SAASE,EAAUF,EAAwC,CAChE,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,SAC5C,CAEO,SAASG,EAAoBH,EAAkD,CACpF,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,mBAC5C,CAEO,SAASI,EAAaJ,EAA2C,CACtE,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,YAC5C,CAEO,SAASK,EAAkBL,EAAgD,CAChF,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,iBAC5C,CAEO,SAASM,EAAUN,EAAwC,CAChE,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,SAC5C,CAEO,SAASO,EAAeP,EAA6C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AC/ER,EAAU,YAAY,KAAKmB,EAAYX,CAAC,CAAC,EACzCR,EAAU,YAAY,KAAKQ,IAAM,EAAI,GAAKgB,EAAIhB,EAAI,CAAC,EACnDR,EAAU,YAAY,KAAKQ,IAAM,EAAI,EAAI,GAAKgB,EAAIhB,EAAI,CAAC,CAE3D,CAEA,SAASc,EAAqBH,EAAyBnB,EAAsB,CAC3E,QAASwB,EAAIxB,EAAU,YAAY,OAAQ,EAAImB,EAAY,OAAS,EAAGX,EAAI,EAAGA,EAAI,EAAGA,IACnFR,EAAU,YAAY,KAAKmB,EAAYX,CAAC,CAAC,EACzCR,EAAU,YAAY,KAAKQ,IAAM,EAAIgB,EAAI,EAAI,EAAIA,EAAIhB,EAAI,CAAC,EAC1DR,EAAU,YAAY,KAAKQ,IAAM,EAAI,EAAIgB,EAAIA,EAAIhB,EAAI,CAAC,CAE1D","names":["index_exports","__export","index_default","__toCommonJS","isFinitePositiveNumber","value","isObject","isFeature","isFeatureCollection","isLineString","isMultiLineString","isPolygon","isMultiPolygon","isGeometryCollection","groupPositions","coordinates","sortIndexes","groupedFrom","groupedTo","i","a","b","deltaX","deltaY","j","getPositionArea","positions","heapcompare","priority","heapsink","heap","heapRev","l","r","t","heapswap","heapbubble","heapupdate","val","heappop","heapify","deletePositions","groups","tolerance","fraction","n","isDeleted","toDelete","candidatesByGroupFrom","isCandidate","k","index_default","geojson","options","isObject","tolerance","isFinitePositiveNumber","fraction","mutate","positions","collectPositions","updatePositions","deletePositions","groupPositions","isDeleted","index","isFeatureCollection","i","isFeature","isGeometryCollection","isLineString","updateLinePositions","isMultiLineString","isPolygon","remove","updateRingsPositions","isMultiPolygon","offset","coordinates","updateRingPositions","collectLinePositions","collectRingPositions","j","p"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/lib/typeGuards.ts","../src/lib/functions.ts"],"sourcesContent":["import { GeoJsonObject, Position } from 'geojson'\nimport {\n isObject,\n isFinitePositiveNumber,\n isFeature,\n isFeatureCollection,\n isLineString,\n isMultiLineString,\n isPolygon,\n isMultiPolygon,\n isGeometryCollection,\n} from '@lib/typeGuards'\nimport { deletePositions, groupPositions, type Positions } from '@lib/functions'\n\nexport type SimplifyOptions = {\n tolerance?: number\n fraction?: number\n mutate?: boolean\n}\n\nexport default function (geojson: GeoJsonObject, options: SimplifyOptions = {}): GeoJsonObject {\n // validate input data\n if (!isObject(geojson)) {\n throw new TypeError(\n `Expected provided GeoJSON to be an object, but received ${geojson === null ? 'null' : typeof geojson}.`,\n )\n }\n\n // validate options\n let tolerance = 0\n if (options.tolerance !== undefined) {\n if (!isFinitePositiveNumber(options.tolerance)) {\n throw new Error(`Expected provided tolerance to be a finite positive number, but received ${options.tolerance}.`)\n }\n tolerance = options.tolerance\n }\n let fraction = 0\n if (options.fraction !== undefined) {\n if (!isFinitePositiveNumber(options.fraction)) {\n throw new Error(`Expected provided fraction to be a finite positive number, but received ${options.fraction}.`)\n }\n if (options.fraction > 1) {\n throw new Error(`Expected provided fraction to be less or equal to 1, but received ${options.fraction}.`)\n }\n fraction = options.fraction\n }\n let mutate = true\n if (options.mutate !== undefined) {\n mutate = !!options.mutate\n }\n\n // exit if no simplification options provided\n if (tolerance === 0 && fraction === 0) {\n return geojson\n }\n\n if (!mutate) {\n geojson = structuredClone(geojson)\n }\n\n const positions: Positions = {\n coordinates: [],\n nextIndexes: [],\n prevIndexes: [],\n }\n collectPositions(geojson, positions)\n\n if (positions.coordinates.length) {\n updatePositions(geojson, deletePositions(positions, groupPositions(positions.coordinates), tolerance, fraction), 0)\n }\n\n return geojson\n}\nfunction updatePositions(geojson: GeoJsonObject, isDeleted: Uint8Array, index: number): number {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n index = updatePositions(geojson.features[i], isDeleted, index)\n }\n } else if (isFeature(geojson)) {\n index = updatePositions(geojson.geometry, isDeleted, index)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n index = updatePositions(geojson.geometries[i], isDeleted, index)\n }\n } else if (isLineString(geojson)) {\n index = updateLinePositions(geojson.coordinates, isDeleted, index)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n index = updateLinePositions(geojson.coordinates[i], isDeleted, index)\n }\n } else if (isPolygon(geojson)) {\n let remove = false\n ;[index, remove] = updateRingsPositions(geojson.coordinates, isDeleted, index)\n if (remove) geojson.coordinates.splice(0)\n } else if (isMultiPolygon(geojson)) {\n let offset = 0\n for (let remove = false, i = 0; i < geojson.coordinates.length; i++) {\n ;[index, remove] = updateRingsPositions(geojson.coordinates[i], isDeleted, index)\n if (remove) {\n offset++\n } else if (offset) {\n geojson.coordinates[i - offset] = geojson.coordinates[i]\n }\n }\n if (offset) geojson.coordinates.splice(geojson.coordinates.length - offset)\n }\n return index\n}\n\nfunction updateLinePositions(coordinates: Position[], isDeleted: Uint8Array, index: number): number {\n let offset = 0\n for (let i = 0; i < coordinates.length; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return index\n}\n\nfunction updateRingsPositions(coordinates: Position[][], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let remove = false, i = 0; i < coordinates.length; i++) {\n ;[index, remove] = updateRingPositions(coordinates[i], isDeleted, index)\n if (remove) {\n // skip interior rings if exterior ring is removed\n if (i === 0) {\n for (i = 1; i < coordinates.length; i++) {\n if (coordinates[i].length) index += coordinates[i].length - 1\n }\n // avoid alternating coordinates array if exterior ring is removed\n return [index, true]\n }\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return [index, false]\n}\n\nfunction updateRingPositions(coordinates: Position[], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let i = 0; i < coordinates.length - 1; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) {\n if (coordinates.length - 1 - offset < 3) {\n // avoid alternating coordinates array if ring is removed\n return [index, true]\n }\n coordinates.splice(coordinates.length - 1 - offset, offset + 1, coordinates[0])\n }\n return [index, false]\n}\n\nfunction collectPositions(geojson: GeoJsonObject, positions: Positions): void {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n collectPositions(geojson.features[i], positions)\n }\n } else if (isFeature(geojson)) {\n collectPositions(geojson.geometry, positions)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n collectPositions(geojson.geometries[i], positions)\n }\n } else if (isLineString(geojson)) {\n collectLinePositions(geojson.coordinates, positions)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectLinePositions(geojson.coordinates[i], positions)\n }\n } else if (isPolygon(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectRingPositions(geojson.coordinates[i], positions)\n }\n } else if (isMultiPolygon(geojson)) {\n for (let j, i = 0; i < geojson.coordinates.length; i++) {\n for (j = 0; j < geojson.coordinates[i].length; j++) {\n collectRingPositions(geojson.coordinates[i][j], positions)\n }\n }\n }\n}\n\nfunction collectLinePositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? -1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? -1 : p + i + 1)\n }\n}\n\nfunction collectRingPositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length - 1, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? p + n - 1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? p : p + i + 1)\n }\n}\n","import {\n GeoJsonObject,\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon,\n GeometryCollection,\n} from 'geojson'\n\nexport type FinitePositiveNumber = number & { readonly __type: unique symbol }\n\nexport function isFinitePositiveNumber(value: number): value is FinitePositiveNumber {\n return value != null && Number.isFinite(value) && value > 0\n}\n\nexport function isObject(value: object): value is object {\n return typeof value === 'object' && value !== null\n}\n\nexport function isFeature(value: GeoJsonObject): value is Feature {\n return isObject(value) && value?.type === 'Feature'\n}\n\nexport function isFeatureCollection(value: GeoJsonObject): value is FeatureCollection {\n return isObject(value) && value?.type === 'FeatureCollection'\n}\n\nexport function isLineString(value: GeoJsonObject): value is LineString {\n return isObject(value) && value?.type === 'LineString'\n}\n\nexport function isMultiLineString(value: GeoJsonObject): value is MultiLineString {\n return isObject(value) && value?.type === 'MultiLineString'\n}\n\nexport function isPolygon(value: GeoJsonObject): value is Polygon {\n return isObject(value) && value?.type === 'Polygon'\n}\n\nexport function isMultiPolygon(value: GeoJsonObject): value is MultiPolygon {\n return isObject(value) && value?.type === 'MultiPolygon'\n}\n\nexport function isGeometryCollection(value: GeoJsonObject): value is GeometryCollection {\n return isObject(value) && value?.type === 'GeometryCollection'\n}\n","import { Position } from 'geojson'\n\nexport type Positions = {\n coordinates: Position[]\n nextIndexes: number[]\n prevIndexes: number[]\n}\n\nexport type Groups = {\n groupOf: Uint32Array\n groupSize: Uint32Array\n nextInGroup: Uint32Array\n}\n\nexport function groupPositions(coordinates: Position[]): Groups {\n const groupOf = new Uint32Array(coordinates.length)\n const groupSize = new Uint32Array(coordinates.length)\n const nextInGroup = new Uint32Array(coordinates.length)\n const groupTail = new Uint32Array(coordinates.length)\n const groupsByX = new Map<number, number | Map<number, number>>()\n for (let i = 0; i < coordinates.length; i++) {\n const x = coordinates[i][0]\n const y = coordinates[i][1]\n const byX = groupsByX.get(x)\n let root: number\n if (byX === undefined) {\n root = i\n groupsByX.set(x, i)\n } else if (typeof byX === 'number') {\n if (coordinates[byX][1] === y) {\n root = byX\n } else {\n root = i\n const byY = new Map<number, number>()\n byY.set(coordinates[byX][1], byX)\n byY.set(y, i)\n groupsByX.set(x, byY)\n }\n } else {\n const existing = byX.get(y)\n if (existing === undefined) {\n root = i\n byX.set(y, i)\n } else {\n root = existing\n }\n }\n groupOf[i] = root\n if (root === i) {\n groupSize[root] = 1\n groupTail[root] = i\n } else {\n groupSize[root]++\n nextInGroup[groupTail[root]] = i\n groupTail[root] = i\n }\n nextInGroup[i] = coordinates.length\n }\n return {\n groupOf,\n groupSize,\n nextInGroup,\n }\n}\n\nfunction getPositionArea(i: number, positions: Positions): number {\n return (\n Math.abs(\n positions.coordinates[i][0] *\n (positions.coordinates[positions.prevIndexes[i]][1] - positions.coordinates[positions.nextIndexes[i]][1]) +\n positions.coordinates[positions.prevIndexes[i]][0] *\n (positions.coordinates[positions.nextIndexes[i]][1] - positions.coordinates[i][1]) +\n positions.coordinates[positions.nextIndexes[i]][0] *\n (positions.coordinates[i][1] - positions.coordinates[positions.prevIndexes[i]][1]),\n ) / 2\n )\n}\n\nfunction heapcompare(a: number, b: number, priority: Float64Array, coordinates: Position[]): number {\n return priority[a] - priority[b] || coordinates[a][0] - coordinates[b][0] || coordinates[a][1] - coordinates[b][1]\n}\n\nfunction heapsink(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n const value = heap[i]\n let l: number, r: number, t: number\n let selected: number\n while (true) {\n t = i\n selected = value\n if ((l = i << 1) <= heap[0] && heapcompare(selected, heap[l], priority, coordinates) > 0) {\n t = l\n selected = heap[l]\n }\n if ((r = l + 1) <= heap[0] && heapcompare(selected, heap[r], priority, coordinates) > 0) t = r\n if (i === t) break\n heap[i] = heap[t]\n heapRev[heap[i]] = i\n i = t\n }\n heap[i] = value\n heapRev[value] = i\n return i\n}\n\nfunction heapbubble(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n let t: number\n while (i > 1) {\n t = i >>> 1\n if (i === t || heapcompare(heap[t], heap[i], priority, coordinates) <= 0) break\n heapswap(heap, heapRev, i, t)\n i = t\n }\n return i\n}\n\nfunction heapupdate(\n heap: Uint32Array,\n heapRev: Uint32Array,\n val: number,\n priority: Float64Array,\n coordinates: Position[],\n): void {\n heapbubble(heap, heapRev, heapsink(heap, heapRev, heapRev[val], priority, coordinates), priority, coordinates)\n}\n\nfunction heapswap(heap: Uint32Array, heapRev: Uint32Array, i: number, t: number): void {\n heapRev[heap[i]] = t\n heapRev[heap[t]] = i\n ;[heap[i], heap[t]] = [heap[t], heap[i]]\n}\n\nfunction heappop(heap: Uint32Array, heapRev: Uint32Array, priority: Float64Array, coordinates: Position[]): number {\n if (heap[0] > 1) {\n heapswap(heap, heapRev, 1, heap[0])\n heap[0]--\n heapsink(heap, heapRev, 1, priority, coordinates)\n return heap[heap[0] + 1]\n } else if (heap[0] === 1) {\n heap[0]--\n return heap[1]\n }\n return -1\n}\n\nfunction heapify(heap: Uint32Array, heapRev: Uint32Array, priority: Float64Array, coordinates: Position[]): void {\n for (let i = heap[0] >>> 1; i > 0; i--) {\n heapsink(heap, heapRev, i, priority, coordinates)\n }\n}\n\nexport function deletePositions(positions: Positions, groups: Groups, tolerance: number, fraction: number): Uint8Array {\n const n = positions.coordinates.length\n\n const isDeleted = new Uint8Array(n)\n let toDelete = Math.round(n * fraction)\n\n const candidatesByGroup = new Uint32Array(n)\n const isCandidate = new Uint8Array(n)\n\n const heap = new Uint32Array(n + 1)\n const priority = new Float64Array(n)\n const heapRev = new Uint32Array(n)\n\n for (let i = 0; i < n; i++) {\n if (positions.prevIndexes[i] !== -1 && positions.nextIndexes[i] !== -1) {\n priority[i] = getPositionArea(i, positions)\n heap[0]++\n heap[heap[0]] = i\n heapRev[i] = heap[0]\n }\n }\n heapify(heap, heapRev, priority, positions.coordinates)\n\n let i: number\n while (heap[0]) {\n i = heappop(heap, heapRev, priority, positions.coordinates)\n\n if (isDeleted[i]) {\n continue\n }\n\n if (priority[i] >= tolerance && toDelete <= 0) {\n break\n }\n\n const groupId = groups.groupOf[i]\n if (!isCandidate[i]) {\n isCandidate[i] = 1\n candidatesByGroup[groupId]++\n }\n\n if (candidatesByGroup[groupId] !== groups.groupSize[groupId]) {\n continue\n }\n\n let k = groupId\n while (k < n) {\n if (isDeleted[k]) {\n k = groups.nextInGroup[k]\n continue\n }\n\n if (\n positions.prevIndexes[k] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[k]] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[positions.prevIndexes[k]]] === k\n ) {\n if (!isCandidate[positions.prevIndexes[k]]) {\n isCandidate[positions.prevIndexes[k]] = 1\n candidatesByGroup[groups.groupOf[positions.prevIndexes[k]]]++\n }\n if (!isCandidate[positions.nextIndexes[k]]) {\n isCandidate[positions.nextIndexes[k]] = 1\n candidatesByGroup[groups.groupOf[positions.nextIndexes[k]]]++\n }\n\n if (\n candidatesByGroup[groups.groupOf[positions.prevIndexes[k]]] ===\n groups.groupSize[groups.groupOf[positions.prevIndexes[k]]] &&\n candidatesByGroup[groups.groupOf[positions.nextIndexes[k]]] ===\n groups.groupSize[groups.groupOf[positions.nextIndexes[k]]]\n ) {\n isDeleted[k] = 1\n isDeleted[positions.nextIndexes[k]] = 1\n isDeleted[positions.prevIndexes[k]] = 1\n toDelete -= 3\n k = groupId\n continue\n }\n } else {\n isDeleted[k] = 1\n toDelete--\n positions.prevIndexes[positions.nextIndexes[k]] = positions.prevIndexes[k]\n positions.nextIndexes[positions.prevIndexes[k]] = positions.nextIndexes[k]\n\n if (positions.prevIndexes[positions.prevIndexes[k]] !== -1) {\n priority[positions.prevIndexes[k]] = getPositionArea(positions.prevIndexes[k], positions)\n heapupdate(heap, heapRev, positions.prevIndexes[k], priority, positions.coordinates)\n }\n if (positions.nextIndexes[positions.nextIndexes[k]] !== -1) {\n priority[positions.nextIndexes[k]] = getPositionArea(positions.nextIndexes[k], positions)\n heapupdate(heap, heapRev, positions.nextIndexes[k], priority, positions.coordinates)\n }\n }\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AI,EAAGA,EAAIf,EAAQ,YAAY,OAAQe,IAC9Ca,EAAqB5B,EAAQ,YAAYe,CAAC,EAAGR,CAAS,UAE/Cc,EAAUrB,CAAO,EAC1B,QAASe,EAAI,EAAGA,EAAIf,EAAQ,YAAY,OAAQe,IAC9Cc,EAAqB7B,EAAQ,YAAYe,CAAC,EAAGR,CAAS,UAE/CiB,EAAexB,CAAO,EAC/B,QAAS8B,EAAGf,EAAI,EAAGA,EAAIf,EAAQ,YAAY,OAAQe,IACjD,IAAKe,EAAI,EAAGA,EAAI9B,EAAQ,YAAYe,CAAC,EAAE,OAAQe,IAC7CD,EAAqB7B,EAAQ,YAAYe,CAAC,EAAEe,CAAC,EAAGvB,CAAS,CAIjE,CAEA,SAASqB,EAAqBF,EAAyBnB,EAAsB,CAC3E,QAASwB,EAAIxB,EAAU,YAAY,OAAQ,EAAImB,EAAY,OAAQX,EAAI,EAAGA,EAAI,EAAGA,IAC/ER,EAAU,YAAY,KAAKmB,EAAYX,CAAC,CAAC,EACzCR,EAAU,YAAY,KAAKQ,IAAM,EAAI,GAAKgB,EAAIhB,EAAI,CAAC,EACnDR,EAAU,YAAY,KAAKQ,IAAM,EAAI,EAAI,GAAKgB,EAAIhB,EAAI,CAAC,CAE3D,CAEA,SAASc,EAAqBH,EAAyBnB,EAAsB,CAC3E,QAASwB,EAAIxB,EAAU,YAAY,OAAQ,EAAImB,EAAY,OAAS,EAAGX,EAAI,EAAGA,EAAI,EAAGA,IACnFR,EAAU,YAAY,KAAKmB,EAAYX,CAAC,CAAC,EACzCR,EAAU,YAAY,KAAKQ,IAAM,EAAIgB,EAAI,EAAI,EAAIA,EAAIhB,EAAI,CAAC,EAC1DR,EAAU,YAAY,KAAKQ,IAAM,EAAI,EAAIgB,EAAIA,EAAIhB,EAAI,CAAC,CAE1D","names":["index_exports","__export","index_default","__toCommonJS","isFinitePositiveNumber","value","isObject","isFeature","isFeatureCollection","isLineString","isMultiLineString","isPolygon","isMultiPolygon","isGeometryCollection","groupPositions","coordinates","groupOf","groupSize","nextInGroup","groupTail","groupsByX","i","x","y","byX","root","byY","existing","getPositionArea","positions","heapcompare","a","b","priority","heapsink","heap","heapRev","value","l","r","t","selected","heapbubble","heapswap","heapupdate","val","heappop","heapify","deletePositions","groups","tolerance","fraction","n","isDeleted","toDelete","candidatesByGroup","isCandidate","groupId","k","index_default","geojson","options","isObject","tolerance","isFinitePositiveNumber","fraction","mutate","positions","collectPositions","updatePositions","deletePositions","groupPositions","isDeleted","index","isFeatureCollection","i","isFeature","isGeometryCollection","isLineString","updateLinePositions","isMultiLineString","isPolygon","remove","updateRingsPositions","isMultiPolygon","offset","coordinates","updateRingPositions","collectLinePositions","collectRingPositions","j","p"]}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- function v(e){return e!=null&&Number.isFinite(e)&&e>0}function d(e){return typeof e=="object"&&e!==null}function A(e){return d(e)&&e?.type==="Feature"}function F(e){return d(e)&&e?.type==="FeatureCollection"}function h(e){return d(e)&&e?.type==="LineString"}function U(e){return d(e)&&e?.type==="MultiLineString"}function g(e){return d(e)&&e?.type==="Polygon"}function G(e){return d(e)&&e?.type==="MultiPolygon"}function w(e){return d(e)&&e?.type==="GeometryCollection"}function L(e){let r=new Uint32Array(e.length),t=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let l=0;l<e.length;l++)r[l]=l;r.sort((l,u)=>{let m=e[l][0]-e[u][0];if(m)return m<0?-1:1;let f=e[l][1]-e[u][1];return f<0?-1:f>0?1:0}),e.length&&(n[r[e.length-1]]=n.length-1);for(let l=1,u=e.length-2;l<e.length;l++,u--)e[r[l]][0]!==e[r[l-1]][0]||e[r[l]][1]!==e[r[l-1]][1]?t[r[l]]=l:t[r[l]]=t[r[l-1]],e[r[u]][0]!==e[r[u+1]][0]||e[r[u]][1]!==e[r[u+1]][1]?n[r[u]]=u:n[r[u]]=n[r[u+1]];return{sortIndexes:r,groupedFrom:t,groupedTo:n}}function O(e,r){return Math.abs(r.coordinates[e][0]*(r.coordinates[r.prevIndexes[e]][1]-r.coordinates[r.nextIndexes[e]][1])+r.coordinates[r.prevIndexes[e]][0]*(r.coordinates[r.nextIndexes[e]][1]-r.coordinates[e][1])+r.coordinates[r.nextIndexes[e]][0]*(r.coordinates[e][1]-r.coordinates[r.prevIndexes[e]][1]))/2}function J(e,r,t,n){return t[e]-t[r]||n[e][0]-n[r][0]||n[e][1]-n[r][1]}function s(e,r,t,n,l){let u,m,f;for(;f=t,(u=t<<1)<=e[0]&&J(e[f],e[u],n,l)>0&&(f=u),(m=u+1)<=e[0]&&J(e[f],e[m],n,l)>0&&(f=m),t!==f;)S(e,r,t,f),t=f;return t}function k(e,r,t,n,l){let u;for(;t>1&&(u=t>>>1,!(t===u||J(e[u],e[t],n,l)<=0));)S(e,r,t,u),t=u;return t}function C(e,r,t,n,l){k(e,r,s(e,r,r[t],n,l),n,l)}function S(e,r,t,n){r[e[t]]=n,r[e[n]]=t,[e[t],e[n]]=[e[n],e[t]]}function $(e,r,t,n){return e[0]>1?(S(e,r,1,e[0]),e[0]--,s(e,r,1,t,n),e[e[0]+1]):e[0]===1?(e[0]--,e[1]):-1}function q(e,r,t,n){for(let l=e[0]>>>1;l>0;l--)s(e,r,l,t,n)}function M(e,r,t,n){let l=e.coordinates.length,u=new Uint8Array(l),m=Math.round(l*n),f=new Uint32Array(l),b=new Uint8Array(l),o=new Uint32Array(l+1),a=new Float64Array(l),x=new Uint32Array(l);for(let i=0;i<l;i++)e.prevIndexes[i]!==-1&&e.nextIndexes[i]!==-1&&(a[i]=O(i,e),o[0]++,o[o[0]]=i,x[i]=o[0]);q(o,x,a,e.coordinates);let c;for(;o[0];)if(c=$(o,x,a,e.coordinates),!u[c]){if(a[c]>=t&&m<=0)break;if(b[c]||(b[c]=1,f[r.groupedFrom[c]]++),f[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],!u[i]&&(e.prevIndexes[i]!==-1&&e.prevIndexes[e.prevIndexes[i]]!==-1&&e.prevIndexes[e.prevIndexes[e.prevIndexes[i]]]===i?(b[e.prevIndexes[i]]||(b[e.prevIndexes[i]]=1,f[r.groupedFrom[e.prevIndexes[i]]]++),b[e.nextIndexes[i]]||(b[e.nextIndexes[i]]=1,f[r.groupedFrom[e.nextIndexes[i]]]++),f[r.groupedFrom[e.prevIndexes[i]]]===r.groupedTo[e.prevIndexes[i]]-r.groupedFrom[e.prevIndexes[i]]+1&&f[r.groupedFrom[e.nextIndexes[i]]]===r.groupedTo[e.nextIndexes[i]]-r.groupedFrom[e.nextIndexes[i]]+1&&(u[i]=1,u[e.nextIndexes[i]]=1,u[e.prevIndexes[i]]=1,m-=3,y=r.groupedFrom[c]-1)):(u[i]=1,m--,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]]=O(e.prevIndexes[i],e),C(o,x,e.prevIndexes[i],a,e.coordinates)),e.nextIndexes[e.nextIndexes[i]]!==-1&&(a[e.nextIndexes[i]]=O(e.nextIndexes[i],e),C(o,x,e.nextIndexes[i],a,e.coordinates))))}return u}function H(e,r={}){if(!d(e))throw new TypeError(`Expected provided GeoJSON to be an object, but received ${e===null?"null":typeof e}.`);let t=0;if(r.tolerance!==void 0){if(!v(r.tolerance))throw new Error(`Expected provided tolerance to be a finite positive number, but received ${r.tolerance}.`);t=r.tolerance}let n=0;if(r.fraction!==void 0){if(!v(r.fraction))throw new Error(`Expected provided fraction to be a finite positive number, but received ${r.fraction}.`);if(r.fraction>1)throw new Error(`Expected provided fraction to be less or equal to 1, but received ${r.fraction}.`);n=r.fraction}let l=!0;if(r.mutate!==void 0&&(l=!!r.mutate),t===0&&n===0)return e;l||(e=structuredClone(e));let u={coordinates:[],nextIndexes:[],prevIndexes:[]};return P(e,u),u.coordinates.length&&I(e,M(u,L(u.coordinates),t,n),0),e}function I(e,r,t){if(F(e))for(let n=0;n<e.features.length;n++)t=I(e.features[n],r,t);else if(A(e))t=I(e.geometry,r,t);else if(w(e))for(let n=0;n<e.geometries.length;n++)t=I(e.geometries[n],r,t);else if(h(e))t=p(e.coordinates,r,t);else if(U(e))for(let n=0;n<e.coordinates.length;n++)t=p(e.coordinates[n],r,t);else if(g(e)){let n=!1;[t,n]=E(e.coordinates,r,t),n&&e.coordinates.splice(0)}else if(G(e)){let n=0;for(let l=!1,u=0;u<e.coordinates.length;u++)[t,l]=E(e.coordinates[u],r,t),l?n++:n&&(e.coordinates[u-n]=e.coordinates[u]);n&&e.coordinates.splice(e.coordinates.length-n)}return t}function p(e,r,t){let n=0;for(let l=0;l<e.length;l++)r[t]?n++:n&&(e[l-n]=e[l]),t++;return n&&e.splice(e.length-n),t}function E(e,r,t){let n=0;for(let l=!1,u=0;u<e.length;u++)if([t,l]=_(e[u],r,t),l){if(u===0){for(u=1;u<e.length;u++)e[u].length&&(t+=e[u].length-1);return[t,!0]}n++}else n&&(e[u-n]=e[u]);return n&&e.splice(e.length-n),[t,!1]}function _(e,r,t){let n=0;for(let l=0;l<e.length-1;l++)r[t]?n++:n&&(e[l-n]=e[l]),t++;if(n){if(e.length-1-n<3)return[t,!0];e.splice(e.length-1-n,n+1,e[0])}return[t,!1]}function P(e,r){if(F(e))for(let t=0;t<e.features.length;t++)P(e.features[t],r);else if(A(e))P(e.geometry,r);else if(w(e))for(let t=0;t<e.geometries.length;t++)P(e.geometries[t],r);else if(h(e))T(e.coordinates,r);else if(U(e))for(let t=0;t<e.coordinates.length;t++)T(e.coordinates[t],r);else if(g(e))for(let t=0;t<e.coordinates.length;t++)N(e.coordinates[t],r);else if(G(e))for(let t,n=0;n<e.coordinates.length;n++)for(t=0;t<e.coordinates[n].length;t++)N(e.coordinates[n][t],r)}function T(e,r){for(let t=r.coordinates.length,n=e.length,l=0;l<n;l++)r.coordinates.push(e[l]),r.prevIndexes.push(l===0?-1:t+l-1),r.nextIndexes.push(l===n-1?-1:t+l+1)}function N(e,r){for(let t=r.coordinates.length,n=e.length-1,l=0;l<n;l++)r.coordinates.push(e[l]),r.prevIndexes.push(l===0?t+n-1:t+l-1),r.nextIndexes.push(l===n-1?t:t+l+1)}export{H as default};
1
+ function v(e){return e!=null&&Number.isFinite(e)&&e>0}function d(e){return typeof e=="object"&&e!==null}function s(e){return d(e)&&e?.type==="Feature"}function A(e){return d(e)&&e?.type==="FeatureCollection"}function U(e){return d(e)&&e?.type==="LineString"}function G(e){return d(e)&&e?.type==="MultiLineString"}function O(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 M(e){let r=new Uint32Array(e.length),t=new Uint32Array(e.length),n=new Uint32Array(e.length),u=new Uint32Array(e.length),l=new Map;for(let f=0;f<e.length;f++){let b=e[f][0],a=e[f][1],c=l.get(b),o;if(c===void 0)o=f,l.set(b,f);else if(typeof c=="number")if(e[c][1]===a)o=c;else{o=f;let y=new Map;y.set(e[c][1],c),y.set(a,f),l.set(b,y)}else{let y=c.get(a);y===void 0?(o=f,c.set(a,f)):o=y}r[f]=o,o===f?(t[o]=1,u[o]=f):(t[o]++,n[u[o]]=f,u[o]=f),n[f]=e.length}return{groupOf:r,groupSize:t,nextInGroup:n}}function w(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 F(e,r,t,n){return t[e]-t[r]||n[e][0]-n[r][0]||n[e][1]-n[r][1]}function S(e,r,t,n,u){let l=e[t],f,b,a,c;for(;a=t,c=l,(f=t<<1)<=e[0]&&F(c,e[f],n,u)>0&&(a=f,c=e[f]),(b=f+1)<=e[0]&&F(c,e[b],n,u)>0&&(a=b),t!==a;)e[t]=e[a],r[e[t]]=t,t=a;return e[t]=l,r[l]=t,t}function z(e,r,t,n,u){let l;for(;t>1&&(l=t>>>1,!(t===l||F(e[l],e[t],n,u)<=0));)J(e,r,t,l),t=l;return t}function p(e,r,t,n,u){z(e,r,S(e,r,r[t],n,u),n,u)}function J(e,r,t,n){r[e[t]]=n,r[e[n]]=t,[e[t],e[n]]=[e[n],e[t]]}function $(e,r,t,n){return e[0]>1?(J(e,r,1,e[0]),e[0]--,S(e,r,1,t,n),e[e[0]+1]):e[0]===1?(e[0]--,e[1]):-1}function q(e,r,t,n){for(let u=e[0]>>>1;u>0;u--)S(e,r,u,t,n)}function C(e,r,t,n){let u=e.coordinates.length,l=new Uint8Array(u),f=Math.round(u*n),b=new Uint32Array(u),a=new Uint8Array(u),c=new Uint32Array(u+1),o=new Float64Array(u),y=new Uint32Array(u);for(let m=0;m<u;m++)e.prevIndexes[m]!==-1&&e.nextIndexes[m]!==-1&&(o[m]=w(m,e),c[0]++,c[c[0]]=m,y[m]=c[0]);q(c,y,o,e.coordinates);let x;for(;c[0];){if(x=$(c,y,o,e.coordinates),l[x])continue;if(o[x]>=t&&f<=0)break;let m=r.groupOf[x];if(a[x]||(a[x]=1,b[m]++),b[m]!==r.groupSize[m])continue;let i=m;for(;i<u;){if(l[i]){i=r.nextInGroup[i];continue}if(e.prevIndexes[i]!==-1&&e.prevIndexes[e.prevIndexes[i]]!==-1&&e.prevIndexes[e.prevIndexes[e.prevIndexes[i]]]===i){if(a[e.prevIndexes[i]]||(a[e.prevIndexes[i]]=1,b[r.groupOf[e.prevIndexes[i]]]++),a[e.nextIndexes[i]]||(a[e.nextIndexes[i]]=1,b[r.groupOf[e.nextIndexes[i]]]++),b[r.groupOf[e.prevIndexes[i]]]===r.groupSize[r.groupOf[e.prevIndexes[i]]]&&b[r.groupOf[e.nextIndexes[i]]]===r.groupSize[r.groupOf[e.nextIndexes[i]]]){l[i]=1,l[e.nextIndexes[i]]=1,l[e.prevIndexes[i]]=1,f-=3,i=m;continue}}else l[i]=1,f--,e.prevIndexes[e.nextIndexes[i]]=e.prevIndexes[i],e.nextIndexes[e.prevIndexes[i]]=e.nextIndexes[i],e.prevIndexes[e.prevIndexes[i]]!==-1&&(o[e.prevIndexes[i]]=w(e.prevIndexes[i],e),p(c,y,e.prevIndexes[i],o,e.coordinates)),e.nextIndexes[e.nextIndexes[i]]!==-1&&(o[e.nextIndexes[i]]=w(e.nextIndexes[i],e),p(c,y,e.nextIndexes[i],o,e.coordinates));i=r.nextInGroup[i]}}return l}function H(e,r={}){if(!d(e))throw new TypeError(`Expected provided GeoJSON to be an object, but received ${e===null?"null":typeof e}.`);let t=0;if(r.tolerance!==void 0){if(!v(r.tolerance))throw new Error(`Expected provided tolerance to be a finite positive number, but received ${r.tolerance}.`);t=r.tolerance}let n=0;if(r.fraction!==void 0){if(!v(r.fraction))throw new Error(`Expected provided fraction to be a finite positive number, but received ${r.fraction}.`);if(r.fraction>1)throw new Error(`Expected provided fraction to be less or equal to 1, but received ${r.fraction}.`);n=r.fraction}let u=!0;if(r.mutate!==void 0&&(u=!!r.mutate),t===0&&n===0)return e;u||(e=structuredClone(e));let l={coordinates:[],nextIndexes:[],prevIndexes:[]};return P(e,l),l.coordinates.length&&I(e,C(l,M(l.coordinates),t,n),0),e}function I(e,r,t){if(A(e))for(let n=0;n<e.features.length;n++)t=I(e.features[n],r,t);else if(s(e))t=I(e.geometry,r,t);else if(g(e))for(let n=0;n<e.geometries.length;n++)t=I(e.geometries[n],r,t);else if(U(e))t=L(e.coordinates,r,t);else if(G(e))for(let n=0;n<e.coordinates.length;n++)t=L(e.coordinates[n],r,t);else if(O(e)){let n=!1;[t,n]=E(e.coordinates,r,t),n&&e.coordinates.splice(0)}else if(h(e)){let n=0;for(let u=!1,l=0;l<e.coordinates.length;l++)[t,u]=E(e.coordinates[l],r,t),u?n++:n&&(e.coordinates[l-n]=e.coordinates[l]);n&&e.coordinates.splice(e.coordinates.length-n)}return t}function L(e,r,t){let n=0;for(let u=0;u<e.length;u++)r[t]?n++:n&&(e[u-n]=e[u]),t++;return n&&e.splice(e.length-n),t}function E(e,r,t){let n=0;for(let u=!1,l=0;l<e.length;l++)if([t,u]=B(e[l],r,t),u){if(l===0){for(l=1;l<e.length;l++)e[l].length&&(t+=e[l].length-1);return[t,!0]}n++}else n&&(e[l-n]=e[l]);return n&&e.splice(e.length-n),[t,!1]}function B(e,r,t){let n=0;for(let u=0;u<e.length-1;u++)r[t]?n++:n&&(e[u-n]=e[u]),t++;if(n){if(e.length-1-n<3)return[t,!0];e.splice(e.length-1-n,n+1,e[0])}return[t,!1]}function P(e,r){if(A(e))for(let t=0;t<e.features.length;t++)P(e.features[t],r);else if(s(e))P(e.geometry,r);else if(g(e))for(let t=0;t<e.geometries.length;t++)P(e.geometries[t],r);else if(U(e))N(e.coordinates,r);else if(G(e))for(let t=0;t<e.coordinates.length;t++)N(e.coordinates[t],r);else if(O(e))for(let t=0;t<e.coordinates.length;t++)k(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++)k(e.coordinates[n][t],r)}function N(e,r){for(let t=r.coordinates.length,n=e.length,u=0;u<n;u++)r.coordinates.push(e[u]),r.prevIndexes.push(u===0?-1:t+u-1),r.nextIndexes.push(u===n-1?-1:t+u+1)}function k(e,r){for(let t=r.coordinates.length,n=e.length-1,u=0;u<n;u++)r.coordinates.push(e[u]),r.prevIndexes.push(u===0?t+n-1:t+u-1),r.nextIndexes.push(u===n-1?t:t+u+1)}export{H as default};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lib/typeGuards.ts","../src/lib/functions.ts","../src/index.ts"],"sourcesContent":["import {\n GeoJsonObject,\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon,\n GeometryCollection,\n} from 'geojson'\n\nexport type FinitePositiveNumber = number & { readonly __type: unique symbol }\n\nexport function isFinitePositiveNumber(value: number): value is FinitePositiveNumber {\n return value != null && Number.isFinite(value) && value > 0\n}\n\nexport function isObject(value: object): value is object {\n return typeof value === 'object' && value !== null\n}\n\nexport function isFeature(value: GeoJsonObject): value is Feature {\n return isObject(value) && value?.type === 'Feature'\n}\n\nexport function isFeatureCollection(value: GeoJsonObject): value is FeatureCollection {\n return isObject(value) && value?.type === 'FeatureCollection'\n}\n\nexport function isLineString(value: GeoJsonObject): value is LineString {\n return isObject(value) && value?.type === 'LineString'\n}\n\nexport function isMultiLineString(value: GeoJsonObject): value is MultiLineString {\n return isObject(value) && value?.type === 'MultiLineString'\n}\n\nexport function isPolygon(value: GeoJsonObject): value is Polygon {\n return isObject(value) && value?.type === 'Polygon'\n}\n\nexport function isMultiPolygon(value: GeoJsonObject): value is MultiPolygon {\n return isObject(value) && value?.type === 'MultiPolygon'\n}\n\nexport function isGeometryCollection(value: GeoJsonObject): value is GeometryCollection {\n return isObject(value) && value?.type === 'GeometryCollection'\n}\n","import { Position } from 'geojson'\n\nexport type Positions = {\n coordinates: Position[]\n nextIndexes: number[]\n prevIndexes: number[]\n}\n\nexport type Groups = {\n sortIndexes: Uint32Array\n groupedFrom: Uint32Array\n groupedTo: Uint32Array\n}\n\nexport function groupPositions(coordinates: Position[]): Groups {\n const sortIndexes = new Uint32Array(coordinates.length)\n const groupedFrom = new Uint32Array(coordinates.length)\n const groupedTo = new Uint32Array(coordinates.length)\n for (let i = 0; i < coordinates.length; i++) {\n sortIndexes[i] = i\n }\n sortIndexes.sort((a, b) => {\n const deltaX = coordinates[a][0] - coordinates[b][0]\n if (deltaX) {\n return deltaX < 0 ? -1 : 1\n }\n const deltaY = coordinates[a][1] - coordinates[b][1]\n return deltaY < 0 ? -1 : deltaY > 0 ? 1 : 0\n })\n if (coordinates.length) {\n groupedTo[sortIndexes[coordinates.length - 1]] = groupedTo.length - 1\n }\n for (let i = 1, j = coordinates.length - 2; i < coordinates.length; i++, j--) {\n if (\n coordinates[sortIndexes[i]][0] !== coordinates[sortIndexes[i - 1]][0] ||\n coordinates[sortIndexes[i]][1] !== coordinates[sortIndexes[i - 1]][1]\n ) {\n groupedFrom[sortIndexes[i]] = i\n } else {\n groupedFrom[sortIndexes[i]] = groupedFrom[sortIndexes[i - 1]]\n }\n if (\n coordinates[sortIndexes[j]][0] !== coordinates[sortIndexes[j + 1]][0] ||\n coordinates[sortIndexes[j]][1] !== coordinates[sortIndexes[j + 1]][1]\n ) {\n groupedTo[sortIndexes[j]] = j\n } else {\n groupedTo[sortIndexes[j]] = groupedTo[sortIndexes[j + 1]]\n }\n }\n return {\n sortIndexes,\n groupedFrom,\n groupedTo,\n }\n}\n\nfunction getPositionArea(i: number, positions: Positions): number {\n return (\n Math.abs(\n positions.coordinates[i][0] *\n (positions.coordinates[positions.prevIndexes[i]][1] - positions.coordinates[positions.nextIndexes[i]][1]) +\n positions.coordinates[positions.prevIndexes[i]][0] *\n (positions.coordinates[positions.nextIndexes[i]][1] - positions.coordinates[i][1]) +\n positions.coordinates[positions.nextIndexes[i]][0] *\n (positions.coordinates[i][1] - positions.coordinates[positions.prevIndexes[i]][1]),\n ) / 2\n )\n}\n\nfunction heapcompare(a: number, b: number, priority: Float64Array, coordinates: Position[]): number {\n return priority[a] - priority[b] || coordinates[a][0] - coordinates[b][0] || coordinates[a][1] - coordinates[b][1]\n}\n\nfunction heapsink(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n 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\nexport function deletePositions(positions: Positions, groups: Groups, tolerance: number, fraction: number): Uint8Array {\n const n = positions.coordinates.length\n\n const isDeleted = new Uint8Array(n)\n let toDelete = Math.round(n * fraction)\n\n const candidatesByGroupFrom = new Uint32Array(n)\n const isCandidate = new Uint8Array(n)\n\n const heap = new Uint32Array(n + 1)\n const priority = new Float64Array(n)\n const heapRev = new Uint32Array(n)\n\n for (let i = 0; i < n; i++) {\n if (positions.prevIndexes[i] !== -1 && positions.nextIndexes[i] !== -1) {\n priority[i] = getPositionArea(i, positions)\n heap[0]++\n heap[heap[0]] = i\n heapRev[i] = heap[0]\n }\n }\n heapify(heap, heapRev, priority, positions.coordinates)\n\n let i: number\n while (heap[0]) {\n i = heappop(heap, heapRev, priority, positions.coordinates)\n\n if (isDeleted[i]) {\n continue\n }\n\n if (priority[i] >= tolerance && toDelete <= 0) {\n break\n }\n\n if (!isCandidate[i]) {\n isCandidate[i] = 1\n candidatesByGroupFrom[groups.groupedFrom[i]]++\n }\n\n if (candidatesByGroupFrom[groups.groupedFrom[i]] !== groups.groupedTo[i] - groups.groupedFrom[i] + 1) {\n continue\n }\n\n for (let k: number, j = groups.groupedFrom[i]; j <= groups.groupedTo[i]; j++) {\n k = groups.sortIndexes[j]\n if (isDeleted[k]) {\n continue\n }\n\n if (\n positions.prevIndexes[k] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[k]] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[positions.prevIndexes[k]]] === k\n ) {\n if (!isCandidate[positions.prevIndexes[k]]) {\n isCandidate[positions.prevIndexes[k]] = 1\n candidatesByGroupFrom[groups.groupedFrom[positions.prevIndexes[k]]]++\n }\n if (!isCandidate[positions.nextIndexes[k]]) {\n isCandidate[positions.nextIndexes[k]] = 1\n candidatesByGroupFrom[groups.groupedFrom[positions.nextIndexes[k]]]++\n }\n\n if (\n candidatesByGroupFrom[groups.groupedFrom[positions.prevIndexes[k]]] ===\n groups.groupedTo[positions.prevIndexes[k]] - groups.groupedFrom[positions.prevIndexes[k]] + 1 &&\n candidatesByGroupFrom[groups.groupedFrom[positions.nextIndexes[k]]] ===\n groups.groupedTo[positions.nextIndexes[k]] - groups.groupedFrom[positions.nextIndexes[k]] + 1\n ) {\n isDeleted[k] = 1\n isDeleted[positions.nextIndexes[k]] = 1\n isDeleted[positions.prevIndexes[k]] = 1\n toDelete -= 3\n j = groups.groupedFrom[i] - 1\n }\n } else {\n isDeleted[k] = 1\n toDelete--\n positions.prevIndexes[positions.nextIndexes[k]] = positions.prevIndexes[k]\n positions.nextIndexes[positions.prevIndexes[k]] = positions.nextIndexes[k]\n\n if (positions.prevIndexes[positions.prevIndexes[k]] !== -1) {\n priority[positions.prevIndexes[k]] = getPositionArea(positions.prevIndexes[k], positions)\n heapupdate(heap, heapRev, positions.prevIndexes[k], priority, positions.coordinates)\n }\n if (positions.nextIndexes[positions.nextIndexes[k]] !== -1) {\n priority[positions.nextIndexes[k]] = getPositionArea(positions.nextIndexes[k], positions)\n heapupdate(heap, heapRev, positions.nextIndexes[k], priority, positions.coordinates)\n }\n }\n }\n }\n return isDeleted\n}\n","import { GeoJsonObject, Position } from 'geojson'\nimport {\n isObject,\n isFinitePositiveNumber,\n isFeature,\n isFeatureCollection,\n isLineString,\n isMultiLineString,\n isPolygon,\n isMultiPolygon,\n isGeometryCollection,\n} from '@lib/typeGuards'\nimport { deletePositions, groupPositions, type Positions } from '@lib/functions'\n\nexport type SimplifyOptions = {\n tolerance?: number\n fraction?: number\n mutate?: boolean\n}\n\nexport default function (geojson: GeoJsonObject, options: SimplifyOptions = {}): GeoJsonObject {\n // validate input data\n if (!isObject(geojson)) {\n throw new TypeError(\n `Expected provided GeoJSON to be an object, but received ${geojson === null ? 'null' : typeof geojson}.`,\n )\n }\n\n // validate options\n let tolerance = 0\n if (options.tolerance !== undefined) {\n if (!isFinitePositiveNumber(options.tolerance)) {\n throw new Error(`Expected provided tolerance to be a finite positive number, but received ${options.tolerance}.`)\n }\n tolerance = options.tolerance\n }\n let fraction = 0\n if (options.fraction !== undefined) {\n if (!isFinitePositiveNumber(options.fraction)) {\n throw new Error(`Expected provided fraction to be a finite positive number, but received ${options.fraction}.`)\n }\n if (options.fraction > 1) {\n throw new Error(`Expected provided fraction to be less or equal to 1, but received ${options.fraction}.`)\n }\n fraction = options.fraction\n }\n let mutate = true\n if (options.mutate !== undefined) {\n mutate = !!options.mutate\n }\n\n // exit if no simplification options provided\n if (tolerance === 0 && fraction === 0) {\n return geojson\n }\n\n if (!mutate) {\n geojson = structuredClone(geojson)\n }\n\n const positions: Positions = {\n coordinates: [],\n nextIndexes: [],\n prevIndexes: [],\n }\n collectPositions(geojson, positions)\n\n if (positions.coordinates.length) {\n updatePositions(geojson, deletePositions(positions, groupPositions(positions.coordinates), tolerance, fraction), 0)\n }\n\n return geojson\n}\nfunction updatePositions(geojson: GeoJsonObject, isDeleted: Uint8Array, index: number): number {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n index = updatePositions(geojson.features[i], isDeleted, index)\n }\n } else if (isFeature(geojson)) {\n index = updatePositions(geojson.geometry, isDeleted, index)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n index = updatePositions(geojson.geometries[i], isDeleted, index)\n }\n } else if (isLineString(geojson)) {\n index = updateLinePositions(geojson.coordinates, isDeleted, index)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n index = updateLinePositions(geojson.coordinates[i], isDeleted, index)\n }\n } else if (isPolygon(geojson)) {\n let remove = false\n ;[index, remove] = updateRingsPositions(geojson.coordinates, isDeleted, index)\n if (remove) geojson.coordinates.splice(0)\n } else if (isMultiPolygon(geojson)) {\n let offset = 0\n for (let remove = false, i = 0; i < geojson.coordinates.length; i++) {\n ;[index, remove] = updateRingsPositions(geojson.coordinates[i], isDeleted, index)\n if (remove) {\n offset++\n } else if (offset) {\n geojson.coordinates[i - offset] = geojson.coordinates[i]\n }\n }\n if (offset) geojson.coordinates.splice(geojson.coordinates.length - offset)\n }\n return index\n}\n\nfunction updateLinePositions(coordinates: Position[], isDeleted: Uint8Array, index: number): number {\n let offset = 0\n for (let i = 0; i < coordinates.length; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return index\n}\n\nfunction updateRingsPositions(coordinates: Position[][], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let remove = false, i = 0; i < coordinates.length; i++) {\n ;[index, remove] = updateRingPositions(coordinates[i], isDeleted, index)\n if (remove) {\n // skip interior rings if exterior ring is removed\n if (i === 0) {\n for (i = 1; i < coordinates.length; i++) {\n if (coordinates[i].length) index += coordinates[i].length - 1\n }\n // avoid alternating coordinates array if exterior ring is removed\n return [index, true]\n }\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return [index, false]\n}\n\nfunction updateRingPositions(coordinates: Position[], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let i = 0; i < coordinates.length - 1; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) {\n if (coordinates.length - 1 - offset < 3) {\n // avoid alternating coordinates array if ring is removed\n return [index, true]\n }\n coordinates.splice(coordinates.length - 1 - offset, offset + 1, coordinates[0])\n }\n return [index, false]\n}\n\nfunction collectPositions(geojson: GeoJsonObject, positions: Positions): void {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n collectPositions(geojson.features[i], positions)\n }\n } else if (isFeature(geojson)) {\n collectPositions(geojson.geometry, positions)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n collectPositions(geojson.geometries[i], positions)\n }\n } else if (isLineString(geojson)) {\n collectLinePositions(geojson.coordinates, positions)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectLinePositions(geojson.coordinates[i], positions)\n }\n } else if (isPolygon(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectRingPositions(geojson.coordinates[i], positions)\n }\n } else if (isMultiPolygon(geojson)) {\n for (let j, i = 0; i < geojson.coordinates.length; i++) {\n for (j = 0; j < geojson.coordinates[i].length; j++) {\n collectRingPositions(geojson.coordinates[i][j], positions)\n }\n }\n }\n}\n\nfunction collectLinePositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? -1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? -1 : p + i + 1)\n }\n}\n\nfunction collectRingPositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length - 1, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? p + n - 1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? p : p + i + 1)\n }\n}\n"],"mappings":"AAaO,SAASA,EAAuBC,EAA8C,CACnF,OAAOA,GAAS,MAAQ,OAAO,SAASA,CAAK,GAAKA,EAAQ,CAC5D,CAEO,SAASC,EAASD,EAAgC,CACvD,OAAO,OAAOA,GAAU,UAAYA,IAAU,IAChD,CAEO,SAASE,EAAUF,EAAwC,CAChE,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,SAC5C,CAEO,SAASG,EAAoBH,EAAkD,CACpF,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,mBAC5C,CAEO,SAASI,EAAaJ,EAA2C,CACtE,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,YAC5C,CAEO,SAASK,EAAkBL,EAAgD,CAChF,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,iBAC5C,CAEO,SAASM,EAAUN,EAAwC,CAChE,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,SAC5C,CAEO,SAASO,EAAeP,EAA6C,CAC1E,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,cAC5C,CAEO,SAASQ,EAAqBR,EAAmD,CACtF,OAAOC,EAASD,CAAK,GAAKA,GAAO,OAAS,oBAC5C,CCjCO,SAASS,EAAeC,EAAiC,CAC9D,IAAMC,EAAc,IAAI,YAAYD,EAAY,MAAM,EAChDE,EAAc,IAAI,YAAYF,EAAY,MAAM,EAChDG,EAAY,IAAI,YAAYH,EAAY,MAAM,EACpD,QAASI,EAAI,EAAGA,EAAIJ,EAAY,OAAQI,IACtCH,EAAYG,CAAC,EAAIA,EAEnB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AC,CAAC,EACzCR,EAAU,YAAY,KAAKQ,IAAM,EAAIgB,EAAI,EAAI,EAAIA,EAAIhB,EAAI,CAAC,EAC1DR,EAAU,YAAY,KAAKQ,IAAM,EAAI,EAAIgB,EAAIA,EAAIhB,EAAI,CAAC,CAE1D","names":["isFinitePositiveNumber","value","isObject","isFeature","isFeatureCollection","isLineString","isMultiLineString","isPolygon","isMultiPolygon","isGeometryCollection","groupPositions","coordinates","sortIndexes","groupedFrom","groupedTo","i","a","b","deltaX","deltaY","j","getPositionArea","positions","heapcompare","priority","heapsink","heap","heapRev","l","r","t","heapswap","heapbubble","heapupdate","val","heappop","heapify","deletePositions","groups","tolerance","fraction","n","isDeleted","toDelete","candidatesByGroupFrom","isCandidate","k","index_default","geojson","options","isObject","tolerance","isFinitePositiveNumber","fraction","mutate","positions","collectPositions","updatePositions","deletePositions","groupPositions","isDeleted","index","isFeatureCollection","i","isFeature","isGeometryCollection","isLineString","updateLinePositions","isMultiLineString","isPolygon","remove","updateRingsPositions","isMultiPolygon","offset","coordinates","updateRingPositions","collectLinePositions","collectRingPositions","j","p"]}
1
+ {"version":3,"sources":["../src/lib/typeGuards.ts","../src/lib/functions.ts","../src/index.ts"],"sourcesContent":["import {\n GeoJsonObject,\n Feature,\n FeatureCollection,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon,\n GeometryCollection,\n} from 'geojson'\n\nexport type FinitePositiveNumber = number & { readonly __type: unique symbol }\n\nexport function isFinitePositiveNumber(value: number): value is FinitePositiveNumber {\n return value != null && Number.isFinite(value) && value > 0\n}\n\nexport function isObject(value: object): value is object {\n return typeof value === 'object' && value !== null\n}\n\nexport function isFeature(value: GeoJsonObject): value is Feature {\n return isObject(value) && value?.type === 'Feature'\n}\n\nexport function isFeatureCollection(value: GeoJsonObject): value is FeatureCollection {\n return isObject(value) && value?.type === 'FeatureCollection'\n}\n\nexport function isLineString(value: GeoJsonObject): value is LineString {\n return isObject(value) && value?.type === 'LineString'\n}\n\nexport function isMultiLineString(value: GeoJsonObject): value is MultiLineString {\n return isObject(value) && value?.type === 'MultiLineString'\n}\n\nexport function isPolygon(value: GeoJsonObject): value is Polygon {\n return isObject(value) && value?.type === 'Polygon'\n}\n\nexport function isMultiPolygon(value: GeoJsonObject): value is MultiPolygon {\n return isObject(value) && value?.type === 'MultiPolygon'\n}\n\nexport function isGeometryCollection(value: GeoJsonObject): value is GeometryCollection {\n return isObject(value) && value?.type === 'GeometryCollection'\n}\n","import { Position } from 'geojson'\n\nexport type Positions = {\n coordinates: Position[]\n nextIndexes: number[]\n prevIndexes: number[]\n}\n\nexport type Groups = {\n groupOf: Uint32Array\n groupSize: Uint32Array\n nextInGroup: Uint32Array\n}\n\nexport function groupPositions(coordinates: Position[]): Groups {\n const groupOf = new Uint32Array(coordinates.length)\n const groupSize = new Uint32Array(coordinates.length)\n const nextInGroup = new Uint32Array(coordinates.length)\n const groupTail = new Uint32Array(coordinates.length)\n const groupsByX = new Map<number, number | Map<number, number>>()\n for (let i = 0; i < coordinates.length; i++) {\n const x = coordinates[i][0]\n const y = coordinates[i][1]\n const byX = groupsByX.get(x)\n let root: number\n if (byX === undefined) {\n root = i\n groupsByX.set(x, i)\n } else if (typeof byX === 'number') {\n if (coordinates[byX][1] === y) {\n root = byX\n } else {\n root = i\n const byY = new Map<number, number>()\n byY.set(coordinates[byX][1], byX)\n byY.set(y, i)\n groupsByX.set(x, byY)\n }\n } else {\n const existing = byX.get(y)\n if (existing === undefined) {\n root = i\n byX.set(y, i)\n } else {\n root = existing\n }\n }\n groupOf[i] = root\n if (root === i) {\n groupSize[root] = 1\n groupTail[root] = i\n } else {\n groupSize[root]++\n nextInGroup[groupTail[root]] = i\n groupTail[root] = i\n }\n nextInGroup[i] = coordinates.length\n }\n return {\n groupOf,\n groupSize,\n nextInGroup,\n }\n}\n\nfunction getPositionArea(i: number, positions: Positions): number {\n return (\n Math.abs(\n positions.coordinates[i][0] *\n (positions.coordinates[positions.prevIndexes[i]][1] - positions.coordinates[positions.nextIndexes[i]][1]) +\n positions.coordinates[positions.prevIndexes[i]][0] *\n (positions.coordinates[positions.nextIndexes[i]][1] - positions.coordinates[i][1]) +\n positions.coordinates[positions.nextIndexes[i]][0] *\n (positions.coordinates[i][1] - positions.coordinates[positions.prevIndexes[i]][1]),\n ) / 2\n )\n}\n\nfunction heapcompare(a: number, b: number, priority: Float64Array, coordinates: Position[]): number {\n return priority[a] - priority[b] || coordinates[a][0] - coordinates[b][0] || coordinates[a][1] - coordinates[b][1]\n}\n\nfunction heapsink(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n const value = heap[i]\n let l: number, r: number, t: number\n let selected: number\n while (true) {\n t = i\n selected = value\n if ((l = i << 1) <= heap[0] && heapcompare(selected, heap[l], priority, coordinates) > 0) {\n t = l\n selected = heap[l]\n }\n if ((r = l + 1) <= heap[0] && heapcompare(selected, heap[r], priority, coordinates) > 0) t = r\n if (i === t) break\n heap[i] = heap[t]\n heapRev[heap[i]] = i\n i = t\n }\n heap[i] = value\n heapRev[value] = i\n return i\n}\n\nfunction heapbubble(\n heap: Uint32Array,\n heapRev: Uint32Array,\n i: number,\n priority: Float64Array,\n coordinates: Position[],\n): number {\n let t: number\n while (i > 1) {\n t = i >>> 1\n if (i === t || heapcompare(heap[t], heap[i], priority, coordinates) <= 0) break\n heapswap(heap, heapRev, i, t)\n i = t\n }\n return i\n}\n\nfunction heapupdate(\n heap: Uint32Array,\n heapRev: Uint32Array,\n val: number,\n priority: Float64Array,\n coordinates: Position[],\n): void {\n heapbubble(heap, heapRev, heapsink(heap, heapRev, heapRev[val], priority, coordinates), priority, coordinates)\n}\n\nfunction heapswap(heap: Uint32Array, heapRev: Uint32Array, i: number, t: number): void {\n heapRev[heap[i]] = t\n heapRev[heap[t]] = i\n ;[heap[i], heap[t]] = [heap[t], heap[i]]\n}\n\nfunction heappop(heap: Uint32Array, heapRev: Uint32Array, priority: Float64Array, coordinates: Position[]): number {\n if (heap[0] > 1) {\n heapswap(heap, heapRev, 1, heap[0])\n heap[0]--\n heapsink(heap, heapRev, 1, priority, coordinates)\n return heap[heap[0] + 1]\n } else if (heap[0] === 1) {\n heap[0]--\n return heap[1]\n }\n return -1\n}\n\nfunction heapify(heap: Uint32Array, heapRev: Uint32Array, priority: Float64Array, coordinates: Position[]): void {\n for (let i = heap[0] >>> 1; i > 0; i--) {\n heapsink(heap, heapRev, i, priority, coordinates)\n }\n}\n\nexport function deletePositions(positions: Positions, groups: Groups, tolerance: number, fraction: number): Uint8Array {\n const n = positions.coordinates.length\n\n const isDeleted = new Uint8Array(n)\n let toDelete = Math.round(n * fraction)\n\n const candidatesByGroup = new Uint32Array(n)\n const isCandidate = new Uint8Array(n)\n\n const heap = new Uint32Array(n + 1)\n const priority = new Float64Array(n)\n const heapRev = new Uint32Array(n)\n\n for (let i = 0; i < n; i++) {\n if (positions.prevIndexes[i] !== -1 && positions.nextIndexes[i] !== -1) {\n priority[i] = getPositionArea(i, positions)\n heap[0]++\n heap[heap[0]] = i\n heapRev[i] = heap[0]\n }\n }\n heapify(heap, heapRev, priority, positions.coordinates)\n\n let i: number\n while (heap[0]) {\n i = heappop(heap, heapRev, priority, positions.coordinates)\n\n if (isDeleted[i]) {\n continue\n }\n\n if (priority[i] >= tolerance && toDelete <= 0) {\n break\n }\n\n const groupId = groups.groupOf[i]\n if (!isCandidate[i]) {\n isCandidate[i] = 1\n candidatesByGroup[groupId]++\n }\n\n if (candidatesByGroup[groupId] !== groups.groupSize[groupId]) {\n continue\n }\n\n let k = groupId\n while (k < n) {\n if (isDeleted[k]) {\n k = groups.nextInGroup[k]\n continue\n }\n\n if (\n positions.prevIndexes[k] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[k]] !== -1 &&\n positions.prevIndexes[positions.prevIndexes[positions.prevIndexes[k]]] === k\n ) {\n if (!isCandidate[positions.prevIndexes[k]]) {\n isCandidate[positions.prevIndexes[k]] = 1\n candidatesByGroup[groups.groupOf[positions.prevIndexes[k]]]++\n }\n if (!isCandidate[positions.nextIndexes[k]]) {\n isCandidate[positions.nextIndexes[k]] = 1\n candidatesByGroup[groups.groupOf[positions.nextIndexes[k]]]++\n }\n\n if (\n candidatesByGroup[groups.groupOf[positions.prevIndexes[k]]] ===\n groups.groupSize[groups.groupOf[positions.prevIndexes[k]]] &&\n candidatesByGroup[groups.groupOf[positions.nextIndexes[k]]] ===\n groups.groupSize[groups.groupOf[positions.nextIndexes[k]]]\n ) {\n isDeleted[k] = 1\n isDeleted[positions.nextIndexes[k]] = 1\n isDeleted[positions.prevIndexes[k]] = 1\n toDelete -= 3\n k = groupId\n continue\n }\n } else {\n isDeleted[k] = 1\n toDelete--\n positions.prevIndexes[positions.nextIndexes[k]] = positions.prevIndexes[k]\n positions.nextIndexes[positions.prevIndexes[k]] = positions.nextIndexes[k]\n\n if (positions.prevIndexes[positions.prevIndexes[k]] !== -1) {\n priority[positions.prevIndexes[k]] = getPositionArea(positions.prevIndexes[k], positions)\n heapupdate(heap, heapRev, positions.prevIndexes[k], priority, positions.coordinates)\n }\n if (positions.nextIndexes[positions.nextIndexes[k]] !== -1) {\n priority[positions.nextIndexes[k]] = getPositionArea(positions.nextIndexes[k], positions)\n heapupdate(heap, heapRev, positions.nextIndexes[k], priority, positions.coordinates)\n }\n }\n k = groups.nextInGroup[k]\n }\n }\n return isDeleted\n}\n","import { GeoJsonObject, Position } from 'geojson'\nimport {\n isObject,\n isFinitePositiveNumber,\n isFeature,\n isFeatureCollection,\n isLineString,\n isMultiLineString,\n isPolygon,\n isMultiPolygon,\n isGeometryCollection,\n} from '@lib/typeGuards'\nimport { deletePositions, groupPositions, type Positions } from '@lib/functions'\n\nexport type SimplifyOptions = {\n tolerance?: number\n fraction?: number\n mutate?: boolean\n}\n\nexport default function (geojson: GeoJsonObject, options: SimplifyOptions = {}): GeoJsonObject {\n // validate input data\n if (!isObject(geojson)) {\n throw new TypeError(\n `Expected provided GeoJSON to be an object, but received ${geojson === null ? 'null' : typeof geojson}.`,\n )\n }\n\n // validate options\n let tolerance = 0\n if (options.tolerance !== undefined) {\n if (!isFinitePositiveNumber(options.tolerance)) {\n throw new Error(`Expected provided tolerance to be a finite positive number, but received ${options.tolerance}.`)\n }\n tolerance = options.tolerance\n }\n let fraction = 0\n if (options.fraction !== undefined) {\n if (!isFinitePositiveNumber(options.fraction)) {\n throw new Error(`Expected provided fraction to be a finite positive number, but received ${options.fraction}.`)\n }\n if (options.fraction > 1) {\n throw new Error(`Expected provided fraction to be less or equal to 1, but received ${options.fraction}.`)\n }\n fraction = options.fraction\n }\n let mutate = true\n if (options.mutate !== undefined) {\n mutate = !!options.mutate\n }\n\n // exit if no simplification options provided\n if (tolerance === 0 && fraction === 0) {\n return geojson\n }\n\n if (!mutate) {\n geojson = structuredClone(geojson)\n }\n\n const positions: Positions = {\n coordinates: [],\n nextIndexes: [],\n prevIndexes: [],\n }\n collectPositions(geojson, positions)\n\n if (positions.coordinates.length) {\n updatePositions(geojson, deletePositions(positions, groupPositions(positions.coordinates), tolerance, fraction), 0)\n }\n\n return geojson\n}\nfunction updatePositions(geojson: GeoJsonObject, isDeleted: Uint8Array, index: number): number {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n index = updatePositions(geojson.features[i], isDeleted, index)\n }\n } else if (isFeature(geojson)) {\n index = updatePositions(geojson.geometry, isDeleted, index)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n index = updatePositions(geojson.geometries[i], isDeleted, index)\n }\n } else if (isLineString(geojson)) {\n index = updateLinePositions(geojson.coordinates, isDeleted, index)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n index = updateLinePositions(geojson.coordinates[i], isDeleted, index)\n }\n } else if (isPolygon(geojson)) {\n let remove = false\n ;[index, remove] = updateRingsPositions(geojson.coordinates, isDeleted, index)\n if (remove) geojson.coordinates.splice(0)\n } else if (isMultiPolygon(geojson)) {\n let offset = 0\n for (let remove = false, i = 0; i < geojson.coordinates.length; i++) {\n ;[index, remove] = updateRingsPositions(geojson.coordinates[i], isDeleted, index)\n if (remove) {\n offset++\n } else if (offset) {\n geojson.coordinates[i - offset] = geojson.coordinates[i]\n }\n }\n if (offset) geojson.coordinates.splice(geojson.coordinates.length - offset)\n }\n return index\n}\n\nfunction updateLinePositions(coordinates: Position[], isDeleted: Uint8Array, index: number): number {\n let offset = 0\n for (let i = 0; i < coordinates.length; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return index\n}\n\nfunction updateRingsPositions(coordinates: Position[][], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let remove = false, i = 0; i < coordinates.length; i++) {\n ;[index, remove] = updateRingPositions(coordinates[i], isDeleted, index)\n if (remove) {\n // skip interior rings if exterior ring is removed\n if (i === 0) {\n for (i = 1; i < coordinates.length; i++) {\n if (coordinates[i].length) index += coordinates[i].length - 1\n }\n // avoid alternating coordinates array if exterior ring is removed\n return [index, true]\n }\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n }\n if (offset) coordinates.splice(coordinates.length - offset)\n return [index, false]\n}\n\nfunction updateRingPositions(coordinates: Position[], isDeleted: Uint8Array, index: number): [number, boolean] {\n let offset = 0\n for (let i = 0; i < coordinates.length - 1; i++) {\n if (isDeleted[index]) {\n offset++\n } else if (offset) {\n coordinates[i - offset] = coordinates[i]\n }\n index++\n }\n if (offset) {\n if (coordinates.length - 1 - offset < 3) {\n // avoid alternating coordinates array if ring is removed\n return [index, true]\n }\n coordinates.splice(coordinates.length - 1 - offset, offset + 1, coordinates[0])\n }\n return [index, false]\n}\n\nfunction collectPositions(geojson: GeoJsonObject, positions: Positions): void {\n if (isFeatureCollection(geojson)) {\n for (let i = 0; i < geojson.features.length; i++) {\n collectPositions(geojson.features[i], positions)\n }\n } else if (isFeature(geojson)) {\n collectPositions(geojson.geometry, positions)\n } else if (isGeometryCollection(geojson)) {\n for (let i = 0; i < geojson.geometries.length; i++) {\n collectPositions(geojson.geometries[i], positions)\n }\n } else if (isLineString(geojson)) {\n collectLinePositions(geojson.coordinates, positions)\n } else if (isMultiLineString(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectLinePositions(geojson.coordinates[i], positions)\n }\n } else if (isPolygon(geojson)) {\n for (let i = 0; i < geojson.coordinates.length; i++) {\n collectRingPositions(geojson.coordinates[i], positions)\n }\n } else if (isMultiPolygon(geojson)) {\n for (let j, i = 0; i < geojson.coordinates.length; i++) {\n for (j = 0; j < geojson.coordinates[i].length; j++) {\n collectRingPositions(geojson.coordinates[i][j], positions)\n }\n }\n }\n}\n\nfunction collectLinePositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? -1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? -1 : p + i + 1)\n }\n}\n\nfunction collectRingPositions(coordinates: Position[], positions: Positions) {\n for (let p = positions.coordinates.length, n = coordinates.length - 1, i = 0; i < n; i++) {\n positions.coordinates.push(coordinates[i])\n positions.prevIndexes.push(i === 0 ? p + n - 1 : p + i - 1)\n positions.nextIndexes.push(i === n - 1 ? p : p + i + 1)\n }\n}\n"],"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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qB,EAAqBF,EAAyBnB,EAAsB,CAC3E,QAASwB,EAAIxB,EAAU,YAAY,OAAQ,EAAImB,EAAY,OAAQX,EAAI,EAAGA,EAAI,EAAGA,IAC/ER,EAAU,YAAY,KAAKmB,EAAYX,CAAC,CAAC,EACzCR,EAAU,YAAY,KAAKQ,IAAM,EAAI,GAAKgB,EAAIhB,EAAI,CAAC,EACnDR,EAAU,YAAY,KAAKQ,IAAM,EAAI,EAAI,GAAKgB,EAAIhB,EAAI,CAAC,CAE3D,CAEA,SAASc,EAAqBH,EAAyBnB,EAAsB,CAC3E,QAASwB,EAAIxB,EAAU,YAAY,OAAQ,EAAImB,EAAY,OAAS,EAAGX,EAAI,EAAGA,EAAI,EAAGA,IACnFR,EAAU,YAAY,KAAKmB,EAAYX,CAAC,CAAC,EACzCR,EAAU,YAAY,KAAKQ,IAAM,EAAIgB,EAAI,EAAI,EAAIA,EAAIhB,EAAI,CAAC,EAC1DR,EAAU,YAAY,KAAKQ,IAAM,EAAI,EAAIgB,EAAIA,EAAIhB,EAAI,CAAC,CAE1D","names":["isFinitePositiveNumber","value","isObject","isFeature","isFeatureCollection","isLineString","isMultiLineString","isPolygon","isMultiPolygon","isGeometryCollection","groupPositions","coordinates","groupOf","groupSize","nextInGroup","groupTail","groupsByX","i","x","y","byX","root","byY","existing","getPositionArea","positions","heapcompare","a","b","priority","heapsink","heap","heapRev","value","l","r","t","selected","heapbubble","heapswap","heapupdate","val","heappop","heapify","deletePositions","groups","tolerance","fraction","n","isDeleted","toDelete","candidatesByGroup","isCandidate","groupId","k","index_default","geojson","options","isObject","tolerance","isFinitePositiveNumber","fraction","mutate","positions","collectPositions","updatePositions","deletePositions","groupPositions","isDeleted","index","isFeatureCollection","i","isFeature","isGeometryCollection","isLineString","updateLinePositions","isMultiLineString","isPolygon","remove","updateRingsPositions","isMultiPolygon","offset","coordinates","updateRingPositions","collectLinePositions","collectRingPositions","j","p"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplify-geojson-visvalingam",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
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",