UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 2.61 kB
import{unwrap as e}from"../../../core/maybe.js";import{k as t}from"../../../chunks/vec2.js";import{a as r}from"../../../chunks/vec2f64.js";import{f as i}from"../../../chunks/vec3f64.js";import{absoluteHeightElevationInfo as s}from"../../../support/elevationInfoUtils.js";import{defaults as o}from"./Settings.js";import{SnappingAlgorithm as n}from"./SnappingAlgorithm.js";import{anyMapPointToSnappingPoint as l,asSnappingPoint as a}from"./SnappingPoint.js";import{editEdgeToSnappingEdge as c,squaredScreenDistance as h}from"./snappingUtils.js";import{ParallelLineSnappingCandidate as p}from"./candidates/ParallelLineSnappingCandidate.js";import{vectorToScreenPoint as d}from"../support/viewUtils.js";import{projectPointToLine as f}from"../../support/geometry2dUtils.js";class g extends n{snapNewVertex(e,t){const r=t.editGeometryOperations.data.components[0],i=r.edges.length,o=r.vertices.length,n=[];if(i<2)return n;const{view:a}=this,h=d(e,t.spatialReference,s,a),p=l(r.vertices[o-1].pos,a,t),f=l(r.vertices[0].pos,a,t),g=r.edges[i-1];let m=g;do{if(this.edgeExceedsShortLineThreshold(m,t)){const r=c(m,a,t);this._checkEdgeForParallelLines(r,p,e,h,t,n),this._checkEdgeForParallelLines(r,f,e,h,t,n)}m=m.leftVertex.leftEdge}while(m&&m!==g);return n}snapExistingVertex(t,r){const i=[],o=e(r.vertexHandle),n=o.component;if(n.edges.length<3)return i;const{view:a}=this,h=d(t,r.spatialReference,s,a),p=o.leftEdge,f=o.rightEdge,g=n.vertices[0],m=l(g.pos,a,r),u=n.vertices.length,v=n.vertices[u-1],E=l(v.pos,a,r),L=n.edges[0];let x=L;do{if(x!==p&&x!==f&&this.edgeExceedsShortLineThreshold(x,r)){const e=c(x,a,r);p&&this._checkEdgeForParallelLines(e,l(p.leftVertex.pos,a,r),t,h,r,i),f&&this._checkEdgeForParallelLines(e,l(f.rightVertex.pos,a,r),t,h,r,i),o===g?this._checkEdgeForParallelLines(e,E,t,h,r,i):o===v&&this._checkEdgeForParallelLines(e,m,t,h,r,i)}x=x.rightVertex.rightEdge}while(x&&x!==L);return i}_checkEdgeForParallelLines(e,r,n,l,c,g){const u=e.left,v=e.right;if(f(m,r,u,v),t(m,r)<o.parallelLineThreshold)return;f(m,n,u,v,r);const{spatialReference:E,pointer:L}=c,x=a(i(m[0],m[1],n[2]));if(h(l,d(x,E,s,this.view))<this.squaredProximityThreshold(L)){if(this.isVertical(x,r)||this.isVertical(u,v))return;if(this._parallelToPreviousCandidate(e,g))return;g.push(new p({referenceLine:e,lineStart:r,targetPoint:x,isDraped:"on-the-ground"===c.elevationInfo?.mode}))}}_parallelToPreviousCandidate(e,r){const i=e.left,s=e.right;for(const n of r)if(f(m,s,n.constraint.start,n.constraint.end,i),t(m,s)<o.parallelLineThreshold)return n.addReferenceLine(e),!0;return!1}}const m=r();export{g as ParallelLineSnapper};