/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../chunks/vec3f64","../../../../chunks/sphere","./Octree"],(function(e,n,t,r){"use strict";function s(e){const n={numNodes:0,numObjects:0,numTerminals:0,numResidents:0,numOutsiders:0,numInnerNodes:0,numTerminalNodes:0,maximumDepth:0,maxNumTerminals:0,maxNumResidents:0,maxNumObjects:0};return e.forEachNode(((t,r,s)=>{null===t.residents?n.numInnerNodes++:n.numTerminalNodes++,n.numTerminals+=t.terminals.length,n.maxNumTerminals=Math.max(t.terminals.length,n.maxNumTerminals);let i=t.terminals.length;null!==t.residents&&(n.numResidents+=t.residents.length,n.maxNumResidents=Math.max(t.residents.length,n.maxNumResidents),i+=t.residents.length),n.maxNumObjects=Math.max(i,n.maxNumObjects);const m=Math.round(Math.log(2*e.halfSize/s)*Math.LOG2E);return n.maximumDepth=Math.max(n.maximumDepth,m),!0})),n.numObjects=n.numOutsiders+n.numTerminals+n.numResidents,n.numNodes=n.numInnerNodes+n.numTerminalNodes,n}function i(e,s=!1){const m=e instanceof r?e.root:e,a={};return e instanceof r&&s&&(a.center=n.clone(t.getCenter(e.bounds)),a.size=2*e.halfSize),m.terminals.length>0&&(a.terminals=m.terminals.map((e=>e.id))),null!==m.residents&&m.residents.length>0&&(a.residents=m.residents.map((e=>e.id))),null===m.residents&&m.children.forEach(((e,n)=>{e&&(a["child"+n]=i(e))})),a}function m(e,r){return e.forEachNode(((s,i,m)=>{const o=l(t.getCenter(i),-m,n.create()),u=l(t.getCenter(i),m,n.create());if(s.terminals.forAll((e=>a(r(e),o,u,!0))),null!==s.residents){if(s.residents.length>e.maximumObjectsPerNode)throw new Error("[Octree Validation] Number of objects "+s.residents.length+" exceeds maximum allowed ("+e.maximumObjectsPerNode+")");s.residents.forAll((e=>a(r(e),o,u,!1)))}let d=!1;if(s.children.forEach((e=>{if(e&&(d=!0,null!==s.residents))throw new Error("[Octree Validation] Node has residents and children")})),!d&&(null===s.residents||0===s.residents.length)&&0===s.terminals.length)throw new Error("[Octree Validation] dangling empty node");return!0})),!0}function a(e,n,t,r){for(let i=0;i<3;i++)if(e[i]<n[i]||e[i]>t[i])throw new Error("[Octree Validation] Object is not within node bounds");const s=.25*(t[0]-n[0]);if(r&&e[3]<s)throw new Error("[Octree Validation] Object is too small to be a terminal");if(!r&&e[3]>s)throw new Error("[Octree Validation] Object is too large to be a resident")}function l(e,n,t){return t[0]=e[0]+n,t[1]=e[1]+n,t[2]=e[2]+n,t}e.assert=m,e.debugDump=i,e.stats=s,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
