/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import{lerp as t,distance as e}from"../../../core/libs/gl-matrix-2/math/vec2.js";import{create as r}from"../../../core/libs/gl-matrix-2/factories/vec2f64.js";import{absoluteHeightElevationInfo as i}from"../../../support/elevationInfoUtils.js";import{fromAnyMapPoint as o,asVec2 as s,markAsTarget as n,fromValues as p}from"../sketch/normalizedPoint.js";import{SnappingAlgorithm as a}from"./SnappingAlgorithm.js";import"../../../core/RandomLCG.js";import"../../../core/Logger.js";import"../../../core/accessorSupport/watch.js";import"../../../core/has.js";import"../../../core/accessorSupport/tracking/SimpleTrackingTarget.js";import"../../../core/sql/UnknownTimeZone.js";import"../../../time/constants.js";import"luxon";import"../../../intl/date.js";import"../../../rest/support/Query.js";import"../../input/InputManager.js";import"../keybindings.js";import{squaredScreenDistance as m}from"../../../core/screenUtils.js";import{RightAngleTriangleSnappingCandidate as c}from"./candidates/RightAngleTriangleSnappingCandidate.js";import{vectorToScreenPoint as l}from"../support/viewUtils.js";import{projectPointToCircle as g}from"../../support/geometry2dUtils.js";class d extends a{async snapNewVertex(t,e){const r=e.editGeometryOperations.data.parts.at(-1),i=[];if(!r)return i;const s=r.vertices.length;if("polygon"!==e.editGeometryOperations.data.type||s<2)return i;const{view:n}=this,p=r.vertices[0],a=r.vertices[s-1];if(a.leftSegment&&"line"!==a.leftSegment.type||a.rightSegment&&"line"!==a.rightSegment.type)return i;const m=o(p.pos,n,e),c=o(a.pos,n,e);return this._processCandidateProposal(m,c,t,e,i),i}async snapExistingVertex(t,e){const r=[],i=e.vertexHandle,{part:s,rightSegment:n,leftSegment:p}=i;if(s.segments.length<2)return r;if("polyline"===e.editGeometryOperations.data.type&&(0===i.index||i.index===s.vertices.length-1))return r;if("line"!==p?.type||n&&"line"!==n.type)return r;const a=n?.rightVertex??(s.autoClose?s.getFirstVertex():null);if(!a)return r;const{view:m}=this,c=o(p.leftVertex.pos,m,e),l=o(a.pos,m,e);return this._processCandidateProposal(c,l,t,e,r),r}_processCandidateProposal(r,o,a,d,f){if(!this.exceedsShortLineThreshold(r,o,d))return;const u=t(h,s(r),s(o),.5),j=.5*e(s(r),s(o)),y=g(h,s(a),u,j),x=n(p(y[0],y[1],a[2])),{spatialReference:v,pointer:S}=d,w=l(a,v,i,this.view);if(m(w,l(x,v,i,this.view))<this.squaredProximityThreshold(S)){if(this.isVertical(r,x,d)||this.isVertical(x,o,d))return;f.push(new c({targetPoint:x,point1:r,point2:o,isDraped:"on-the-ground"===d.elevationInfo?.mode}))}}}const h=r();export{d as RightAngleTriangleSnapper};
