/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../core/has","../../../../core/maybe","../../../../core/typedArrayUtil","../../../../chunks/vec2","../../../../chunks/vec3","../../../../chunks/vec3f64","../../../../geometry/projection","../../../../geometry/projectionEllipsoid","../../../../geometry/support/triangulationUtils","../../../ViewingMode","./constants","./elevationAlignmentUtils","../../terrain/OverlayRenderer","../../webgl-engine/lib/basicInterfaces","../../webgl-engine/lib/Geometry","../../webgl-engine/lib/VertexAttribute","../../webgl-engine/shaders/RibbonLineTechniqueConfiguration"],(function(e,t,n,r,o,i,a,s,u,l,c,p,T,A,E,f,b,g){"use strict";function y(e){const t=[],n=[];I(e,n,t);const r=n[0][1].data,o=t[0][1].length,i=new Uint16Array(o);return O(e,n,t),C(e,n,t,i),m(e,n,t,i),S(e,n,t,i),v(e,n,t,i),w(e,n,t,i),V(e,n,t,r),new f.Geometry(n,t,E.PrimitiveType.Line)}function d(e,t,n,r){const o="polygon"===e.type?l.CounterClockwiseMode.CCW_IS_HOLE:l.CounterClockwiseMode.NONE,i="polygon"===e.type?e.rings:e.paths,{position:a,outlines:s}=l.pathsToTriangulationInfo(i,e.hasZ,o),u=new Float64Array(a.length),c=T.applyPerVertexElevationAlignment(a,e.spatialReference,0,u,0,a,0,a.length/3,t,n,r),p=null!=c;return{lines:p?h(s,a,u):[],projectionSuccess:p,sampledElevation:c}}function h(e,t,n){const r=new Array;for(const{index:o,count:i}of e){if(i<=1)continue;const e=3*o,a=e+3*i;r.push({position:t.subarray(e,a),mapPosition:n?n.subarray(e,a):void 0})}return r}function R(e,t){const n="polygon"===e.type?l.CounterClockwiseMode.CCW_IS_HOLE:l.CounterClockwiseMode.NONE,r="polygon"===e.type?e.rings:e.paths,{position:o,outlines:i}=l.pathsToTriangulationInfo(r,!1,n),a=s.projectBuffer(o,e.spatialReference,0,o,t,0,o.length/3);for(let s=2;s<o.length;s+=3)o[s]=A.DRAPED_Z;return{lines:a?h(i,o):[],projectionSuccess:a}}function I(t,n,o){const{attributeData:{position:i},removeDuplicateStartEnd:a}=t,s=x(i)&&a===e.RemoveDuplicateStartEnd.REMOVE,u=i.length/3-(s?1:0),l=new Uint32Array(2*(u-1)),c=s?r.slice(i,0,i.length-3):i;let p=0;for(let e=0;e<u-1;e++)l[p++]=e,l[p++]=e+1;n.push([b.VertexAttribute.POSITION,{size:3,data:c,exclusive:s}]),o.push([b.VertexAttribute.POSITION,l])}function O(e,t,r){const o=e.attributeData.mapPosition;n.isNone(o)||(r.push([b.VertexAttribute.MAPPOS,r[0][1]]),t.push([b.VertexAttribute.MAPPOS,{size:3,data:o}]))}function C(e,t,r,o){if(n.isSome(e.attributeData.colorFeature))return;const i=e.attributeData.color;t.push([b.VertexAttribute.COLOR,{size:4,data:n.unwrapOr(i,p.WHITE_UNIT)}]),r.push([b.VertexAttribute.COLOR,o])}function S(e,t,r,o){const i=e.attributeData.colorFeature;n.isNone(i)||(t.push([b.VertexAttribute.COLORFEATUREATTRIBUTE,{size:1,data:new Float32Array([i])}]),r.push([b.VertexAttribute.COLOR,o]))}function m(e,t,r,o){if(n.isSome(e.attributeData.sizeFeature))return;const i=e.attributeData.size;t.push([b.VertexAttribute.SIZE,{size:1,data:[n.unwrapOr(i,1)]}]),r.push([b.VertexAttribute.SIZE,o])}function v(e,t,r,o){const i=e.attributeData.sizeFeature;n.isNone(i)||(t.push([b.VertexAttribute.SIZEFEATUREATTRIBUTE,{size:1,data:new Float32Array([i])}]),r.push([b.VertexAttribute.SIZEFEATUREATTRIBUTE,o]))}function w(e,t,r,o){const i=e.attributeData.opacityFeature;n.isNone(i)||(t.push([b.VertexAttribute.OPACITYFEATUREATTRIBUTE,{size:1,data:new Float32Array([i])}]),r.push([b.VertexAttribute.OPACITYFEATUREATTRIBUTE,o]))}function V(e,t,r,a){if(n.isNone(e.overlayInfo)||e.overlayInfo.renderCoordsHelper.viewingMode!==c.ViewingMode.Global||!e.overlayInfo.spatialReference.isGeographic)return;const l=new Float64Array(a.length),p=u.getReferenceEllipsoid(e.overlayInfo.spatialReference);for(let n=0;n<l.length;n+=3)s.lonLatToWebMercatorComparable(a,n,l,n,p);const T=a.length/3,A=new Float32Array(T+1);let E=U,f=F,g=0,y=0;i.set(E,l[y++],l[y++],l[y++]),A[0]=0;for(let n=1;n<T+1;++n)n===T&&(y=0),i.set(f,l[y++],l[y++],l[y++]),g+=o.dist(E,f),A[n]=g,[E,f]=[f,E];t.push([b.VertexAttribute.DISTANCETOSTART,{size:1,data:A}]),r.push([b.VertexAttribute.DISTANCETOSTART,r[0][1]])}function x(e){const t=e.length;return e[0]===e[t-3]&&e[1]===e[t-2]&&e[2]===e[t-1]}var D;e.RemoveDuplicateStartEnd=void 0,(D=e.RemoveDuplicateStartEnd||(e.RemoveDuplicateStartEnd={}))[D.KEEP=0]="KEEP",D[D.REMOVE=1]="REMOVE";const U=a.create(),F=a.create();function P(e){switch(e){case"butt":return g.CapType.BUTT;case"square":return g.CapType.SQUARE;case"round":return g.CapType.ROUND;default:return null}}e.createGeometry=y,e.geometryToRenderInfo=d,e.geometryToRenderInfoDraped=R,e.parseCapType=P,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
