UNPKG

poly-simplify

Version:
4 lines (3 loc) 16.7 kB
function t(t){return function(t){let e=[{type:"M",values:t[0].values}],n=e[0];for(let a=1,l=t.length;a<l;a++){let l=t[a],{type:r,values:h}=l,s=h.length,i=n.values,o=i.length,[p,u]=[h[s-2],h[s-1]],[f,c]=[i[o-2],i[o-1]];switch(r){case"H":n={type:"L",values:[h[0],c]};break;case"V":n={type:"L",values:[f,h[0]]};break;case"z":case"Z":n={type:"Z",values:[]};break;case"M":n={type:"M",values:[h[0],h[1]]};break;default:n={type:"L",values:[p,u]}}e.push(n)}return e}(n(function(t,e=!0){const n={77:2,109:2,65:7,97:7,67:6,99:6,72:1,104:1,76:2,108:2,81:4,113:4,83:4,115:4,84:2,116:2,86:1,118:1,90:0,122:0};let a=new Set([...Object.keys(n).map(Number)]);const l=new Set([5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279]);function r(t){return 10===t||13===t||8232===t||8233===t||44===t||32===t||9===t||11===t||12===t||160===t||t>=5760&&l.has(t)>=0}function h(t){return a.has(t)}let s,i=0,o=t.length,p="",u=[],f=-1,c="",y=!1,g=!1,x=0,d=0,m=0,M=!1,v=[];const b=()=>{M&&("M"===p?p="L":"m"===p&&(p="l"),u.push({type:p,values:[]}),f++,d=0,M=!1)},w=(t=!1)=>{(t?x>0:""!==c)&&(e&&-1===f&&(s="Pathdata must start with M command",v.push(s),p="M",u.push({type:p,values:[]}),m=2,d=0,f++),"A"===p||"a"===p?(c=A(),u[f].values.push(...c)):(e&&c[1]&&"."!==c[1]&&"0"===c[0]&&(s="Leading zeros not valid: "+c,v.push(s)),u[f].values.push(+c)),d++,c="",x=0,M=d>=m)},A=()=>{let t=c.length,e=!1;return 3===d&&2===t||4===d&&t>1?(c=[+c[0],+c[1]],e=!0,d++):3===d&&t>=3&&(c=[+c[0],+c[1],+c.substring(2)],e=!0,d+=2),e?c:[+c]},P=()=>{if(e){let t=f>0?u[f]:0,e=t?t.values.length:0;(e&&e<m||e&&e>m||("z"===p||"Z"===p)&&e>0)&&(s=`Pathdata commands in "${p}" (segment index: ${f}) don't match allowed number of values: ${m-e}/${m}`,v.push(s))}};for(;i<o;){let e=t[i],a=t.charCodeAt(i);if(h(a)){""!==c&&(u[f].values.push(+c),d++,c=""),P(),p=e,m=n[a];let t="M"===p||"m"===p;f>0&&("z"===u[f].type||"Z"===u[f].type)&&!t&&(u.push({type:"m",values:[0,0]}),f++),u.push({type:p,values:[]}),f++,g=!1,x=0,d=0,M=!1,i++}else if(r(a))w(),g=!0,y=!1,i++;else{if(i===o-1){c+=e,w(),g=!1,y=!1,P();break}if(!y&&!g&&45===a||!y&&46===a){let t=46===a;w(t),b(),t&&x++}else b();c+=e,y=69===a||101===a,g=!1,i++}}if(P(),u[0].type="M",e&&v.length){if(s="Invalid path data:\n"+v.join("\n"),"log"!==e)throw new Error(s);console.warn(s)}return u}(t),!1))}function e(t){let e=[{x:t[0].values[0],y:t[0].values[1]}];for(let n=1,a=t.length;n<a;n++){let{values:a}=t[n];if(a.length){let t=a.slice(-2);e.push({x:t[0],y:t[1]})}}return e}function n(t,e=!1){let n=t[0].values,a=n[0],l=n[1],r=a,h=l;for(let n=1,s=t.length;n<s;n++){let s=t[n],{type:i,values:o}=s,p=e?i.toLowerCase():i.toUpperCase();if(i!==p)switch(i=p,s.type=i,i){case"a":case"A":o[5]=e?o[5]-a:o[5]+a,o[6]=e?o[6]-l:o[6]+l;break;case"v":case"V":o[0]=e?o[0]-l:o[0]+l;break;case"h":case"H":o[0]=e?o[0]-a:o[0]+a;break;case"m":case"M":e?(o[0]-=a,o[1]-=l):(o[0]+=a,o[1]+=l),r=e?o[0]+a:o[0],h=e?o[1]+l:o[1];break;default:if(o.length)for(let t=0;t<o.length;t++)o[t]=e?o[t]-(t%2?l:a):o[t]+(t%2?l:a)}let u=o.length;switch(i){case"z":case"Z":a=r,l=h;break;case"h":case"H":a=e?a+o[0]:o[0];break;case"v":case"V":l=e?l+o[0]:o[0];break;case"m":case"M":r=o[u-2]+(e?a:0),h=o[u-1]+(e?l:0);default:a=o[u-2]+(e?a:0),l=o[u-1]+(e?l:0)}}return t[0].type="M",t=t.map((t=>({type:t.type,values:t.values.map((t=>+t.toFixed(9)))})))}function a(t,e=-1,a=!1,l=!1){return l&&(t=function(t){let e,n=[{type:"M",values:t[0].values}],a=n[0],l={x:t[0].values[0],y:t[0].values[1]},r=.01;for(let h=1,s=t.length;h<s;h++){let s=t[h],{type:i,values:o}=s,p=o.length?o.slice(-2):[];e={x:p[0],y:p[1]};let u=Math.abs(e.x-l.x),f=Math.abs(e.y-l.y),c=(u+f)/2*r;switch(i){case"L":a=0===f||f<c&&u>c?{type:"H",values:[o[0]]}:0===u||f>c&&u<c?{type:"V",values:[o[1]]}:s;break;case"M":case"Z":case"z":a={type:i,values:p};break;default:a={type:"L",values:p}}l={x:p[0],y:p[1]},n.push(a)}return n}(t)),a&&(t=function(t){return n(t,!0)}(t)),e>-1&&(t=t.map((t=>({type:t.type,values:t.values.map((t=>+t.toFixed(e)))})))),t}function l(t,e=1){let n=e>1,a=!n&&0!==e;"l"===(t=JSON.parse(JSON.stringify(t)))[1].type&&a&&(t[0].type="m");let l="";l=n?`${t[0].type} ${t[0].values.join(" ")}\n`:`${t[0].type}${t[0].values.join(" ")}`;for(let e=1,r=t.length;e<r;e++){let r=t[e-1],h=t[e],{type:s,values:i}=h;if(!a||"A"!==s&&"a"!==s||(i=[i[0],i[1],i[2],`${i[3]}${i[4]}${i[5]}`,i[6]]),s=r.type===h.type&&"m"!==h.type.toLowerCase()&&a||("m"===r.type&&"l"===h.type||"M"===r.type&&"l"===h.type||"M"===r.type&&"L"===h.type)&&a?" ":h.type,a){let t="",e=!1;for(let n=0,a=i.length;n<a;n++){let a=i[n],l=a.toString(),r=l.includes(".")&&Math.abs(a)<1;r&&e&&(l=l.replace(/^0\./,".")),!(n>0)||e&&r||(t+=" "),t+=l,e=r}l+=`${s}${t}`}else l+=n?`${s} ${i.join(" ")}\n`:`${s}${i.join(" ")}`}return a&&(l=l.replace(/ 0\./g," .").replace(/ -/g,"-").replace(/-0\./g,"-.").replace(/Z/g,"z")),l}function r(n){if(!n||!n.length)return[];const a=t=>{let e=[];for(let n=1,a=t.length;n<a;n+=2)e.push({x:t[n-1],y:t[n]});return e};let l=n[0].x||!1;if(l&&n.length>0&&"object"==typeof n[0]&&n[0].constructor!==Object&&(t=>{let e=t.length,n=new Array(e);for(let a=0;a<e;a++)n[a]={x:t[a].x,y:t[a].y}})(n),l)return n;let r="string"==typeof n,h=!1;if(!!r&&(n.startsWith("M")||n.startsWith("m"))){0;let a=t(n),l=function(t){let e=[];try{t.map(((t,e)=>"m"===t.type.toLowerCase()?e:-1)).filter((t=>-1!==t))}catch{console.log("catch",t)}let n=t.map(((t,e)=>"m"===t.type.toLowerCase()?e:-1)).filter((t=>-1!==t));return 1===n.length?[t]:(n.forEach(((a,l)=>{e.push(t.slice(a,n[l+1]))})),e)}(a);h=l.length>1;let r=[];return h?l.forEach((t=>{let n=e(t);r.push(n)})):r=e(a),r}if(!!r&&(n.startsWith("{")||n.startsWith("["))){try{n=JSON.parse(n)}catch{n=JSON.parse(n.replace(/([{,])\s*(\w+)\s*:/g,'$1"$2":'))}r=!1}if(r){if((n=n.trim().split(/,| /).filter(Boolean).map(Number)).filter((t=>isNaN(t))).length)return console.warn("input doesn't contain point data – please, check your input structure for syntax errors"),[]}let s=Array.isArray(n),i=s&&2===n[0].length,o=!i&&s&&Array.isArray(n[0]),p=o&&2===n[0][0].length,u=o&&!p&&n[0].length>2&&!n[0][0].hasOwnProperty("x");if(u||p){let t=[];n.forEach((e=>{let n=u?a(e):e.map((t=>({x:t[0],y:t[1]})));t.push(n)})),n=t}else i&&(n=n.map((t=>({x:t[0],y:t[1]})))); //!Array.isArray(pts[0] return!Array.isArray(n[0])&&!n[0].hasOwnProperty("x")&&(n=a(n)),n}function h(t,e){return(e.x-t.x)**2+(e.y-t.y)**2}function s(t){let e=h(t[0],t[1]);for(let n=3,a=t.length;n<a;n++){let a=h(t[n-1],t[n]);if(100/e*Math.abs(e-a)>.1)return!1;e=a}return!0}function i(t,e=null){if(0===t.length)return t;if(e=null===e?function(t,e=24){let n=o(t,e),{width:a,height:l}=u(n),r=(Math.max(a,l)/t.length)**2,s=h(t[0],t[t.length-1]);return s<r}(t):e,!e)return t;let n=0;for(let e=1,a=t.length;e<a;e++){let a=t[e],l=t[n];(a.x<l.x||a.x===l.x&&a.y<l.y)&&(n=e)}return t.slice(n).concat(t.slice(0,n))}function o(t,e=48){if(!Array.isArray(t)||t.length<=e)return t;let n=t.length,a=n/e,l=[];for(let n=0;n<e;n++)l.push(t[Math.floor(n*a)]);let r=l.length;return l[r-1]!==t[n-1]&&(l[r-1]=t[n-1]),l}function p(t,e=!0){let n=0;for(let e=0,a=t.length;a&&e<a;e++){n+=t[e].x*t[e===t.length-1?0:e+1].y*.5-t[e===t.length-1?0:e+1].x*t[e].y*.5}return e?Math.abs(n):n}function u(t){let e=t.map((t=>t.x)),n=t.map((t=>t.y)),a=Math.min(...e),l=Math.max(...e),r=Math.min(...n),h=Math.max(...n);return{x:a,left:a,right:l,y:r,top:r,bottom:h,width:l-a,height:h-r}}function f(t){const e=(t,e,n)=>{const a=(t,e,n,a)=>{let[l,r,h,s]=[t.x,e.x,n.x,a.x],[i,o,p,u]=[t.y,e.y,n.y,a.y],[f,c]=[l-r,h-s],[y,g]=[i-o,p-u],x=f*g-y*c;if(0===x)return null;let d=l*o-i*r,m=h*u-p*s,M=(d*c-f*m)/x,v=(d*g-y*m)/x;return M<Math.min(l,r)||M>Math.max(l,r)||M<Math.min(h,s)||M>Math.max(h,s)||v<Math.min(i,o)||v>Math.max(i,o)||v<Math.min(p,u)||v>Math.max(p,u)?null:{x:M,y:v}},l=(t,e)=>(t.x-e.x)**2+(t.y-e.y)**2,r=t.length;let h=[],s=l(e,n),i=s/1e3;for(let o=0;o<r;o++){let p=t[o],u=t[(o+1)%r];if(u===n)continue;let f=a(e,n,p,u);if(f){const t=l(e,f);t>i&&t<s&&h.push({pt0:e,pt1:n,startPoint:p,intersectionPoint:f,endPoint:u,lengthSq:t})}}return h.sort(((t,e)=>t.lengthSq-e.lengthSq)),h},n=t.length;if(n<3)return t;for(let e=0;e<n;e++)t[e].next=(e+1)%n;const a=[];let l=t[0],r=t[l.next];a.push(l);for(let h=0;h<2*n;h++){const n=e(t,l,r);if(0===n.length)a.push(r),l=r,r=t[r.next];else{const t=n[0];l=t.intersectionPoint,r=t.endPoint,a.push(l)}if(a.length>2&&l.x===a[0].x&&l.y===a[0].y)break}const h=a[0],s=a[a.length-1];return h.x===s.x&&h.y===s.y&&a.pop(),a}function c(t){if(!function(t){const e=(t,e)=>t>=-180&&t<=180&&e>=-90&&e<=90;let n=[t[0],t[Math.floor(t.length/2)],t[t.length-1]];return n.every((t=>e(t.x,t.y)))}(t))return t;const e=t=>t*(Math.PI/180),n=t=>{let n=Math.max(-85.05112878,Math.min(85.05112878,t.y)),a=t.x;return{x:(e(a)+Math.PI)/(2*Math.PI),y:(Math.PI-Math.log(Math.tan(Math.PI/4+e(n)/2)))/(2*Math.PI)}};let a=t.length,l=[];for(let e=0;e<a;e++)l.push(n(t[e]));let r=u(t),h=u(l),s=r.width/h.width,i=h.x*s-r.x,o=h.y*s-r.y;for(let t=0;t<a;t++)l[t].x=l[t].x*s-i,l[t].y=l[t].y*s-o;return l}function y(t,e,n="points",r=!1,s=-1,i=!1,p=!1,f=!1,c=1,y=0,g=0,x=!1,d=0,m=0,M=!1){let v={data:[],ptsArr:[],countOriginal:0,count:0,areaOriginal:0,areaptsSmp:0,areaDiff:0,isPolygon:[]};e=function(t,e=1,n=0,a=0,l=!1,r=0,h=0){if(1===e&&0===r&&0===h&&0===n&&0===a&&!1===l)return t;let s,i,o,p,f=Array.isArray(t[0]),c=f?t:[t],y=f?t.flat():t;return({x:s,y:i,width:o,height:p}=u(y)),c.forEach(((t,u)=>{e=r?r/o:h?h/p:e,h&&p*e>h&&(e=h/p),l&&(n=-s,a=-i);for(let l=0,r=t.length;l<r;l++){let r=t[l];c[u][l]={x:(r.x+n)*e,y:(r.y+a)*e}}})),c}(e,c,y,g,x,d,m);for(let n=0,a=e.length;n<a;n++){let a=t[n],l=e[n],s=a.length;v.countOriginal+=s;let i=l.length;v.count+=i,v.ptsArr.push(l);let p=!1;if(r){let t=o(a,32),{width:e,height:n}=u(t),l=(Math.max(e,n)/a.length)**2;p=h(a[0],a[a.length-1])<l,v.isPolygon.push(p)}}if(s>-1&&s<=3){let t=e.flat(),n=o(t,24),{width:a,height:l}=u(n),r=(a+l)/2;if(r>500)s=0;else{let e=t.length/r,n=r/1e3,a=Math.ceil(1/n).toString().length,l=Math.ceil(e).toString().length,h=Math.ceil((a+l)/2);s=s>-1&&s<h?h:s}}switch(n=n?n.toLowerCase():"points"){case"points":case"pointstring":case"pointsnested":case"json":s>-1&&(v.ptsArr=v.ptsArr.map((t=>t.map((t=>({x:+t.x.toFixed(s),y:+t.y.toFixed(s)})))))),"pointstring"===n?v.data=v.ptsArr.map((t=>t.map((t=>`${t.x} ${t.y}`)).join(" "))):"points"===n?(M||(v.ptsArr=v.ptsArr[0]),v.data=v.ptsArr):"pointsnested"===n?(v.data=v.ptsArr.map((t=>t.map((t=>[t.x,t.y])))),M||(v.data=v.data[0],v.ptsArr=v.ptsArr[0])):"json"===n&&(M||(v.ptsArr=v.ptsArr[0]),v.data=JSON.stringify(v.ptsArr));break;case"pathdata":case"path":let t=[];v.ptsArr.forEach(((e,n)=>{let a=[{type:"M",values:[e[0].x,e[0].y]},...e.slice(1).map((t=>({type:"L",values:[t.x,t.y]})))];v.isPolygon[n]&&a.push({type:"Z",values:[]}),t.push(...a)})),t=a(t,s,i,p),"path"===n?(v.data=[l(t,f?1:0)],M||(v.data=v.data[0])):v.data=t}return v}function g(t){if(t.length<3)return t;let e,n,a=[t[0]],l=t[0],r=t[t.length-1],s=1;for(let r=2,i=t.length;r<i;r++){if(e=t[r-1],n=t[r],e.x===n.x&&e.y===n.y)continue;let o=l.x===e.x,p=l.y===e.y;if(o||p){let t=e.x===n.x,h=e.y===n.y;t&&o||h&&p||a.push(e),r===i-1&&a.push(n),l=e;continue}let u=l.x-n.x,f=l.y-n.y,c=l.x-e.x,y=l.y-e.y,g=Math.abs(u*y-f*c);s=h(e,n)/50,g>s&&(r===i-1?a.push(e,n):a.push(e)),l=e}return l=a[0],l.x===r.x&&l.y===r.y&&a.pop(),a}function x(t,e=.9,n=0,a=0){let l=!1;if("string"==typeof e){l=!0,e=parseFloat(e)}if(t.length<4||(!l&&e)>=1)return t;let r,s=t[0],i=[s],p=e;if(!l){if(p=1-e,!n&&!a){let e=o(t,12);({width:n,height:a}=u(e))}p=(p*((n+a)/2/25))**2,e>.5&&(p/=10)}for(let e=1,n=t.length;e<n;e++){r=t[e],h(s,r)>p&&(i.push(r),s=r)}return s.x!==r.x&&s.y!==r.y&&i.push(r),i}function d(t,e=.9,n=0,a=0){let l=!1;if("string"==typeof e&&(l=!0,e=parseFloat(e)),t.length<4||(!l&&e)>=1)return t;let r=e;if(!l){if(r=1-e,e>.5&&(r/=2),!n&&!a){let e=o(t,12);({width:n,height:a}=u(e))}r=(r*((n+a)/2/100))**2}const h=(t,e,n)=>{let a=e.x,l=e.y,r=n.x-a,h=n.y-l;if(0!==r||0!==h){let e=((t.x-a)*r+(t.y-l)*h)/(r*r+h*h);e>1?(a=n.x,l=n.y):e>0&&(a+=r*e,l+=h*e)}return(t.x-a)**2+(t.y-l)**2};let s=[t[0]],i=[];for(i.push([0,t.length-1]);i.length>0;){let[e,n]=i.pop(),a=r,l=-1;for(let r=e+1;r<n;r++){let s=h(t[r],t[e],t[n]);s>a&&(l=r,a=s)}a>r?(i.push([l,n]),i.push([e,l])):s.push(t[n])}return s}function m(t,e=1,n=0,a=0){let l=!1;if("string"==typeof e&&(l=!0,e=parseFloat(e)),t.length<4||(!l&&e)>=1)return t;let r=function(t){const e=new M;for(let n=0,a=t.length;n<a;n++){let l=0===n?a-1:n-1,r=n,h=n===a-1?0:n+1,s=t[l],i=t[r],o=t[h],u=n>0||n===a-1?i.area?i.area:p([s,i,o]):1/0;i.prev=l,i.index=r,i.next=h,i.area=u,i.heapIndex=n>0?e.push(u,r):0}return e}(t);if(!n&&!a){let e=reducePoints(t,12);({width:n,height:a}=getPolyBBox(e))}let h=e;if(!l){h=((1-e)*((n+a)/2/100))**2}const s=(t,e,n)=>{let a=t[e];if(null===a.prev||null===a.next)return;let l=p([t[a.prev],a,t[a.next]]);a.area=l,void 0!==a.heapIndex?n.update(a.heapIndex,l):a.heapIndex=n.push(l,e)};let i=0,o=t.length;for(;r.size()>0;){const{area:e,index:n}=r.pop(),a=t[n];e&&e<i?a.area=i:i=e,0!==n&&(t[a.prev].next=a.next,s(t,a.prev,r)),n!==o-1&&(t[a.next].prev=a.prev,s(t,a.next,r))}let u=[];for(let e=0,n=t.length;e<n;e++){let a=t[e];(!a.area||0===e||e===n-1||a.area>=h)&&u.push(a)}return u}class M{constructor(){this.heap=[],this.indexMap=new Map}push(t,e){const n={area:t,index:e};this.heap.push(n);const a=this.heap.length-1;return this.indexMap.set(e,a),this.bubbleUp(a),a}pop(){if(0===this.heap.length)return null;const t=this.heap[0],e=this.heap.pop();return this.heap.length>0&&(this.heap[0]=e,this.indexMap.set(e.index,0),this.bubbleDown(0)),this.indexMap.delete(t.index),t}update(t,e){if("number"!=typeof t||t<0||t>=this.heap.length)return;const n=this.heap[t].area;this.heap[t].area=e,e<n?this.bubbleUp(t):this.bubbleDown(t)}size(){return this.heap.length}bubbleUp(t){for(;t>0;){const e=Math.floor((t-1)/2);if(this.heap[e].area<=this.heap[t].area)break;this.swap(t,e),t=e}}bubbleDown(t){for(;;){const e=2*t+1,n=2*t+2;let a=t;if(e<this.heap.length&&this.heap[e].area<this.heap[a].area&&(a=e),n<this.heap.length&&this.heap[n].area<this.heap[a].area&&(a=n),a===t)break;this.swap(t,a),t=a}}swap(t,e){[this.heap[t],this.heap[e]]=[this.heap[e],this.heap[t]],this.indexMap.set(this.heap[t].index,t),this.indexMap.set(this.heap[e].index,e)}}function v(t,e=0){if(t.length<=3||!e||t.length<=e)return t;let n=t,a=Math.ceil(t.length/e),l=n.length;for(let t=0;n.length>e&&t<a;t++){if(n=r(n,e,.5,!0,!1),l===n.length)break;l=n.length}function r(t,e=0,n=.5,a=!0,l=!1){let r,h=function(t){let e=[];for(let n=0;n<t.length;n++){let a=0===n?t.length-1:n-1,l=n,r=n===t.length-1?0:n+1,h=p([t[a],t[l],t[r]]),s=a,i=r;e.push({index:n,area:h,prev:s,next:i})}return e}(t),s=h.length,i=[];if(l){r=h.map((t=>t.area)).reduce(((t,e)=>t+e),0)/s*.25,a=!1}a&&h.sort(((t,e)=>t.area-e.area));let o=t.length-e,u=new Set;o=Math.floor(o*n)+1;let f=0;for(let t=0;t<o;t++){let e=h[t],{index:a,area:s,prev:i,next:o}=e,p=h[i],c=h[o],[y,g]=[p.area,c.area];l?a>0&&s<r&&f<a&&(u.add(a),f=o):(1===n||s<y&&s<g)&&(f=a,a>0&&(u.add(a),f=a))}for(let e=0;e<t.length;e++)u.has(e)||i.push(t[e]);return i}return n.length>e&&(n=r(n,e,1)),n}function b(t,{quality:e=1,RC:n=!0,RDP:a=!0,VW:l=!1,RD:h=!0,mercator:M=!1,unite:b=!1,overrideQuality:w=!1,optimizeStartingPoint:A=!0,maxPoints:P=0,skipPoints:k=!1,outputFormat:S="points",scale:$=1,alignToZero:L=!1,translateX:I=0,translateY:O=0,scaleToWidth:j=0,scaleToHeight:z=0,meta:F=!1,decimals:N=-1,toRelative:Z=!1,toShorthands:C=!1,minifyString:D=!1}={}){try{t=r(t)}catch{return console.warn("invalid input"),t=[{x:0,y:0}]}let E,W=e,H=!1,J=!1;if("string"==typeof e&&(W=parseFloat(e),E=e.replace(W.toString(),"").trim(),E?"v"===E?(P=W,J=!0,e=.8):H=!0:e=W<=1?W:.8),P){const n=(t,e,n)=>Math.min(Math.max(t,e),n);let a=+(t.length/P/100).toFixed(1);e=(e=n(e=Math.abs(1-a),.4,.8))>0&&e<1?e:.8}let V=t[0].length>1,q=V?t:[t],R=[],U=[],B=0,T=[];for(let t=0,e=q.length;t<e;t++){let e=o(q[t],64);T.push(u(e));let n=p(e);B+=n,U.push(n)}for(let t=0,r=q.length;t<r;t++){let r=q[t],p=U[t]/B,u=J?Math.ceil(P*p):0;if(!r.length)return[];let y=r;if(r.length<3){R.push(y);continue}if(k&&!a&&!l&&!h&&J){y=o(r,u),R.push(y);continue}if(w||(e>=1&&(a=!1),e>=.75&&(h=!1),e<.5&&(h=!0)),y=A?i(y):y,n){if(!H&&e>1){R.push(y);continue}y=g(y)}if(b&&(y=f(y)),n){s(y)&&(l=!1,a=!1)}let{width:S,height:$}=T[t];if(h&&y.length>u&&(y=x(y,e,S,$)),a&&y.length>u&&(y=d(y,e,S,$)),l&&y.length>u&&(y=m(y,e,S,$)),J&&y.length>u){(y.length-u)/y.length>.25&&(y=x(y,e,S,$)),y=v(y,u)}M&&(y=c(y)),R.push(y)}let Q=y(q,R,S,F,N,Z,C,D,$,I,O,L,j,z,V);return F?Q:Q.data}"undefined"!=typeof window&&(window.polySimplify=b,window.normalizePointInput=r);export{r as normalizePointInput,l as pathDataToD,b as polySimplify,g as simplifyRC,x as simplifyRD,d as simplifyRDP};