/*
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","./Settings","./SnappingAlgorithm","./snappingUtils","./candidates/ParallelLineSnappingCandidate","../support/viewUtils","../../support/geometry2dUtils"],(function(e,t,n,i,r,o,s,a,l,c,p){"use strict";let h=function(e){function s(){var t;return(t=e.apply(this,arguments)||this)._tmpProjection=r.create(),t}t._inheritsLoose(s,e);var h=s.prototype;return h.snapNewVertex=function(e,t){const n=t.editGeometryOperations.data.components[0],i=n.edges.length,r=n.vertices.length,o=[];if(i<2)return o;const s=c.anyMapPointToScreenPoint(e,t.coordinateHelper,t.elevationInfo,this.view),a=n.vertices[r-1],l=n.vertices[0],p=n.edges[i-1];let h=p;do{this.edgeExceedsShortLineThreshold(h,t)&&(this._checkEdgeForParalleLines(h,a.pos,e,s,t,o),this._checkEdgeForParalleLines(h,l.pos,e,s,t,o)),h=h.leftVertex.leftEdge}while(h&&h!==p);return o},h.snapExistingVertex=function(e,t){const i=[],r=n.unwrap(t.vertexHandle),o=r.component;if(o.edges.length<3)return i;const s=c.anyMapPointToScreenPoint(e,t.coordinateHelper,t.elevationInfo,this.view),a=r.leftEdge,l=r.rightEdge,p=o.vertices[0],h=o.vertices.length,d=o.vertices[h-1],g=o.edges[0];let u=g;do{u!==a&&u!==l&&this.edgeExceedsShortLineThreshold(u,t)&&(a&&this._checkEdgeForParalleLines(u,a.leftVertex.pos,e,s,t,i),l&&this._checkEdgeForParalleLines(u,l.rightVertex.pos,e,s,t,i),r===p?this._checkEdgeForParalleLines(u,d.pos,e,s,t,i):r===d&&this._checkEdgeForParalleLines(u,p.pos,e,s,t,i)),u=u.rightVertex.rightEdge}while(u&&u!==g);return i},h._checkEdgeForParalleLines=function(e,t,n,r,s,h){const d=e.leftVertex.pos,g=e.rightVertex.pos;if(p.projectPointToLine(this._tmpProjection,t,d,g),i.squaredDistance(this._tmpProjection,t)<o.defaults.parallelLineThreshold)return;p.projectPointToLine(this._tmpProjection,n,d,g,t);const{coordinateHelper:u,elevationInfo:f,pointer:P}=s,v=u.fromXYZ(this._tmpProjection,u.getZ(n,0));if(a.squareDistance(r,c.anyMapPointToScreenPoint(v,u,f,this.view))<this.squaredProximityTreshold(P)){if(this._parallelToPreviousCandidate(e,h))return;h.push(new l.ParallelLineSnappingCandidate({coordinateHelper:u,referenceLine:e,lineStart:t,targetPoint:v,elevationInfo:f}))}},h._parallelToPreviousCandidate=function(e,t){const n=e.leftVertex.pos,r=e.rightVertex.pos;for(const s of t)if(p.projectPointToLine(this._tmpProjection,r,s.constraint.start,s.constraint.end,n),i.squaredDistance(this._tmpProjection,r)<o.defaults.parallelLineThreshold)return s.addReferenceLine(e),!0;return!1},s}(s.SnappingAlgorithm);e.ParallelLineSnapper=h,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
