/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../core/maybe","../../../chunks/vec2","../../../chunks/vec2f64","./SnappingAlgorithm","./SnappingConstraint","./snappingUtils","./candidates/RightAngleSnappingCandidate","../support/viewUtils"],(function(e,t,r,i,n,o,s,a,p,g){"use strict";let h=function(e){function o(){var t;return(t=e.apply(this,arguments)||this)._tmp=n.create(),t}t._inheritsLoose(o,e);var h=o.prototype;return h.snapNewVertex=function(e,t){const r=t.editGeometryOperations.data.components[0],i=r.vertices.length,n=[];if(i<2)return n;const o=g.anyMapPointToScreenPoint(e,t.coordinateHelper,t.elevationInfo,this.view),s=r.vertices[i-1];this._checkForSnappingCandidate(n,s.leftEdge,s.pos,e,s.leftEdge.leftVertex.pos,s.pos,t,e,o);const a=r.vertices[0];return this._checkForSnappingCandidate(n,a.rightEdge,a.pos,e,a.rightEdge.rightVertex.pos,a.pos,t,e,o),n},h.snapExistingVertex=function(e,t){const i=[],n=r.unwrap(t.vertexHandle),o=n.component,s=o.vertices.length;if(s<3)return i;const a=g.anyMapPointToScreenPoint(e,t.coordinateHelper,t.elevationInfo,this.view),p=n.leftEdge,h=n.rightEdge,d=o.vertices[0],c=o.vertices[s-1];if(!p)return this._checkForSnappingCandidate(i,d.rightEdge.rightVertex.rightEdge,d.rightEdge.rightVertex.pos,e,d.rightEdge.rightVertex.rightEdge.rightVertex.pos,d.rightEdge.rightVertex.pos,t,e,a),i;if(!h)return this._checkForSnappingCandidate(i,c.leftEdge.leftVertex.leftEdge,c.leftEdge.leftVertex.pos,e,c.leftEdge.leftVertex.leftEdge.leftVertex.pos,c.leftEdge.leftVertex.pos,t,e,a),i;if(p&&p.leftVertex.leftEdge){const r=p.leftVertex.leftEdge;this._checkForSnappingCandidate(i,r,p.leftVertex.pos,e,r.leftVertex.pos,p.leftVertex.pos,t,e,a)}if(h&&h.rightVertex.rightEdge){const r=h.rightVertex.rightEdge;this._checkForSnappingCandidate(i,r,h.rightVertex.pos,e,r.rightVertex.pos,h.rightVertex.pos,t,e,a)}return i},h._checkForSnappingCandidate=function(e,t,r,o,h,d,c,l,f){if(!this.edgeExceedsShortLineThreshold(t,c))return;i.subtract(this._tmp,t.rightVertex.pos,t.leftVertex.pos);const u=n.fromValues(this._tmp[1],-this._tmp[0]),x=i.dot(u,i.subtract(this._tmp,o,r))/i.squaredLength(u),{coordinateHelper:V,elevationInfo:E,pointer:v}=c,S=V.fromXYZ(i.scaleAndAdd(n.create(),d,u,x),V.getZ(l,0));a.squareDistance(f,g.anyMapPointToScreenPoint(S,V,E,this.view))<this.squaredProximityTreshold(v)&&e.push(new p.RightAngleSnappingCandidate({coordinateHelper:V,targetPoint:S,constraint:new s.RayConstraint(V,d,i.scaleAndAdd(V.createVector(),d,u,Math.sign(x))),previousVertex:h,otherVertex:d,otherVertexType:p.OtherVertexType.CENTER,elevationInfo:E}))},o}(o.SnappingAlgorithm);e.RightAngleSnapper=h,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
