import*as t from"./extent.js";import*as e from"./types.js";export function write(n,o,s,u,a){var c=0,i=0,l=100,f=a===e.geometries.POLYLINEZ||a===e.geometries.POLYGONZ;n.forEach((function(e,n){var o=r(e),g=parts([e],a),m=16*o.length+48+4*(g-1);f&&(m+=32+16*o.length);var h=o.reduce((function(e,r){return t.enlarge(e,r)}),t.blank());u.setInt32(i,l/2),u.setInt32(i+4,m/2),i+=8,l+=m+8,s.setInt32(c,n+1),s.setInt32(c+4,m/2),s.setInt32(c+8,a,!0),s.setFloat64(c+12,h.xmin,!0),s.setFloat64(c+20,h.ymin,!0),s.setFloat64(c+28,h.xmax,!0),s.setFloat64(c+36,h.ymax,!0),s.setInt32(c+44,g,!0),s.setInt32(c+48,o.length,!0),s.setInt32(c+52,0,!0);for(var L=e.reduce((function(t,e){return Array.isArray(e[0][0])?t=t.concat(e):t.push(e),t}),[]),p=1;p<g;p++)s.setInt32(c+52+4*p,L.reduce((function(t,e,r){return r<p?t+e.length:t}),0),!0);c+=56+4*(g-1);var E=Number.MAX_VALUE,I=-Number.MAX_VALUE,x=Number.MAX_VALUE,A=-Number.MAX_VALUE;o.forEach((function(t,e){(t[2]||0)<E&&(E=t[2]||0),(t[2]||0)>I&&(I=t[2]||0),(t[3]||0)<x&&(x=t[3]||0),(t[3]||0)>A&&(A=t[3]||0),s.setFloat64(c,t[0],!0),s.setFloat64(c+8,t[1],!0),c+=16})),f&&(s.setFloat64(c,E,!0),s.setFloat64(c+8,I,!0),c+=16,o.forEach((function(t,e){s.setFloat64(c,t[2]||0,!0),c+=8})),s.setFloat64(c,x,!0),s.setFloat64(c+8,A,!0),c+=16,o.forEach((function(t,e){s.setFloat64(c,t[3]||0,!0),c+=8})))}))}export function shpLength(t,n){let o=0;return t.forEach((t=>{const s=r(t);let u=56+4*(parts([t],n)-1)+16*s.length;n!==e.geometries.POLYLINEZ&&n!==e.geometries.POLYGONZ||(u+=32+16*s.length),o+=u})),o}export function shxLength(t){return 8*t.length}export function extent(e){return r(e).reduce((function(e,r){return t.enlarge(e,r)}),t.blank())}export function parts(t,r){var n=1;return r!==e.geometries.POLYGON&&r!==e.geometries.POLYLINE&&r!==e.geometries.POLYGONZ&&r!==e.geometries.POLYLINEZ||(n=t.reduce((function(t,e){return t+=e.length,Array.isArray(e[0][0][0])&&(t+=e.reduce((function(t,e){return t+e.length-1}),0)),t}),0)),n}function r(t,e){return void 0===e&&(e=[]),"object"==typeof t[0][0]?t.reduce((function(t,e){return t.concat(r(e))}),e):t}