/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{getMetersPerUnitForSR as e}from"../../../core/units.js";import{distance as t}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{absoluteHeightElevationInfo as s}from"../../../support/elevationInfoUtils.js";import{fromAnyMapPoint as r,asVec2 as i}from"../sketch/normalizedPoint.js";import{defaults as o}from"./Settings.js";import{squaredScreenDistance as h}from"./snappingUtils.js";import{vectorToScreenPoint as n}from"../support/viewUtils.js";class l{constructor(e,t){this.view=e,this.options=t,this.squaredShortLineThreshold=o.shortLineThreshold*o.shortLineThreshold}async snap(e,t){return null!=t.vertexHandle?"vertex"!==t.vertexHandle.type?[]:this.snapExistingVertex(e,t):this.snapNewVertex(e,t)}edgeExceedsShortLineThreshold(e,t){return this.exceedsShortLineThreshold(r(e.leftVertex.pos,this.view,t),r(e.rightVertex.pos,this.view,t),t)}exceedsShortLineThreshold(e,t,{spatialReference:r}){return 0===this.squaredShortLineThreshold||h(n(t,r,s,this.view),n(e,r,s,this.view))>this.squaredShortLineThreshold}isVertical(s,r,{spatialReference:h}){const n=e(h);return t(i(s),i(r))*n<o.verticalLineThresholdMeters}squaredProximityThreshold(e){return"touch"===e?this._squaredTouchProximityThreshold:this._squaredMouseProximityThreshold}get _squaredMouseProximityThreshold(){return this.options.distance*this.options.distance}get _squaredTouchProximityThreshold(){const{distance:e,touchSensitivityMultiplier:t}=this.options,s=e*t;return s*s}}export{l as SnappingAlgorithm};
