/*
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/maybe","../../../../core/uid","../../../../chunks/mat4f64","../../../../chunks/vec3","../../../../chunks/vec3f64","../../../../chunks/vec4f64","../../../../geometry/projection","./basicInterfaces","./Geometry","./LocalOriginFactory","./Object3D","./testUtils","./VertexAttribute","./WebGLLayer","../materials/RibbonLineMaterial"],(function(t,i,e,r,o,n,s,a,c,h,d,g,u,l,b,_){"use strict";let f=function(){function t(t,i=125e4){this._originSR=t,this._gridSize=i,this._origins=new Map,this._objects=new Map,this._rootOriginId="root/"+e.generateUID()}var n=t.prototype;return n.getOrigin=function(t){const e=this._origins.get(this._rootOriginId);if(null==e){const e=u.gridLocalOriginFactory.rootOrigin;if(i.isSome(e))return this._origins.set(this._rootOriginId,d.fromValues(e[0],e[1],e[2],this._rootOriginId)),this.getOrigin(t);const r=d.fromValues(t[0]+Math.random()-.5,t[1]+Math.random()-.5,t[2]+Math.random()-.5,this._rootOriginId);return this._origins.set(this._rootOriginId,r),r}const r=this._gridSize,n=Math.round(t[0]/r),s=Math.round(t[1]/r),a=Math.round(t[2]/r),c=`${n}/${s}/${a}`;let h=this._origins.get(c);const g=.5*r;if(o.subtract(m,t,e.vec3),m[0]=Math.abs(m[0]),m[1]=Math.abs(m[1]),m[2]=Math.abs(m[2]),m[0]<g&&m[1]<g&&m[2]<g){if(h){const i=Math.max(...m);o.subtract(m,t,h.vec3),m[0]=Math.abs(m[0]),m[1]=Math.abs(m[1]),m[2]=Math.abs(m[2]);if(Math.max(...m)<i)return h}return e}return h||(h=d.fromValues(n*r,s*r,a*r,c),this._origins.set(c,h)),h},n._drawOriginBox=function(t,i=s.fromValues(1,1,0,1)){const e=window.view,o=e._stage,n=i.toString();if(!this._objects.has(n)){this._material=new _.RibbonLineMaterial({width:2,color:i}),o.add(this._material);const t=new b.WebGLLayer({isPickable:!1}),e=new g.Object3D({castShadow:!1});o.add(e),t.add(e),o.add(t),this._objects.set(n,e)}const d=this._objects.get(n),u=[0,1,5,4,0,2,1,7,6,2,0,1,3,7,5,4,6,2,0],f=u.length,m=new Array(3*f),M=new Uint16Array(2*(f-1)),O=.5*this._gridSize;for(let r=0;r<f;r++)m[3*r+0]=t[0]+(1&u[r]?O:-O),m[3*r+1]=t[1]+(2&u[r]?O:-O),m[3*r+2]=t[2]+(4&u[r]?O:-O),r>0&&(M[2*r+0]=r-1,M[2*r+1]=r);a.projectBuffer(m,this._originSR,0,m,e.renderSpatialReference,0,f);const y=new h.Geometry([[l.VertexAttribute.POSITION,{size:3,data:m,exclusive:!0}]],[[l.VertexAttribute.POSITION,M]],c.PrimitiveType.Line);o.add(y),d.addGeometry(y,this._material,r.IDENTITY)},t}();const m=n.create();t.GridLocalOriginFactory=f,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
