/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../core/maybe","../../../../core/quantityUtils","../../../../chunks/vec2","../../../../chunks/vec3","../../../../chunks/vec3f64","../../../../chunks/boundedPlane","../../../../geometry/support/vectorStacks","../operations/MoveVertex","../operations/RotateVertex","../operations/ScaleVertex","../operations/UpdateVertices","../../../support/automaticLengthMeasurementUtils"],(function(s,t,e,o,n,i,a,r,c,d,u,b,l){"use strict";function g(s,t){return v(s,t,!1)}function p(s,t){return v(s,t,!0)}function v(s,t,e){if(s instanceof b.UpdateVertices){if(s.operation instanceof c.MoveVertex)return f(s.operation,t,e),!0;if(s.operation instanceof d.RotateVertex)return m(s.operation,t,e),!0;if(s.operation instanceof u.ScaleVertex)return I(s.operation,t,e),!0}return!1}function f(s,t,e=!1){const o=e?-1:1,a=i.fromValues(o*s.dx,o*s.dy,o*s.dz);n.add(t.origin,t.origin,a)}function m(s,t,e=!1){const o=e?-s.angle:s.angle;n.rotateZ(t.basis1,t.basis1,i.ZEROS,o),n.rotateZ(t.basis2,t.basis2,i.ZEROS,o)}function I(s,t,e=!1){const i=e?1/s.factor1:s.factor1,a=e?1/s.factor2:s.factor2;n.scale(t.basis1,t.basis1,i),n.scale(t.basis2,t.basis2,a),o.projectAndScale(t.origin,t.origin,s.origin,s.axis1,i),o.projectAndScale(t.origin,t.origin,s.origin,s.axis2,a)}function N(s,t,e,n){n||(n=a.create());const i=o.set(r.sv2d.get(),s[1],-s[0]),c=o.set(r.sv2d.get(),Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY),d=o.set(r.sv2d.get(),Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY),u=r.sv2d.get();t.components.forEach((t=>t.vertices.forEach((t=>{const e=t.pos;o.set(u,o.dot(s,e),o.dot(i,e)),o.min(c,c,u),o.max(d,d,u)}))));const b=1e-6,l=o.set(r.sv2d.get(),d[0]-c[0]<b?e/2:0,d[1]-c[1]<b?e/2:0);return o.subtract(c,c,l),o.add(d,d,l),o.scale(n.basis1,s,(d[0]-c[0])/2),o.scale(n.basis2,i,(d[1]-c[1])/2),o.set(n.origin,c[0]*s[0]+c[1]*i[0],c[0]*s[1]+c[1]*i[1]),o.add(n.origin,n.origin,n.basis1),o.add(n.origin,n.origin,n.basis2),n}function E(s,t,e,o=0,i){i||(i=a.create()),t.toRenderCoords(s.origin,e,i.origin);const c=r.sv3d.get();n.add(c,s.origin,s.basis1),n.add(c,c,s.basis2),t.toRenderCoords(c,e,c);const d=r.sv3d.get();n.add(d,s.origin,s.basis1),n.subtract(d,d,s.basis2),t.toRenderCoords(d,e,d);const u=r.sv3d.get();n.subtract(u,s.origin,s.basis1),n.subtract(u,u,s.basis2),t.toRenderCoords(u,e,u);const b=r.sv3d.get();n.subtract(b,s.origin,s.basis1),n.add(b,b,s.basis2),t.toRenderCoords(b,e,b);const l=n.lerp(r.sv3d.get(),c,d,.5);n.subtract(l,l,i.origin);const g=n.lerp(r.sv3d.get(),u,b,.5);n.subtract(g,i.origin,g),n.lerp(i.basis1,l,g,.5);const p=n.lerp(r.sv3d.get(),b,c,.5);n.subtract(p,p,i.origin);const v=n.lerp(r.sv3d.get(),d,u,.5);n.subtract(v,i.origin,v),n.lerp(i.basis2,p,v,.5);const f=n.cross(r.sv3d.get(),i.basis1,i.basis2),m=n.cross(f,f,i.basis1);return n.normalize(m,m),n.scale(i.basis2,m,n.dot(i.basis2,m)),n.scale(i.basis1,i.basis1,1+o/n.length(i.basis1)),n.scale(i.basis2,i.basis2,1+o/n.length(i.basis2)),a.updateUnboundedPlane(i),i}function x(s,o,i,a){const c=r.sv3d.get();n.subtract(c,n.subtract(c,s.origin,s.basis1),s.basis2);const d=r.sv3d.get();n.scaleAndAdd(d,c,s.basis1,2);const u=r.sv3d.get();n.scaleAndAdd(u,d,s.basis2,2);const b=r.sv3d.get();n.scaleAndAdd(b,c,s.basis2,2),c[2]=d[2]=u[2]=b[2]=o;const g=a?"on-the-ground":"absolute-height",p=e.max(l.autoHorizontalDistanceByElevationMode(c,d,i,g),l.autoHorizontalDistanceByElevationMode(b,u,i,g)),v=e.max(l.autoHorizontalDistanceByElevationMode(d,u,i,g),l.autoHorizontalDistanceByElevationMode(c,b,i,g));return t.isNone(v)||t.isNone(p)?null:[p,v]}s.apply=g,s.calculateOrientedBounds=N,s.mapPlaneAutoHorizontalSizeByElevationMode=x,s.mapPlaneToRenderPlane=E,s.unapply=p,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
