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