!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(n.topojson=n.topojson||{})}(this,function(n){"use strict";function r(n,r,e,o){t(n,r,e),t(n,r,r+o),t(n,r+o,e)}function t(n,r,t){for(var e,o=r+(t-- -r>>1);r<o;++r,--t)e=n[r],n[r]=n[t],n[t]=e}function e(n){return(n&&x.hasOwnProperty(n.type)?x[n.type]:i)(n)}function o(n){var r=n.geometry;return null==r?n.type=null:(i(r),n.type=r.type,r.geometries?n.geometries=r.geometries:r.coordinates&&(n.coordinates=r.coordinates),r.bbox&&(n.bbox=r.bbox)),delete n.geometry,n}function i(n){return n?(b.hasOwnProperty(n.type)&&b[n.type](n),n):{type:null}}function a(n){var r,t=n[0],e=n[1];return e<t&&(r=t,t=e,e=r),t+31*e}function f(n,r){var t,e=n[0],o=n[1],i=r[0],a=r[1];return o<e&&(t=e,e=o,o=t),a<i&&(t=i,i=a,a=t),e===i&&o===a}var u=function(n){function r(n){n&&c.hasOwnProperty(n.type)&&c[n.type](n)}function t(n){var r=n[0],t=n[1];r<i&&(i=r),r>f&&(f=r),t<a&&(a=t),t>u&&(u=t)}function e(n){n.forEach(t)}function o(n){n.forEach(e)}var i=1/0,a=1/0,f=-(1/0),u=-(1/0),c={GeometryCollection:function(n){n.geometries.forEach(r)},Point:function(n){t(n.coordinates)},MultiPoint:function(n){n.coordinates.forEach(t)},LineString:function(n){e(n.coordinates)},MultiLineString:function(n){n.coordinates.forEach(e)},Polygon:function(n){n.coordinates.forEach(e)},MultiPolygon:function(n){n.coordinates.forEach(o)}};for(var l in n)r(n[l]);return f>=i&&u>=a?[i,a,f,u]:void 0},c=function(n,r,t,e,o){function i(e){for(var i=r(e)&c,a=u[i],f=0;a!=o;){if(t(a,e))return!0;if(++f>=n)throw new Error("full hashset");a=u[i=i+1&c]}return u[i]=e,!0}function a(e){for(var i=r(e)&c,a=u[i],f=0;a!=o;){if(t(a,e))return!0;if(++f>=n)break;a=u[i=i+1&c]}return!1}function f(){for(var n=[],r=0,t=u.length;r<t;++r){var e=u[r];e!=o&&n.push(e)}return n}3===arguments.length&&(e=Array,o=null);for(var u=new e(n=1<<Math.max(4,Math.ceil(Math.log(n)/Math.LN2))),c=n-1,l=0;l<n;++l)u[l]=o;return{add:i,has:a,values:f}},l=function(n,r,t,e,o,i){function a(e,i){for(var a=r(e)&h,f=l[a],u=0;f!=o;){if(t(f,e))return s[a]=i;if(++u>=n)throw new Error("full hashmap");f=l[a=a+1&h]}return l[a]=e,s[a]=i,i}function f(e,i){for(var a=r(e)&h,f=l[a],u=0;f!=o;){if(t(f,e))return s[a];if(++u>=n)throw new Error("full hashmap");f=l[a=a+1&h]}return l[a]=e,s[a]=i,i}function u(e,i){for(var a=r(e)&h,f=l[a],u=0;f!=o;){if(t(f,e))return s[a];if(++u>=n)break;f=l[a=a+1&h]}return i}function c(){for(var n=[],r=0,t=l.length;r<t;++r){var e=l[r];e!=o&&n.push(e)}return n}3===arguments.length&&(e=i=Array,o=null);for(var l=new e(n=1<<Math.max(4,Math.ceil(Math.log(n)/Math.LN2))),s=new i(n),h=n-1,g=0;g<n;++g)l[g]=o;return{set:a,maybeSet:f,get:u,keys:c}},s=function(n,r){return n[0]===r[0]&&n[1]===r[1]},h=new ArrayBuffer(16),g=new Float64Array(h),d=new Uint32Array(h),v=function(n){g[0]=n[0],g[1]=n[1];var r=d[0]^d[1];return r=r<<5^r>>7^d[2]^d[3],2147483647&r},y=function(n){function r(n,r,t,e){if(m[t]!==n){m[t]=n;var o=w[t];if(o>=0){var i=M[t];o===r&&i===e||o===e&&i===r||(++x,P[t]=1)}else w[t]=r,M[t]=e}}function t(){for(var n=l(1.4*g.length,e,o,Int32Array,-1,Int32Array),r=new Int32Array(g.length),t=0,i=g.length;t<i;++t)r[t]=n.maybeSet(t,t);return r}function e(n){return v(g[n])}function o(n,r){return s(g[n],g[r])}var i,a,f,u,h,g=n.coordinates,d=n.lines,y=n.rings,p=t(),m=new Int32Array(g.length),w=new Int32Array(g.length),M=new Int32Array(g.length),P=new Int8Array(g.length),x=0;for(i=0,a=g.length;i<a;++i)m[i]=w[i]=M[i]=-1;for(i=0,a=d.length;i<a;++i){var b=d[i],E=b[0],L=b[1];for(u=p[E],h=p[++E],++x,P[u]=1;++E<=L;)r(i,f=u,u=h,h=p[E]);++x,P[h]=1}for(i=0,a=g.length;i<a;++i)m[i]=-1;for(i=0,a=y.length;i<a;++i){var S=y[i],A=S[0]+1,C=S[1];for(f=p[C-1],u=p[A-1],h=p[A],r(i,f,u,h);++A<=C;)r(i,f=u,u=h,h=p[A])}m=w=M=null;var I,O=c(1.4*x,v,s);for(i=0,a=g.length;i<a;++i)P[I=p[i]]&&O.add(g[I]);return O},p=function(n){var t,e,o,i=y(n),a=n.coordinates,f=n.lines,u=n.rings;for(e=0,o=f.length;e<o;++e)for(var c=f[e],l=c[0],s=c[1];++l<s;)i.has(a[l])&&(t={0:l,1:c[1]},c[1]=l,c=c.next=t);for(e=0,o=u.length;e<o;++e)for(var h=u[e],g=h[0],d=g,v=h[1],p=i.has(a[g]);++d<v;)i.has(a[d])&&(p?(t={0:d,1:h[1]},h[1]=d,h=h.next=t):(r(a,g,v,v-d),a[v]=a[g],p=!0,d=g));return n},m=function(n){function r(n){var r,t,i,a,f,u,c,l;if(i=w.get(r=d[n[0]]))for(c=0,l=i.length;c<l;++c)if(a=i[c],e(a,n))return n[0]=a[0],void(n[1]=a[1]);if(f=w.get(t=d[n[1]]))for(c=0,l=f.length;c<l;++c)if(u=f[c],o(u,n))return n[1]=u[0],void(n[0]=u[1]);i?i.push(n):w.set(r,[n]),f?f.push(n):w.set(t,[n]),M.push(n)}function t(n){var r,t,e,o,u;if(t=w.get(r=d[n[0]]))for(o=0,u=t.length;o<u;++o){if(e=t[o],i(e,n))return n[0]=e[0],void(n[1]=e[1]);if(a(e,n))return n[0]=e[1],void(n[1]=e[0])}if(t=w.get(r=d[n[0]+f(n)]))for(o=0,u=t.length;o<u;++o){if(e=t[o],i(e,n))return n[0]=e[0],void(n[1]=e[1]);if(a(e,n))return n[0]=e[1],void(n[1]=e[0])}t?t.push(n):w.set(r,[n]),M.push(n)}function e(n,r){var t=n[0],e=r[0],o=n[1],i=r[1];if(t-o!==e-i)return!1;for(;t<=o;++t,++e)if(!s(d[t],d[e]))return!1;return!0}function o(n,r){var t=n[0],e=r[0],o=n[1],i=r[1];if(t-o!==e-i)return!1;for(;t<=o;++t,--i)if(!s(d[t],d[i]))return!1;return!0}function i(n,r){var t=n[0],e=r[0],o=n[1],i=r[1],a=o-t;if(a!==i-e)return!1;for(var u=f(n),c=f(r),l=0;l<a;++l)if(!s(d[t+(l+u)%a],d[e+(l+c)%a]))return!1;return!0}function a(n,r){var t=n[0],e=r[0],o=n[1],i=r[1],a=o-t;if(a!==i-e)return!1;for(var u=f(n),c=a-f(r),l=0;l<a;++l)if(!s(d[t+(l+u)%a],d[i-(l+c)%a]))return!1;return!0}function f(n){for(var r=n[0],t=n[1],e=r,o=e,i=d[e];++e<t;){var a=d[e];(a[0]<i[0]||a[0]===i[0]&&a[1]<i[1])&&(o=e,i=a)}return o-r}var u,c,h,g,d=n.coordinates,y=n.lines,p=n.rings,m=y.length+p.length;for(delete n.lines,delete n.rings,h=0,g=y.length;h<g;++h)for(u=y[h];u=u.next;)++m;for(h=0,g=p.length;h<g;++h)for(c=p[h];c=c.next;)++m;var w=l(2*m*1.4,v,s),M=n.arcs=[];for(h=0,g=y.length;h<g;++h){u=y[h];do r(u);while(u=u.next)}for(h=0,g=p.length;h<g;++h)if(c=p[h],c.next){do r(c);while(c=c.next)}else t(c);return n},w=function(n){for(var r=n.arcs,t=-1,e=r.length;++t<e;)for(var o,i,a=r[t],f=0,u=a.length,c=a[0],l=c[0],s=c[1];++f<u;)c=a[f],o=c[0],i=c[1],a[f]=[o-l,i-s],l=o,s=i;return n},M=function(n){function r(n){n&&c.hasOwnProperty(n.type)&&c[n.type](n)}function t(n){for(var r=0,t=n.length;r<t;++r)u[++i]=n[r];var e={0:i-t+1,1:i};return a.push(e),e}function e(n){for(var r=0,t=n.length;r<t;++r)u[++i]=n[r];var e={0:i-t+1,1:i};return f.push(e),e}function o(n){return n.map(e)}var i=-1,a=[],f=[],u=[],c={GeometryCollection:function(n){n.geometries.forEach(r)},LineString:function(n){n.arcs=t(n.coordinates),delete n.coordinates},MultiLineString:function(n){n.arcs=n.coordinates.map(t),delete n.coordinates},Polygon:function(n){n.arcs=n.coordinates.map(e),delete n.coordinates},MultiPolygon:function(n){n.arcs=n.coordinates.map(o),delete n.coordinates}};for(var l in n)r(n[l]);return{type:"Topology",coordinates:u,lines:a,rings:f,objects:n}},P=function(n){var r;for(r in n)n[r]=e(n[r]);return n},x={Feature:o,FeatureCollection:function(n){return n.type="GeometryCollection",n.geometries=n.features,n.features.forEach(o),delete n.features,n}},b={GeometryCollection:function(n){for(var r=n.geometries,t=-1,e=r.length;++t<e;)r[t]=i(r[t])},MultiPoint:function(n){n.coordinates.length?n.coordinates.length<2&&(n.type="Point",n.coordinates=n.coordinates[0]):(n.type=null,delete n.coordinates)},LineString:function(n){n.coordinates.length||(n.type=null,delete n.coordinates)},MultiLineString:function(n){for(var r=n.coordinates,t=0,e=0,o=r.length;t<o;++t){var i=r[t];i.length&&(r[e++]=i)}e?e<2?(n.type="LineString",n.coordinates=r[0]):n.coordinates.length=e:(n.type=null,delete n.coordinates)},Polygon:function(n){for(var r=n.coordinates,t=0,e=0,o=r.length;t<o;++t){var i=r[t];i.length&&(r[e++]=i)}e?n.coordinates.length=e:(n.type=null,delete n.coordinates)},MultiPolygon:function(n){for(var r=n.coordinates,t=0,e=0,o=r.length;t<o;++t){for(var i=r[t],a=0,f=0,u=i.length;a<u;++a){var c=i[a];c.length&&(i[f++]=c)}f&&(i.length=f,r[e++]=i)}e?e<2?(n.type="Polygon",n.coordinates=r[0]):r.length=e:(n.type=null,delete n.coordinates)}},E=function(n,r,t){function e(n){return n[0]=Math.round((n[0]-a)*l),n[1]=Math.round((n[1]-f)*s),n}function o(n){for(var r,t,o,i=0,a=1,f=n.length,u=e(n[0]),c=u[0],l=u[1];++i<f;)u=e(n[i]),t=u[0],o=u[1],t===c&&o===l||(r=n[a++],r[0]=c=t,r[1]=l=o);n.length=a}function i(n){n&&h.hasOwnProperty(n.type)&&h[n.type](n)}var a=r[0],f=r[1],u=r[2],c=r[3],l=u-a?(t-1)/(u-a):1,s=c-f?(t-1)/(c-f):1,h={GeometryCollection:function(n){n.geometries.forEach(i)},Point:function(n){e(n.coordinates)},MultiPoint:function(n){n.coordinates.forEach(e)},LineString:function(n){var r=n.coordinates;o(r),r.length<2&&(r[1]=r[0])},MultiLineString:function(n){for(var r=n.coordinates,t=0,e=r.length;t<e;++t){var i=r[t];o(i),i.length<2&&(i[1]=i[0])}},Polygon:function(n){for(var r=n.coordinates,t=0,e=r.length;t<e;++t){var i=r[t];for(o(i);i.length<4;)i.push(i[0])}},MultiPolygon:function(n){for(var r=n.coordinates,t=0,e=r.length;t<e;++t)for(var i=r[t],a=0,f=i.length;a<f;++a){var u=i[a];for(o(u);u.length<4;)u.push(u[0])}}};for(var g in n)i(n[g]);return{scale:[1/l,1/s],translate:[a,f]}},L=function(n,r){function t(n){n&&d.hasOwnProperty(n.type)&&d[n.type](n)}function e(n){var r=[];do{var t=g.get(n);r.push(n[0]<n[1]?t:~t)}while(n=n.next);return r}function o(n){return n.map(e)}var i=u(P(n)),c=r>0&&i&&E(n,i,r),s=m(p(M(n))),h=s.coordinates,g=l(1.4*s.arcs.length,a,f);n=s.objects,s.bbox=i,s.arcs=s.arcs.map(function(n,r){return g.set(n,r),h.slice(n[0],n[1]+1)}),delete s.coordinates,h=null;var d={GeometryCollection:function(n){n.geometries.forEach(t)},LineString:function(n){n.arcs=e(n.arcs)},MultiLineString:function(n){n.arcs=n.arcs.map(e)},Polygon:function(n){n.arcs=n.arcs.map(e)},MultiPolygon:function(n){n.arcs=n.arcs.map(o)}};for(var v in n)t(n[v]);return c&&(s.transform=c,w(s)),s};n.topology=L,Object.defineProperty(n,"__esModule",{value:!0})});