// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/layers/vectorTiles/views/vectorTiles/FillBucket","require exports ../../core/tsSupport/extendsHelper ../../core/tsSupport/decorateHelper ../../core/ArrayPool ./Bucket ../2d/engine/webgl/Geometry ../../core/libs/earcut/earcut".split(" "),function(F,G,C,H,A,D,y,E){return function(B){function g(a,b,d,c,q,e){b=B.call(this,a,b)||this;if(a.hasDataDrivenFill!==d.isDataDriven())throw Error("incompatible fill buffer");if(a.hasDataDrivenOutline!==q.isDataDriven())throw Error("incompatible outline buffer");
b._fillVertexBuffer=d;b._fillIndexBuffer=c;b._outlineVertexBuffer=q;b._outlineIndexBuffer=e;return b}C(g,B);Object.defineProperty(g.prototype,"fillIndexStart",{get:function(){return this._fillIndexStart},enumerable:!0,configurable:!0});Object.defineProperty(g.prototype,"fillIndexCount",{get:function(){return this._fillIndexCount},enumerable:!0,configurable:!0});Object.defineProperty(g.prototype,"outlineIndexStart",{get:function(){return this._outlineIndexStart},enumerable:!0,configurable:!0});Object.defineProperty(g.prototype,
"outlineIndexCount",{get:function(){return this._outlineIndexCount},enumerable:!0,configurable:!0});g.prototype.assignBufferInfo=function(a){a._fillIndexStart=this._fillIndexStart;a._fillIndexCount=this._fillIndexCount;a.layer.getPaintProperty("fill-outline-color")?(a._outlineIndexStart=this._outlineIndexStart,a._outlineIndexCount=this._outlineIndexCount):(a._outlineIndexStart=0,a._outlineIndexCount=0)};g.prototype.processFeatures=function(a,b){this._fillIndexStart=this._fillIndexBuffer.index;this._fillIndexCount=
0;this._outlineIndexStart=this._outlineIndexBuffer.index;this._outlineIndexCount=0;var d=this.layer,c=this.zoom,q=d.hasDataDrivenFill,e=d.hasDataDrivenOutline;a&&a.setExtent(this.layerExtent);for(var f=d.getPaintValue("fill-pattern",c),g=d.getPaintValue("fill-antialias",c)&&void 0===f,n=0,p=this._features;n<p.length;n++){var m=p[n],k=void 0;q&&(k={color:f?[1,1,1,1]:d.getPaintValue("fill-color",c,m),opacity:d.getPaintValue("fill-opacity",c,m)});var h=void 0;e&&(h={color:f?[1,1,1,1]:d.getPaintValue("fill-outline-color",
c,m),opacity:d.getPaintValue("fill-opacity",c,m)});m=m.getGeometry(a);this._processFeature(m,g,k,h)}};g.prototype._processFeature=function(a,b,d,c){if(a){var q=a.length;if(b)for(b=0;b<q;b++)this._processOutline(a[b],c);var e;for(b=0;b<q;b++)c=g._area(a[b]),128<c?(void 0!==e&&this._processFill(a,e,d),e=[b]):-128>c&&void 0!==e&&e.push(b);void 0!==e&&this._processFill(a,e,d)}};g.prototype._processOutline=function(a,b){var d=this._outlineVertexBuffer,c=this._outlineIndexBuffer,q=c.index,e,f,g,n=new y.Point(0,
0),p=new y.Point(0,0),m=new y.Point(0,0),k=-1,h=-1,l=-1,r=-1,x=-1,z=!1,t=a.length;if(!(2>t)){var w=a[0];for(e=a[t-1];t&&e.isEqual(w);)--t,e=a[t-1];if(!(2>t-0)){for(w=0;w<t;++w){0===w?(e=a[t-1],f=a[0],g=a[1],n.assignSub(f,e),n.normalize(),n.rightPerpendicular()):(e=f,f=g,g=w!==t-1?a[w+1]:a[0],n.assign(p));e=this._isClipEdge(e,f);-1===r&&(z=e);p.assignSub(g,f);p.normalize();p.rightPerpendicular();l=n.x*p.y-n.y*p.x;m.assignAdd(n,p);m.normalize();var u=-m.x*-n.x+-m.y*-n.y,u=Math.abs(0!==u?1/u:1);8<u&&
(u=8);0<=l?(l=d.add(f.x,f.y,n.x,n.y,0,1,b),-1===r&&(r=l),0<=k&&0<=h&&0<=l&&!e&&c.add(k,h,l),h=d.add(f.x,f.y,u*-m.x,u*-m.y,0,-1,b),-1===x&&(x=h),0<=k&&0<=h&&0<=l&&!e&&c.add(k,h,l),k=h,h=l,l=d.add(f.x,f.y,m.x,m.y,0,1,b),0<=k&&0<=h&&0<=l&&!e&&c.add(k,h,l),h=d.add(f.x,f.y,p.x,p.y,0,1,b)):(l=d.add(f.x,f.y,u*m.x,u*m.y,0,1,b),-1===r&&(r=l),0<=k&&0<=h&&0<=l&&!e&&c.add(k,h,l),h=d.add(f.x,f.y,-n.x,-n.y,0,-1,b),-1===x&&(x=h),0<=k&&0<=h&&0<=l&&!e&&c.add(k,h,l),k=h,h=l,l=d.add(f.x,f.y,-m.x,-m.y,0,-1,b),0<=k&&
0<=h&&0<=l&&!e&&c.add(k,h,l),k=d.add(f.x,f.y,-p.x,-p.y,0,-1,b));0<=k&&0<=h&&0<=l&&!e&&c.add(k,h,l)}0<=k&&0<=h&&0<=r&&!z&&c.add(k,h,r);0<=k&&0<=r&&0<=x&&!z&&c.add(k,x,r);this._outlineIndexCount+=3*(c.index-q)}}};g.prototype._processFill=function(a,b,d){var c;1<b.length&&(c=[]);for(var g=0,e=0;e<b.length;e++){var f=b[e];0!==g&&c.push(g);g+=a[f].length}for(var e=2*g,g=A.acquire(),v=0;v<b.length;v++)for(var f=b[v],f=a[f],n=f.length,p=0;p<n;++p)g.push(f[p].x),g.push(f[p].y);a=E(g,c,2);b=a.length;if(0<
b){c=this._fillVertexBuffer.index;for(v=0;v<e;)this._fillVertexBuffer.add(g[v++],g[v++],d);for(d=0;d<b;)this._fillIndexBuffer.add(c+a[d++],c+a[d++],c+a[d++]);this._fillIndexCount+=b}A.release(g)};g.prototype._isClipEdge=function(a,b){return a.x===b.x?-64>=a.x||4160<=a.x:a.y===b.y?-64>=a.y||4160<=a.y:!1};g._area=function(a){for(var b=0,d=a.length-1,c=0;c<d;c++)b+=(a[c].x-a[c+1].x)*(a[c].y+a[c+1].y);b+=(a[d].x-a[0].x)*(a[d].y+a[0].y);return.5*b};return g}(D)});