/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{copy as t,set as e,length as i,normalize as s,dot as r,scale as o,add as a}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{cross as l,set as h}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as c}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{copy as p}from"../../../../core/libs/gl-matrix-2/math/vec4.js";import{fromValues as m}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{newFloatArray as u}from"../../../../geometry/support/FloatArray.js";import{newHalfFloatArray as f}from"../../../../geometry/support/HalfFloatArray.js";import{getZeroIndexArray as b}from"../../../../geometry/support/Indices.js";import{Attribute as d,Vertices as g}from"./Attribute.js";import{decompressNormal as v,compressNormal as x}from"./Normals.js";import{intersectTriangles as A}from"./RayIntersections.js";class w{constructor(t){this.builder=t}onPathChanged(t){this.builder.onPathChanged()}}class y extends w{constructor(t){super(t),this.color=m(255,255,255,255),this._size=n(),this.positions=u(3*this.builder.numVerticesTotal),this.normals=new Int16Array(2*this.builder.numVerticesTotal)}bakeVertexColors(t){p(this.color,t)}bake(n){t(this._size,n);const{numVerticesTotal:c,pathVertexData:p,positions:m,profileRightAxes:u,profileUpAxes:f,profileVertexAndNormals:b,profileAuxData:d}=this.builder;for(let t=0;t<c;++t){let c=p[t];c*=3;const g=_;let A=0,w=0;const y=v(I,u,t),j=v(D,f,t),P=4*t,F=e(V,b[P]*n[0],b[P+1]*n[1]),k=3*t;if(1===d[k+2])l(g,j,y),A=d[k]*n[0],w=d[k+1];else{const t=C,n=z;e(t,d[k],d[k+1]);const l=i(t);s(t,t);const c=r(F,t);if(Math.abs(c)>l){e(n,-t[1],t[0]);const i=r(F,n);o(t,t,l*Math.sign(c)),o(n,n,i),a(F,t,n)}h(g,0,0,0)}const N=y[0]*F[0]+j[0]*F[1],R=y[1]*F[0]+j[1]*F[1],M=y[2]*F[0]+j[2]*F[1];this.positions[k]=m[c]+N+g[0]*A,this.positions[k+1]=m[c+1]+R+g[1]*A,this.positions[k+2]=m[c+2]+M+g[2]*A;const T=b[P+2],U=b[P+3];x(this.normals,t,y[0]*T+j[0]*U+g[0]*w,y[1]*T+j[1]*U+g[1]*w,y[2]*T+j[2]*U+g[2]*w)}}createGeometryData(){const t=this.builder.vertexIndices;return[["position",new d(this.positions,t,3,!0)],["normalCompressed",new d(this.normals,t,2,!0)],["color",new d(this.color,b(t.length),4,!0)]]}onPathChanged(t){super.onPathChanged(t),this.bake(this.size)}intersect(t,e,i,s){const r=this.builder.vertexIndices,o=new g(this.positions,3),a=r.length/3;A(t,e,0,a,r,o,void 0,i,(t,e,i)=>s(t,i,e))}get size(){return this._size}}class j extends w{constructor(t,e,i,s){super(t),this.sizeAttributeValue=e,this.colorAttributeValue=i,this.opacityAttributeValue=s,this.baked=new y(t),this._vvSize=u(this.builder.path.vertices.length).fill(e),this._vvColor=f(this.builder.path.vertices.length).fill(i),this._vvOpacity=f(this.builder.path.vertices.length).fill(s)}createGeometryData(){const t=this.builder,{pathVertexIndices:e,vertexIndices:i}=t;return[["position",new d(t.positions,e,3,!0)],["profileVertexAndNormal",new d(t.profileVertexAndNormals,i,4,!0)],["profileAuxData",new d(t.profileAuxData,i,3,!0)],["profileRight",new d(t.profileRightAxes,i,2,!0)],["profileUp",new d(t.profileUpAxes,i,2,!0)],["sizeFeatureAttribute",new d(this._vvSize,e,1,!0)],["colorFeatureAttribute",new d(this._vvColor,e,1,!0)],["opacityFeatureAttribute",new d(this._vvOpacity,e,1,!0)]]}onPathChanged(t){super.onPathChanged(t);const e=t.getMutableAttribute("position");e&&(e.data=this.builder.positions)}}const V=n(),C=n(),z=n(),_=c(),I=c(),D=c();export{j as FastUpdatePathGeometry,w as PathGeometryData,y as StaticPathGeometry};
