/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{clamp as t}from"../../../../core/mathUtils.js";import{d as e,j as r}from"../../../../chunks/vec32.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{wrap as o}from"../../../../geometry/support/ray.js";import{defaultConstraintOptions as i,interactionDirectionTowardsConstraintMinimization as s,hasConstraintType as a,adjustRangeForInteraction as c}from"./common.js";import{closestPointOnRay as m}from"../../support/intersectionUtils.js";function u(t,r,n=i){const a=l(t,r,n);if(0===a)return!1;const c=t.renderCoordsHelper,u=c.getAltitude(r.eye)+a,f=s(r,n.interactionDirection,p(t,r,Math.sign(a),g),j),d=e(A,r.viewForward),y=c.intersectInfiniteManifold(o(r.eye,f),u,C);return r.eye=null!=y?y:c.setAltitude(C,u,r.eye),r.center=m(C,r.eye,d,r.center),!0}function l(e,r,n=i){if(!f(e,n)||!e.state.constraints.altitude)return 0;const o=y(e.state.constraints.altitude,x);d(e,n,o);const s=e.renderCoordsHelper.getAltitude(r.eye),a=t(s,o.min,o.max)-s;return Math.abs(a)<=1e-6?0:a}function f(t,e){const r=t.state.constraints.altitude;return!(!t.state.isGlobal||!r)&&(2!==e.interactionType||!a(e.selection,1))}function d(t,e,r){const n=e.interactionType;if(0===n)return;const{min:o,max:i}=r,{interactionStartCamera:s,interactionFactor:a}=e;if(!s)return;const m=2===n||1===n,u=l(t,s),f=0===u?0:t.renderCoordsHelper.getAltitude(s.eye);r.min=o,r.max=i;c(u,f,m,a,.05*f,r)}function p(t,e,n,o){return t.renderCoordsHelper.worldUpAtPosition(e.eye,o),r(o,o,n),o}function y(t,e){return e.min=t.min,e.max=t.max,e}const x={min:0,max:0},j=n(),g=n(),A=n(),C=n();export{u as applyAltitudeConstraint,l as getAltitudeConstraintError};
