/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import{dot as e}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as t}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";function n(e,t,n){for(let l=0;l<t.length;l++)o[l]=!1,g[l]=null;for(let o=0;o<e.length;o++)l[o]=!1,r[o]=null;for(let l=0;l<t.length;l++){const g=h(t[l],e,n);g>=0&&(o[l]=!0,null!=r[g]?r[g].push(t[l]):r[g]=[t[l]])}for(let r=0;r<e.length;r++){const o=h(e[r],t,n);o>=0&&(l[r]=!0,null!=g[o]?g[o].push(e[r]):g[o]=[e[r]])}const u=[];for(let o=0;o<e.length;o++)null!=r[o]||l[o]||u.push({load:[],remove:[e[o]]});for(let l=0;l<t.length;l++)null!=g[l]||o[l]||u.push({load:[t[l]],remove:[]});for(let l=0;l<t.length;l++)null!=g[l]&&(g[l].length>1||g[l][0]!==t[l])&&u.push({load:[t[l]],remove:g[l]});for(let l=0;l<e.length;l++)null!=r[l]&&(r[l].length>1||r[l][0]!==e[l])&&u.push({load:r[l],remove:[e[l]]});return u}const l=[!1],r=[null],o=[!1],g=[null];function h(e,t,n){let l=e;for(;l>0;){const e=t.indexOf(l);if(e>=0)return e;l=n.getParentId(l)}return t.indexOf(l)}function u(t,n,l){return t.sort((t,r)=>{if(0===t.load.length&&0===r.load.length)return 0;if(0===t.load.length)return-1;if(0===r.load.length)return 1;if(0===t.remove.length&&0===r.remove.length){const o=l.getRenderObb(t.load[0]).getCenter(a),g=l.getRenderObb(r.load[0]).getCenter(s);return e(o,n)-e(g,n)}if(0===t.remove.length)return-1;if(0===r.remove.length)return 1;if(1===t.load.length&&1===r.load.length){const o=l.getRenderObb(t.load[0]).getCenter(a),g=l.getRenderObb(r.load[0]).getCenter(s);return e(o,n)-e(g,n)}if(1===t.load.length)return-1;if(1===r.load.length)return 1;{const o=l.getRenderObb(t.remove[0]).getCenter(a),g=l.getRenderObb(r.remove[0]).getCenter(s);return e(o,n)-e(g,n)}})}function f(e,t,n){for(let l=0;l<e.length;++l){const r=e[l];r.load.length>t&&1===r.remove.length&&d(e,r,n)}}function d(e,t,n){const l=[t.remove[0]],r=[];for(;1===l.length;){const e=l.pop();r.length=0;for(let o=0;o<t.load.length;o++){let g=t.load[o],h=n.getParentId(g);for(;h!==e;)g=h,h=n.getParentId(g);let u=l.indexOf(g);u<0&&(u=l.length,l.push(g),r.push([])),r[u].push(t.load[o])}}t.load=l;for(let o=0;o<l.length;o++)r[o].length>1?e.push({remove:[l[o]],load:r[o]}):l[o]=r[o][0]}const a=t(),s=t();export{n as nodeDiff,u as sortFrontToBack,f as splitWorkEntries,d as splitWorkEntry};
