/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{set as e,subtract as t,scale as s,add as i,normalize as r}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";class o{rebuildConnectingProfileGeometry(e,t,s){for(let i=0;i<t.vertices.length;++i)s(e.frame,t.vertices[i],t.normals[i],0,0)}}class l extends o{constructor(){super(),this.numVertices=0,this.numIndices=0}rebuildCapGeometry(){}buildTopology(){}}class f extends o{constructor(e,t=0,s=!1){super(),this.profile=e,this.profilePlaneOffset=t,this.flip=s}get numVertices(){return this.profile.vertices.length}get numIndices(){return 3*this.profile.numSegments}rebuildConnectingProfileGeometry(e,t,s){const i=this.profilePlaneOffset;for(let r=0;r<t.vertices.length;++r)s(e.frame,t.vertices[r],t.normals[r],i,0)}rebuildCapGeometry(t,s){const i=this.profile,r=this.flip?1:-1,n=this.profilePlaneOffset,o=m;e(o,0,0);for(let e=0;e<i.vertices.length;++e)s(t.frame,i.vertices[e],o,n,r)}buildTopology(e,t){const s=this.profile,i=this.vertexBufferStart+s.indices[0];for(let r=1;r<s.numSegments;++r){const e=s.indices[2*r],n=s.indices[2*r+1],o=this.vertexBufferStart+e,l=this.vertexBufferStart+n;this.flip?t(l,o,i):t(i,o,l)}}}class h extends o{constructor(e){super(),this.flip=!1,this.sign=0,this.breakNormals=!1,this.numSegments=3,this.profile=e.profile,this.flip=e.flip,this.sign=this.flip?1:-1,this.breakNormals=e.breakNormals,this.numSegments=e.subdivisions}get numVertices(){let e=this.profile.vertices.length*(this.numSegments-1)+this.profile.poles.length;return this.breakNormals&&(e+=this.profile.vertices.length),e}get numIndices(){let e=0;const t=this.profile;e+=2*t.numSegments*(this.numSegments-1);for(let s=0;s<t.numSegments;++s){const i=t.indices[2*s],r=t.indices[2*s+1];t.poleIndices[i]===t.poleIndices[r]?e+=1:e+=2}return 3*e}rebuildCapGeometry(n,o){const l=this.profile,f=n.frame,h=.5*this.sign,p=c,a=m;e(a,0,0);for(const e of l.poles)e.normal?o(f,e.position,e.normal,h,0):o(f,e.position,a,h,this.sign);if(this.breakNormals)for(let e=0;e<l.vertices.length;++e)o(f,l.vertices[e],l.normals[e],0,0);for(let e=0;e<this.numSegments-1;++e){const n=(1-(e+1)/this.numSegments)*Math.PI*.5,c=Math.sin(n),m=Math.cos(n);for(let e=0;e<l.vertices.length;++e){const n=l.poles[l.poleIndices[e]];t(p,l.vertices[e],n.position),s(p,p,c),n.normal?(i(p,p,n.position),o(f,p,n.normal,h*m,0)):(r(a,p),s(a,a,c),i(p,p,n.position),o(f,p,a,h*m,this.sign*m))}}}buildTopology(e,t){const s=this.profile,i=this.breakNormals?this.vertexBufferStart+s.poles.length:this.firstProfileVertexIndex,r=this.breakNormals?this.vertexBufferStart+s.poles.length+s.vertices.length:this.vertexBufferStart+s.poles.length;for(let n=0;n<s.numSegments;++n){const e=s.indices[2*n],o=s.indices[2*n+1],l=this.vertexBufferStart+s.poleIndices[e],f=this.vertexBufferStart+s.poleIndices[o];let h=i+e,c=i+o;for(let i=0;i<this.numSegments-1;++i){const n=r+i*s.vertices.length+e,l=r+i*s.vertices.length+o;this.flip?(t(n,c,h),t(c,n,l)):(t(h,c,n),t(l,n,c)),h=n,c=l}this.flip?(t(l,c,h),l!==f&&t(l,f,c)):(t(h,c,l),l!==f&&t(c,f,l))}}}const c=n(),m=n();export{l as NoCapBuilder,o as PathCapBuilder,h as RoundCapBuilder,f as TriangulationCapBuilder};
