import*as t from"./extent.js";import*as e from"./types.js";export function write(n,r,o,a,s){var u=0,l=0,c=100,i=s===e.geometries.MULTIPOINTZ;n.forEach((function(e,n){var r=40+16*e.length;i&&(r+=32+16*e.length);var f=r+8,h=e.reduce((function(e,n){return t.enlarge(e,n)}),t.blank());a.setInt32(l,c/2),a.setInt32(l+4,f/2),l+=8,c+=f,o.setInt32(u,n),o.setInt32(u+4,r/2),o.setInt32(u+8,s,!0),o.setFloat64(u+12,h.xmin,!0),o.setFloat64(u+20,h.ymin,!0),o.setFloat64(u+28,h.xmax,!0),o.setFloat64(u+36,h.ymax,!0),o.setInt32(u+44,e.length,!0),u+=48;var g=Number.MAX_VALUE,m=-Number.MAX_VALUE,x=Number.MAX_VALUE,F=-Number.MAX_VALUE;e.forEach((function(t,n){(e[2]||0)<g&&(g=e[2]||0),(e[2]||0)>m&&(m=e[2]||0),(e[3]||0)<x&&(x=e[3]||0),(e[3]||0)>F&&(F=e[3]||0),o.setFloat64(u,t[0],!0),o.setFloat64(u+8,t[1],!0),u+=16})),i&&(o.setFloat64(u,g,!0),o.setFloat64(u+8,m,!0),u+=16,e.forEach((function(t,e){o.setFloat64(u,t[2]||0,!0),u+=8})),o.setFloat64(u,x,!0),o.setFloat64(u+8,F,!0),u+=16,e.forEach((function(t,e){o.setFloat64(u,t[3]||0,!0),u+=8})))}))}export function extent(e){return n(e).reduce((function(e,n){return t.enlarge(e,n)}),t.blank())}export function parts(t,e){return t.length}export function shxLength(t){return 8*t.length}export function shpLength(t,r){var o=n(t),a=48*t.length+16*o.length;return r===e.geometries.MULTIPOINTZ&&(a+=32+16*o.length),a}function n(t){return t.reduce((function(t,e){return t.concat(e)}),[])}