/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{valueInUnit as e}from"../../../../../core/quantity.js";import{createScreenPointArray as r,createRenderScreenPointArray3 as o}from"../../../../../core/screenUtils.js";import{getMetersPerUnitForSR as t}from"../../../../../core/units.js";import{fromValues as n}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{cross as i,direction as s,squaredLength as c,subtract as l,scaleAndAdd as a}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as m}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{geodesicCompatibleSpatialReference as p,inverseGeodeticSolver as f,InverseGeodeticSolverResult as u,directGeodeticSolver as d}from"../../../../../geometry/geodesicUtils.js";import{projectPoint as j}from"../../../../../geometry/projectionUtils.js";import{projectVectorToVector as g}from"../../../../../geometry/projection/projectVectorToVector.js";import{getNormal as y,fromPositionAndNormal as h,create as x}from"../../../../../geometry/support/plane.js";import{makeDehydratedPoint as R}from"../../../../../layers/graphics/dehydratedPoint.js";import{getZForElevationMode as v}from"../../../../../support/elevationInfoUtils.js";import{OffsetEdgeVertex as C}from"../../../../interactive/editGeometry/operations/OffsetEdgeVertex.js";function H(e,r,o){const t="on-the-ground"===o.mode?1:0;return new C(e,t,r,0)}function w(e,r,o){const t=m();if(!e.renderCoordsHelper.toRenderCoords(r,t))return null;const n=T(e,r,y(o.plane)),s=T(e,r,o.edgeDirection);if(null==n||null==s)return null;const c=i(m(),n,s);return h(t,c,x())}function T(e,r,o){const t=R(r.x+o[0],r.y+o[1],r.z+o[2],r.spatialReference),n=m(),i=m();return e.renderCoordsHelper.toRenderCoords(r,n)&&e.renderCoordsHelper.toRenderCoords(t,i)?s(i,n,i):null}function U(e,r,o){const t=y(e),c=s(m(),r,o),l=i(m(),c,t),a=i(m(),c,l);return n(c[0],c[1],c[2],0,l[0],l[1],l[2],0,a[0],a[1],a[2],0,0,0,0,1)}function b(e,r,t){const n=t.projectToRenderScreen(e,o()),i=t.projectToRenderScreen(r,o());return null!=n&&null!=i?c(l(n,n,i)):0}function q(e,o,t,n){const{elevationInfo:i,operations:s}=t;if(!s||!e)return null;const c=n.manipulator.elevationAlignedLocation,l=v(c,o,i),a=o.sceneIntersectionHelper.intersectElevationFromScreen(r(e.x,e.y),i,l);return a&&j(a,a,s.data.spatialReference)?a:null}function A(r,o,n,{data:{coordinateHelper:i,spatialReference:s}}){const c=e(r,"meters"),l=t(s),j=Math.sign(c*n.selectedArrow),h=p(s),x=y(n.plane),R=i.pointToXYZ(o),v=m();a(v,R,x,j*(I/l));const C=c*n.selectedArrow/l;if(!h||!g(R,s,R,h)||!g(v,s,v,h))return C;const H=new u;if(f(H,R,v,h),d(v,R,H.azimuth,c,h),!g(v,h,v,s))return C;const w=v[0]-o.x,T=v[1]-o.y,U=Math.sqrt(w*w+T*T)*j,[b,q]=x,A=Math.sqrt(b*b+q*q);return 0===A?0:U/A}const I=10;export{w as createEdgeOffsetIntersectionPlane,H as createEdgeOffsetOperation,U as edgeOffsetRotationMatrix,A as getDistanceInGeometrySR,q as getMapPointAtEdgeOffsetManipulatorElevation,b as screenEdgeLengthSquared};
