/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import"../../../../core/has.js";import{generateUID as t}from"../../../../core/uid.js";import{e as i}from"../../../../chunks/vec32.js";import{create as r}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{fromValues as o}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{projectBuffer as s}from"../../../../geometry/projection/projectBuffer.js";import{Attribute as e}from"./Attribute.js";import{Geometry as n}from"./Geometry.js";import{fromValues as a}from"./LocalOriginFactory.js";import{Object3D as h}from"./Object3D.js";import{gridLocalOriginFactory as c}from"./testUtils.js";import{WebGLLayer as m}from"./WebGLLayer.js";import{RibbonLineMaterial as g}from"../materials/RibbonLineMaterial.js";class f{constructor(i){this._originSR=i,this._rootOriginId="root/"+t(),this._origins=new Map,this._objects=new Map,this._gridSize=5e5}getOrigin(t){const r=this._origins.get(this._rootOriginId);if(null==r){const i=c.rootOrigin;if(null!=i)return this._origins.set(this._rootOriginId,a(i[0],i[1],i[2],this._rootOriginId)),this.getOrigin(t);const r=a(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 o=this._gridSize,s=Math.round(t[0]/o),e=Math.round(t[1]/o),n=Math.round(t[2]/o),h=`${s}/${e}/${n}`;let m=this._origins.get(h);const g=.5*o;if(i(d,t,r.vec3),d[0]=Math.abs(d[0]),d[1]=Math.abs(d[1]),d[2]=Math.abs(d[2]),d[0]<g&&d[1]<g&&d[2]<g){if(m){const r=Math.max(...d);i(d,t,m.vec3),d[0]=Math.abs(d[0]),d[1]=Math.abs(d[1]),d[2]=Math.abs(d[2]);if(Math.max(...d)<r)return m}return r}return m||(m=a(s*o,e*o,n*o,h),this._origins.set(h,m)),m}_drawOriginBox(t,i=o(1,1,0,1)){const r=window.view,a=r.stage,c=i.toString();if(!this._objects.has(c)){this._material=new g({width:2,color:i},!1);const t=new m(a,{pickable:!1}),r=new h({castShadow:!1});t.add(r),this._objects.set(c,r)}const f=this._objects.get(c),d=[0,1,5,4,0,2,1,7,6,2,0,1,3,7,5,4,6,2,0],l=d.length,_=new Array(3*l),p=new Array,j=.5*this._gridSize;for(let o=0;o<l;o++)_[3*o]=t[0]+(1&d[o]?j:-j),_[3*o+1]=t[1]+(2&d[o]?j:-j),_[3*o+2]=t[2]+(4&d[o]?j:-j),o>0&&p.push(o-1,o);s(_,this._originSR,0,_,r.renderSpatialReference,0,l);const b=new n(this._material,[["position",new e(_,p,3,!0)]],null,2);f.addGeometry(b)}get test(){}}const d=r();export{f as GridLocalOriginFactory};
