/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{releaseMaybe as t}from"../../../core/maybe.js";import{maxUint16 as e}from"../../../core/typedArrayUtil.js";import{add as s}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{empty as i}from"../../../geometry/support/aaBoundingBox.js";import{internalAssert as r}from"./terrainUtils.js";import{decompressNormal as n,compressNormal as o}from"../webgl-engine/lib/Normals.js";class d{constructor(){this.indices=null,this.indexCount=0,this.edgeIndicesStartIndex=0,this.poleIndicesStartIndex=0,this.vertexAttributes=null,this.edgeVerticesStartIndex=0,this.poleVerticesStartIndex=0,this.maxEdgeVertexCount=0,this.boundingBox=i(),this.numVerticesPerSide=0,this.minu=0,this.minv=0,this.maxu=1,this.maxv=1,this.outerEdgesOffsetAndLength=[0,0,0,0,0,0,0,0]}release(){this.vertexAttributes=t(this.vertexAttributes),this.indices=null}reset(){this.indices=null,this.vertexAttributes=null,i(this.boundingBox),this.numVerticesPerSide=0}getEdgeFirstVertexIndex(t){return this.outerEdgesOffsetAndLength[2*t]}getEdgeCount(t){return this.outerEdgesOffsetAndLength[2*t+1]}getEdgeVertexIndex(t,e){return this.getEdgeAttributeIndex(t,e)}getEdgeVertexPosition(t,e,i,r){this._getEdgeVertexRaw(this.getEdgeAttributeIndex(t,r),e),s(e,e,i)}getEdgeNormal(t,e,s){const{typedBuffer:i,typedBufferStride:r}=this.vertexAttributes.normalCompressed;n(e,i,this.getEdgeAttributeIndex(t,s),r)}setEdgeNormalFromValues(t,e,s,i,r){this._setNormal(this.getEdgeAttributeIndex(t,e),s,i,r)}setEdgeVertexFromValuesRawPositionUV(t,e,s,i,r,n,o){const d=this.getEdgeAttributeIndex(t,e);this.vertexAttributes.position.setValues(d,s,i,r),this._setUV(d,n,o)}setEdgeVertexFromValuesRawPositionUVNormal(t,e,s,i,r,n,o,d,u,g){const h=this.getEdgeAttributeIndex(t,e);this.vertexAttributes.position.setValues(h,s,i,r),this._setUV(h,n,o),this._setNormal(h,d,u,g)}_getEdgeVertexRaw(t,e){this.vertexAttributes.position.getVec(t,e)}_setNormal(t,e,s,i){const{typedBuffer:r,typedBufferStride:n}=this.vertexAttributes.normalCompressed;o(r,t,e,s,i,n)}_setUV(t,s,i){this.vertexAttributes.uv0.setValues(t,Math.round(s*e),Math.round(i*e))}getEdgeAttributeIndex(t,e){return r(0<=e&&e<this.getEdgeCount(t)),this.getEdgeFirstVertexIndex(t)+e}}export{d as PatchGeometry};
