/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/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 o,markAsTarget as n,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 d}from"../support/viewUtils.js";import{projectPointToCircle as g}from"../../support/geometry2dUtils.js";class c extends a{snapNewVertex(e,t){const i=t.editGeometryOperations.data.parts.at(-1),r=[];if(!i)return r;const o=i.vertices.length;if("polygon"!==t.editGeometryOperations.data.type||o<2)return r;const{view:n}=this,p=i.vertices[0],a=i.vertices[o-1];if(a.leftSegment&&"line"!==a.leftSegment.type||a.rightSegment&&"line"!==a.rightSegment.type)return r;const l=s(p.pos,n,t),m=s(a.pos,n,t);return this._processCandidateProposal(l,m,e,t,r),r}snapExistingVertex(e,t){const i=[],r=t.vertexHandle,{part:o,rightSegment:n,leftSegment:p}=r;if(o.segments.length<2)return i;if("polyline"===t.editGeometryOperations.data.type&&(0===r.index||r.index===o.vertices.length-1))return i;if("line"!==p?.type||n&&"line"!==n.type)return i;const a=n?.rightVertex??(o.autoClose?o.getFirstVertex():null);if(!a)return i;const{view:l}=this,m=s(p.leftVertex.pos,l,t),d=s(a.pos,l,t);return this._processCandidateProposal(m,d,e,t,i),i}_processCandidateProposal(i,s,a,c,h){if(!this.exceedsShortLineThreshold(i,s,c))return;const u=e(f,o(i),o(s),.5),x=.5*t(o(i),o(s)),v=g(f,o(a),u,x),y=n(p(v[0],v[1],a[2])),{spatialReference:j,pointer:S}=c,w=d(a,j,r,this.view);if(l(w,d(y,j,r,this.view))<this.squaredProximityThreshold(S)){if(this.isVertical(i,y,c)||this.isVertical(y,s,c))return;h.push(new m({targetPoint:y,point1:i,point2:s,isDraped:"on-the-ground"===c.elevationInfo?.mode}))}}}const f=i();export{c as RightAngleTriangleSnapper};
