/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{set as o,dot as i,min as r,max as t,subtract as s,add as e,scale as n,projectAndScale as a}from"../../../../core/libs/gl-matrix-2/math/vec2.js";import{set as c,add as f,rotateZ as m,scale as g}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{fromValues as p,ZEROS as u}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{c as b,u as I}from"../../../../chunks/boundedPlane.js";import{sv2d as l}from"../../../../geometry/support/vectorStacks.js";import{MoveVertex as N}from"../operations/MoveVertex.js";import{RotateVertex as d}from"../operations/RotateVertex.js";import{ScaleVertex as x}from"../operations/ScaleVertex.js";import{UpdateVertices as j}from"../operations/UpdateVertices.js";function V(o,i){return E(o,i,!1)}function T(o,i){return E(o,i,!0)}function E(o,i,r){if(o instanceof j){if(o.operation instanceof N)return h(o.operation,i,r),!0;if(o.operation instanceof d)return v(o.operation,i,r),!0;if(o.operation instanceof x)return F(o.operation,i,r),!0}return!1}function h(o,i,r=!1){const t=r?-1:1,s=p(t*o.dx,t*o.dy,t*o.dz);f(i.origin,i.origin,s),I(i)}function v(o,i,r=!1){const t=r?-o.angle:o.angle;m(i.basis1,i.basis1,u,t),m(i.basis2,i.basis2,u,t),I(i)}function F(o,i,r=!1){const t=r?1/o.factor1:o.factor1,s=r?1/o.factor2:o.factor2;g(i.basis1,i.basis1,t),g(i.basis2,i.basis2,s),a(i.origin,i.origin,o.origin,o.axis1,t),a(i.origin,i.origin,o.origin,o.axis2,s),I(i)}function S(a,m,g,p,u=!1){p||(p=b());const N=o(l.get(),a[1],-a[0]),d=o(l.get(),Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),x=o(l.get(),Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),j=l.get(),V=m.allVerticesUnordered;V.forEach(({pos:s})=>{o(j,i(a,s),i(N,s)),r(d,d,j),t(x,x,j)});const T=1e-6,E=o(l.get(),x[0]-d[0]<T?g/2:0,x[1]-d[1]<T?g/2:0);s(d,d,E),e(x,x,E);const h=u?V.reduce((o,i)=>o+(i.pos[2]??0),0)/V.length:0;return n(p.basis1,a,(x[0]-d[0])/2),n(p.basis2,N,(x[1]-d[1])/2),c(p.origin,d[0]*a[0]+d[1]*N[0],d[0]*a[1]+d[1]*N[1],h),f(p.origin,p.origin,p.basis1),f(p.origin,p.origin,p.basis2),I(p),p}export{V as apply,T as applyInverse,S as calculateOrientedBounds};
