!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("d3-array"),require("d3-polygon")):"function"==typeof define&&define.amd?define(["exports","d3-array","d3-polygon"],i):i(t.d3=t.d3||{},t.d3,t.d3)}(this,function(t,i,n){"use strict";function e(t){return t<=C&&t>=-C}function s(t,i){return t.x*i.x+t.y*i.y+t.z*i.z}function o(t,i){return e(t.x*i.y-t.y*i.x)&&e(t.y*i.z-t.z*i.y)&&e(t.z*i.x-t.x*i.z)}function r(t){var i,n,e,s,o,r,u,c;if(e=t[t.length-2],s=t[t.length-1],o=t[0],r=h(e,s),u=h(s,o),n=l(r,u),i=Math.sign(n),e=s,s=o,o=t[1],r=u,u=h(s,o),n=l(r,u),Math.sign(n)===i){for(c=2;cC||b>C)&&(g.push([E,j]),y=E,z=j)}if(d.nonClippedPolygon=g.reverse(),!d.isDummy&&n.polygonLength(d.nonClippedPolygon)>0){var q=w(e,d.nonClippedPolygon);d.polygon=q,q.site=d,q.length>0&&r.push(q)}}}}return r}function P(){function t(t){var i;return i=t.map(function(t){return new a(s(t),o(t),null,h(t),t,(!1))}),F(i,e(),l)}function e(){var t,i,n,e,s,o,r,h,l,c,f=[],p=[];t=u[0][0],i=u[1][0],n=u[0][1],e=u[1][1],s=i-t,o=e-n,r=t-s,h=i+s,l=n-o,c=e+o,f[0]=[r,l],f[1]=[r,c],f[2]=[h,c],f[3]=[h,l];for(var d=0;d<4;d++)p.push(new a(f[d][0],f[d][1],null,C,new a(f[d][0],f[d][1],null,C,null,(!0)),(!0)));return p}var s=function(t){return t.x},o=function(t){return t.y},h=function(t){return t.weight},l=[[0,0],[0,1],[1,1],[1,0]],u=[[0,0],[1,1]],c=[1,1];return t.x=function(i){return arguments.length?(s=i,t):s},t.y=function(i){return arguments.length?(o=i,t):o},t.weight=function(i){return arguments.length?(h=i,t):h},t.clip=function(e){var s,o,h;return arguments.length?(o=i.extent(e.map(function(t){return t[0]})),h=i.extent(e.map(function(t){return t[1]})),s=r(e),l=void 0===s?n.polygonHull(e):1===s?e.reverse():e,u=[[o[0],h[0]],[o[1],h[1]]],c=[o[1]-o[0],h[1]-h[0]],t):l},t.extent=function(i){return arguments.length?(l=[i[0],[i[0][0],i[1][1]],i[1],[i[1][0],i[0][1]]],u=i,c=[i[1][0]-i[0][0],i[1][1]-i[0][1]],t):u},t.size=function(i){return arguments.length?(l=[[0,0],[0,i[1]],[i[0],i[1]],[i[0],0]],u=[[0,0],i],c=i,t):c},t}var C=1e-10;c.prototype.add=function(t){null===this.head?this.head=t:this.forFace?(this.head.prevv=t,t.nextv=this.head,this.head=t):(this.head.prevf=t,t.nextf=this.head,this.head=t)},c.prototype.isEmpty=function(){return null===this.head},c.prototype.fill=function(t){if(!this.forFace){var i=this.head;do t.push(i.face),i.face.marked=!0,i=i.nextf;while(null!==i)}},c.prototype.removeAll=function(){if(this.forFace){var t=this.head;do null===t.prevf?null===t.nextf?t.vert.conflicts.head=null:(t.nextf.prevf=null,t.vert.conflicts.head=t.nextf):(null!=t.nextf&&(t.nextf.prevf=t.prevf),t.prevf.nextf=t.nextf),t=t.nextv,null!=t&&(t.prevv=null);while(null!=t)}else{var t=this.head;do null==t.prevv?null==t.nextv?t.face.conflicts.head=null:(t.nextv.prevv=null,t.face.conflicts.head=t.nextv):(null!=t.nextv&&(t.nextv.prevv=t.prevv),t.prevv.nextv=t.nextv),t=t.nextf,null!=t&&(t.prevf=null);while(null!=t)}},c.prototype.getVertices=function(){for(var t=[],i=this.head;null!==i;)t.push(i.vert),i=i.nextv;return t},a.prototype.projectZ=function(t,i,n){return t*t+i*i-n},a.prototype.setWeight=function(t){this.weight=t,this.z=this.projectZ(this.x,this.y,this.weight)},a.prototype.subtract=function(t){return new a(t.x-this.x,t.y-this.y,t.z-this.z)},a.prototype.crossproduct=function(t){return new a(this.y*t.z-this.z*t.y,this.z*t.x-this.x*t.z,this.x*t.y-this.y*t.x)},a.prototype.equals=function(t){return this.x===t.x&&this.y===t.y&&this.z===t.z},f.prototype.getNormZPlane=function(){return[-1*(this.a/this.c),-1*(this.b/this.c),-1*(this.d/this.c)]},f.prototype.getDualPointMappedToPlane=function(){var t=this.getNormZPlane(),i=new p(t[0]/2,t[1]/2);return i},d.prototype.negate=function(){this.x*=-1,this.y*=-1,this.z*=-1},d.prototype.normalize=function(){var t=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);t>0&&(this.x/=t,this.y/=t,this.z/=t)},v.prototype.isHorizon=function(){return null!==this.twin&&!this.iFace.marked&&this.twin.iFace.marked},v.prototype.findHorizon=function(t){if(this.isHorizon()){if(t.length>0&&this===t[0])return;t.push(this),this.next.findHorizon(t)}else null!==this.twin&&this.twin.next.findHorizon(t)},v.prototype.isEqual=function(t,i){return this.orig.equals(t)&&this.dest.equals(i)||this.orig.equals(i)&&this.dest.equals(t)},g.prototype.name="d3WeightedVoronoiError",g.prototype=new Error,y.prototype.getDualPoint=function(){if(null==this.dualPoint){var t=new f(this);this.dualPoint=t.getDualPointMappedToPlane()}return this.dualPoint},y.prototype.isVisibleFromBelow=function(){return this.normal.z<-1.4259414393190911e-9},y.prototype.createEdges=function(){this.edges=[],this.edges[0]=new v(this.verts[0],this.verts[1],this),this.edges[1]=new v(this.verts[1],this.verts[2],this),this.edges[2]=new v(this.verts[2],this.verts[0],this),this.edges[0].next=this.edges[1],this.edges[0].prev=this.edges[2],this.edges[1].next=this.edges[2],this.edges[1].prev=this.edges[0],this.edges[2].next=this.edges[0],this.edges[2].prev=this.edges[1]},y.prototype.orient=function(t){if(!(s(this.normal,t)s(this.normal,this.verts[0])+C},y.prototype.getHorizon=function(){for(var t=0;t<3;t++)if(null!==this.edges[t].twin&&this.edges[t].twin.isHorizon())return this.edges[t];return null},y.prototype.removeConflict=function(){this.conflicts.removeAll()},x.prototype.init=function(t,i){this.points=[];for(var n=0;n0;i--){var n=Math.floor(Math.random()*i),e=this.points[n];e.index=i;var s=this.points[i];s.index=n,this.points.splice(n,1,s),this.points.splice(i,1,e)}},x.prototype.prep=function(){if(this.points.length<=3)throw new g("Less than 4 points");for(var t=0;ts.index?(u.push(e),o++):(u.push(s),r++)):o=0;o--)e=u[o],n.conflict(e)&&this.addConflict(n,e)},x.prototype.addConflict=function(t,i){var n=new u(t,i);t.conflicts.add(n),i.conflicts.add(n)},x.prototype.removeConflict=function(t){t.removeConflict();var i=t.index;if(t.index=-1,i===this.facets.length-1)return void this.facets.splice(this.facets.length-1,1);if(!(i>=this.facets.length||i<0)){var n=this.facets.splice(this.facets.length-1,1);n[0].index=i,this.facets.splice(i,1,n[0])}},x.prototype.addFacet=function(t){t.index=this.facets.length,this.facets.push(t)},x.prototype.compute=function(){for(this.prep();this.current