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