/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
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 g}from"../support/viewUtils.js";import{projectPointToCircle as d}from"../../support/geometry2dUtils.js";class h extends a{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}snapExistingVertex(e,t){const i=[],r=t.vertexHandle,n=r.part;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"!==r.leftSegment?.type||"line"!==r.rightSegment?.type)return i;const{view:o}=this,p=s(r.leftSegment.leftVertex.pos,o,t),a=s(r.rightSegment.rightVertex.pos,o,t);return this._processCandidateProposal(p,a,e,t,i),i}_processCandidateProposal(i,s,a,h,c){if(!this.exceedsShortLineThreshold(i,s,h))return;const u=e(f,n(i),n(s),.5),v=.5*t(n(i),n(s)),x=d(f,n(a),u,v),y=o(p(x[0],x[1],a[2])),{spatialReference:S,pointer:j}=h,w=g(a,S,r,this.view);if(l(w,g(y,S,r,this.view))<this.squaredProximityThreshold(j)){if(this.isVertical(i,y,h)||this.isVertical(y,s,h))return;c.push(new m({targetPoint:y,point1:i,point2:s,isDraped:"on-the-ground"===h.elevationInfo?.mode}))}}}const f=i();export{h as RightAngleTriangleSnapper};
