@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 5.83 kB
JavaScript
import{deg2rad as t}from"../../../../core/mathUtils.js";import{isSome as i,isNone as e}from"../../../../core/maybe.js";import{a as s,f as n,h as r}from"../../../../chunks/vec2.js";import{a as h}from"../../../../chunks/vec2f64.js";import{r as o,e as a,o as _,f as c,n as l,a as p,g as d,F as g,c as f}from"../../../../chunks/vec3.js";import{c as m,f as u}from"../../../../chunks/vec3f64.js";import{create as D,fromPositionAndNormal as E,signedDistance as x,copy as b,isPointInside as I,normal as V,intersectLine as M}from"../../../../geometry/support/plane.js";import{angle as X,projectPointSignedLength as Y}from"../../../../geometry/support/vector.js";import{intersectLineAndRay as N,LineType as y}from"../../../support/geometry2dUtils.js";class P{get plane(){return this._plane}get requiresSplitEdgeLeft(){return!this._left.isOriginalDirection}get requiresSplitEdgeRight(){return!this._right.isOriginalDirection}get edgeDirection(){return this._edgeDirection}constructor(t,i,e,s=0,n=j.IMMEDIATE){this._helper=t,this._planeType=i,this._edge=e,this.distance=s,this._plane=D(),this._offsetPlane=D(),this._minDistance=-1/0,this._maxDistance=1/0,this._selectedArrow=1,n===j.IMMEDIATE&&this._initialize()}_initialize(){this._initializeNeighbors(),this._initializePlane(),this._initializeDistanceConstraints()}_initializeNeighbors(){const t=this._toXYZ(this._edge.leftVertex.pos),i=this._toXYZ(this._edge.leftVertex.leftEdge?.leftVertex?.pos),e=this._toXYZ(this._edge.rightVertex.pos),s=this._toXYZ(this._edge.rightVertex.rightEdge?.rightVertex?.pos);this._edgeDirection=o(m(),t,e),this._left=this._computeNeighbor(t,i,this._edgeDirection),this._right=this._computeNeighbor(e,s,this._edgeDirection)}_toXYZ(t){return i(t)?this._helper.toXYZ(t):null}_pointToXYZ(t){return this._toXYZ(this._helper.pointToVector(t))}_computeNeighbor(t,i,s){if(e(i))return{start:t,end:i,direction:u(-s[1],s[0],0),isOriginalDirection:!0};const n=o(m(),t,i),r=!this._passesBisectingAngleThreshold(n,s);return{start:t,end:i,direction:r?this._bisectVectorsPerpendicular(s,n):n,isOriginalDirection:!r}}_passesBisectingAngleThreshold(t,i){const e=Math.abs(X(i,t));return e>=T&&e<=Math.PI-T}_bisectVectorsPerpendicular(t,i){const e=a(t,i)<0?t:_(m(),t),s=Math.abs(a(e,i));if(!(s<Z||s>1-Z))return this._bisectDirection(e,i);const n=c(m(),e,[0,0,1]);return l(n,n)}_bisectDirection(t,i){const e=p(m(),t,i);return l(e,e)}_initializePlane(){const t=this._computeNormalDirection(this._left),i=this._computeNormalDirection(this._right);a(t,i)<0&&_(i,i),E(this._left.start,this._bisectDirection(t,i),this._plane)}_computeNormalDirection(t){const i=c(m(),t.direction,this._edgeDirection);l(i,i);const e=c(m(),this._edgeDirection,i);return this._planeType===A.XY&&(e[2]=0),l(e,e)}_initializeDistanceConstraints(){i(this._left.end)&&!this.requiresSplitEdgeLeft&&this._updateDistanceConstraint(x(this._plane,this._left.end)),i(this._right.end)&&!this.requiresSplitEdgeRight&&this._updateDistanceConstraint(x(this._plane,this._right.end)),this._updateIntersectDistanceConstraint(this._plane)}_updateDistanceConstraint(t){t<=0&&(this._minDistance=Math.max(this._minDistance,t)),t>=0&&(this._maxDistance=Math.min(this._maxDistance,t))}_updateIntersectDistanceConstraint(t){const i=V(t),e=this._edgeDirection,o=p(m(),this._left.start,this._left.direction),a=p(m(),this._right.start,this._right.direction),_=this._pointInBasis2D(h(),i,e,this._left.start),c=this._pointInBasis2D(h(),i,e,o),l=this._pointInBasis2D(h(),i,e,this._right.start),g=this._pointInBasis2D(h(),i,e,a),[f]=N({start:c,end:_,type:y.LINE},{start:g,end:l,type:y.LINE});if(!f)return;const u=s(h(),_,c);n(u,u);const D=s(h(),f,c),E=r(u,D),b=p(m(),o,d(m(),this._left.direction,-E)),I=x(t,b);this._updateDistanceConstraint(I)}_pointInBasis2D(t,i,e,s){return t[0]=Y(i,s),t[1]=Y(e,s),t}_offset(t,e){Number.isFinite(this._minDistance)&&(e=Math.max(this._minDistance,e)),Number.isFinite(this._maxDistance)&&(e=Math.min(this._maxDistance,e)),b(this._offsetPlane,this._plane),this._offsetPlane[3]-=e;const s=(t,e,s)=>i(e)&&M(this._offsetPlane,t,p(m(),t,e),s),n=m();(t===this._edge.leftVertex?s(this._left.start,this._left.direction,n):s(this._right.start,this._right.direction,n))&&this._helper.copy(this._helper.fromXYZ(n,void 0,this._helper.getM(t.pos)),t.pos)}selectArrowFromStartPoint(t){this._selectedArrow=I(this.plane,this._pointToXYZ(t))?1:-1}get selectedArrow(){return this._selectedArrow}signedDistanceToPoint(t){return x(this.plane,this._pointToXYZ(t))}apply(t){this._offset(t,this.distance)}undo(t){this._offset(t,0)}canAccumulate(t){return t instanceof P&&this._edge.leftVertex.index===t._edge.leftVertex.index&&this._edge.rightVertex.index===t._edge.rightVertex.index&&this._edge.component===t._edge.component&&this._maybeEqualsVec3(this._left.direction,t._left.direction)&&this._maybeEqualsVec3(this._right.direction,t._right.direction)&&g(V(this._plane),V(t._plane))}accumulate(t,i){const e=this._plane[3]-i._plane[3]+i.distance;this._offset(t,e)}accumulateParams(t){const i=t.distance-t._plane[3];this.distance=i+this._plane[3]}clone(){const t=new P(this._helper,this._planeType,this._edge,this.distance,j.DEFERRED);return b(t._plane,this._plane),b(t._offsetPlane,this._offsetPlane),t._maxDistance=this._maxDistance,t._minDistance=this._minDistance,t._left=this._cloneNeighbor(this._left),t._right=this._cloneNeighbor(this._right),t._edgeDirection=f(m(),this._edgeDirection),t}_maybeEqualsVec3(t,s){return e(t)&&e(s)||i(t)&&i(s)&&g(t,s)}_cloneNeighbor({start:t,end:e,direction:s,isOriginalDirection:n}){return{start:f(m(),t),end:i(e)?f(m(),e):null,direction:f(m(),s),isOriginalDirection:n}}}const T=t(15),Z=.001;var A,j;!function(t){t[t.XYZ=0]="XYZ",t[t.XY=1]="XY"}(A||(A={})),function(t){t[t.IMMEDIATE=0]="IMMEDIATE",t[t.DEFERRED=1]="DEFERRED"}(j||(j={}));export{P as OffsetEdgeVertex,A as PlaneType};