// 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/LineBucket","require exports ../../core/tsSupport/extendsHelper ../../core/tsSupport/decorateHelper ./Bucket ../2d/engine/webgl/LineTess ./style/StyleLayer".split(" "),function(u,v,q,w,r,f,t){var l=new f.Tessellator({distanceAlongCorrection:!0});return function(p){function c(a,b,e,d){b=p.call(this,a,b)||this;b.extrudeVectorsDoubleBuffer=[f.allocExtrudeVectors(),f.allocExtrudeVectors()];b.firstExtrudeVectors=f.allocExtrudeVectors();b.recycledTriangleBridge=
f.allocTriangles(20);b.recycledTrianglePie=f.allocTriangles(20);if(a.hasDataDrivenLine!==e.isDataDriven())throw Error("incompatible line buffer");b._lineVertexBuffer=e;b._lineIndexBuffer=d;return b}q(c,p);Object.defineProperty(c.prototype,"lineIndexStart",{get:function(){return this._lineIndexStart},enumerable:!0,configurable:!0});Object.defineProperty(c.prototype,"lineIndexCount",{get:function(){return this._lineIndexCount},enumerable:!0,configurable:!0});Object.defineProperty(c.prototype,"connectorStart",
{get:function(){return 0},enumerable:!0,configurable:!0});Object.defineProperty(c.prototype,"connectorCount",{get:function(){return 0},enumerable:!0,configurable:!0});c.prototype.assignBufferInfo=function(a){a._lineIndexStart=this._lineIndexStart;a._lineIndexCount=this._lineIndexCount};c.prototype.processFeatures=function(a,b){this._lineIndexStart=this._lineIndexBuffer.index;this._lineIndexCount=0;var e=this.layer,d=this.zoom,h=e.hasDataDrivenLine;a&&a.setExtent(this.layerExtent);for(var n=e.getPaintValue("line-pattern",
d),g=0,k=this._features;g<k.length;g++){var f=k[g],m=new t.LineLayout(e,d,f),c=void 0;if(h&&(c={color:n?[1,1,1,1]:e.getPaintValue("line-color",d,f),opacity:e.getPaintValue("line-opacity",d,f),size:Math.max(Math.min(e.getPaintValue("line-width",d,f),256),0)},0>=c.size||0>=c.opacity||0>=c.color[3]))continue;f=f.getGeometry(a);this._processFeature(m,f,c)}};c.prototype._processFeature=function(a,b,e){if(b)for(var d=b.length,h=0;h<d;h++)this._processGeometry(b[h],a,e)};c.prototype._processGeometry=function(a,
b,e){if(!(2>a.length)){for(var d=a[0],h=a[a.length-1],n=h.x-d.x,h=h.y-d.y,d=1E-6>n*n+h*h,g=a[0],k=1;k<a.length;)n=a[k].x-g.x,h=a[k].y-g.y,1E-6>n*n+h*h?a.splice(k,1):(g=a[k],++k);if(!(2>a.length)){this.vertices=a;this.verticesLen=a.length;this.isClosed=d;this.cap=b.cap;this.join=b.join;this.almostParallelRads=.05;this.veryShallowRads=.1;this.miterSafeRads=f.MITER_SAFE_RADS;this.miterLimitMag=Math.min(b.miterLimit,f.SYSTEM_MAG_LIMIT);this.roundLimitRads=Math.min(b.roundLimit,.5);this.newRoundJoinsSafeRads=
2.3;b=this._lineIndexBuffer.index;for(var n=0,c=void 0,h=this.verticesLen,g=0;g<h;++g){var k=a[g],m=a[(g+h-1)%h],l=d&&this._isClipEdge(m,k),m=c===this.extrudeVectorsDoubleBuffer[g%2]?this.extrudeVectorsDoubleBuffer[(g+1)%2]:this.extrudeVectorsDoubleBuffer[g%2];g<h-1||!d||this.hasPattern?(this._computeExtrudeVectors(m,g),this._writeGPUVertices(k.x,k.y,n,m,e),!m.capCenter||d&&g===h-1||this._writeGPUPieElements(m,l),d&&0===g&&!this.hasPattern&&f.copyExtrudeVectors(this.firstExtrudeVectors,m)):f.copyExtrudeVectors(m,
this.firstExtrudeVectors);c&&this._writeGPUBridgeElements(c,m,l);g<h-1&&(c=a[g+1],k=f.length([c.x-k.x,c.y-k.y]),n+=k);c=m}this._lineIndexCount+=3*(this._lineIndexBuffer.index-b)}}};c.prototype._computeExtrudeVectors=function(a,b){var e=this.vertices,d=this.verticesLen,h=this.isClosed,c=e[b],g=[void 0,void 0],k=[void 0,void 0];if(0<b&&b<d-1){var l=e[(b+d-1)%d],m=e[(b+1)%d];f.normalize(g,[c.x-l.x,c.y-l.y]);f.normalize(k,[m.x-c.x,m.y-c.y])}else if(0===b)m=e[(b+1)%d],f.normalize(k,[m.x-c.x,m.y-c.y]),
h?(e=e[d-2],f.normalize(g,[c.x-e.x,c.y-e.y])):g=k;else if(b===d-1)l=e[(b+d-1)%d],f.normalize(g,[c.x-l.x,c.y-l.y]),h?(e=e[1],f.normalize(k,[e.x-c.x,e.y-c.y])):k=g;else{console.error("Vertex index 'i' out of range.");return}h||0!==b?h||b!==d-1?this._computeJoinExtrudeVectors(a,g,k):this._computeCapExtrudeVectors(a,g,k,f.CapPosition.END):this._computeCapExtrudeVectors(a,g,k,f.CapPosition.START)};c.prototype._computeCapExtrudeVectors=function(a,b,e,d){0===this.cap?l.buttCap(a,b,e):1===this.cap?l.roundCap(a,
b,e,d,f.getNumberOfSlices(Math.PI),d===f.CapPosition.START?-1:1):2===this.cap?l.squareCap(a,b,e,d):l.buttCap(a,b,e)};c.prototype._computeJoinExtrudeVectors=function(a,b,e){var d=f.getRads(b,e);if(d>Math.PI-this.almostParallelRads)l.rectJoin(a,b,e);else if(0===this.join&&d>=this.veryShallowRads)l.bevelJoin(a,b,e,1);else if(1===this.join&&d>=this.veryShallowRads){var c=f.getNumberOfSlices(d);d<this.newRoundJoinsSafeRads?2>c||d<this.roundLimitRads?l.bevelJoin(a,b,e,1):l.roundJoin(a,b,e,c):l.unitRoundJoin(a,
b,e,c)}else d<this.almostParallelRads?l.fastMiterJoin(a,b,e):d<this.miterSafeRads?l.miterJoin(a,b,e):l.bevelJoin(a,b,e,this.miterLimitMag)};c.prototype._writeGPUVertices=function(a,b,e,d,c){for(var f=0;f<d.vectors.count;++f){var g=d.vectors.items[f].vector[0],k=d.vectors.items[f].vector[1],h=d.vectors.items[f].texCoords[0],l=d.vectors.items[f].texCoords[1];d.vectors.items[f].base=this._lineVertexBuffer.index;this._lineVertexBuffer.add(a,b,g,k,h,l,e,c)}};c.prototype._writeGPUBridgeElements=function(a,
b,c){l.bridge(this.recycledTriangleBridge,a,b);if(!c)for(a=0;a<this.recycledTriangleBridge.count;++a)b=this.recycledTriangleBridge.items[a],this._lineIndexBuffer.add(b.v1.base,b.v2.base,b.v3.base)};c.prototype._writeGPUPieElements=function(a,b){l.pie(this.recycledTrianglePie,a);if(!b)for(var c=0;c<this.recycledTrianglePie.count;++c){var d=this.recycledTrianglePie.items[c];this._lineIndexBuffer.add(d.v1.base,d.v2.base,d.v3.base)}};c.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};return c}(r)});