UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 3.16 kB
import{PathGeometryCursor as t,setId as e}from"../CIMCursor.js";import{CurveHelper as r,PIXEL_TOLERANCE as n,PathHelper as o}from"../CurveHelper.js";import{GeometricEffectArrowType as s,GeometricEffectOffsetMethod as i}from"../enums.js";const l=1.7320508075688772,c=5,u=s.OpenEnded;class h{static local(){return null===h.instance&&(h.instance=new h),h.instance}execute(t,e,r,n,o){return new a(t,e,r)}}h.instance=null;class a extends t{constructor(t,e,o){super(t,!1,!0),this._curveHelper=new r,this._width=(void 0!==e.width?e.width:c)*o,this._arrowType=void 0!==e.geometricEffectArrowType?e.geometricEffectArrowType:void 0!==e.arrowType?e.arrowType:u,this._offsetFlattenError=n*o}processPath(t){switch(this._arrowType){case s.OpenEnded:default:return this._constructSimpleArrow(t,!0);case s.Block:return this._constructSimpleArrow(t,!1);case s.Crossed:return this._constructCrossedArrow(t)}}_constructSimpleArrow(t,e){const r=this._curveHelper.calculatePathLength(t);let n=this._width;r<2*n&&(n=r/2);const s=this._curveHelper.getSubCurve(t,0,r-n);if(!s)return null;const i=n/2;if(this._curveHelper.isEmpty(s,!1))return null;const l=this._constructOffset(s,-i);if(!l)return null;const c=this._constructOffset(s,i);if(!c)return null;const u=this._constructArrowBasePoint(l,-i/2);if(!u)return null;const h=this._constructArrowBasePoint(c,i/2);if(!h)return null;const a=t[t.length-1];e||(this._makeControlPoint(c,!0),this._makeControlPoint(l,!0));const _=new o;return _.addPath(c,!0),_.lineTo(h),this._makeControlPoint(_.path()),_.lineTo(a),this._makeControlPoint(_.path()),_.lineTo(u),this._makeControlPoint(_.path()),_.addPath(l,!1),e?{paths:[_.path()]}:(_.close(),{rings:[_.path()]})}_constructCrossedArrow(t){const e=this._curveHelper.calculatePathLength(t);let r=this._width;e<r*(1+l+1)&&(r=e/(1+l+1));const n=this._curveHelper.getSubCurve(t,0,e-r*(1+l));if(!n)return null;const s=r/2;if(this._curveHelper.isEmpty(n,!1))return null;const i=this._constructOffset(n,s);if(!i)return null;const c=this._constructOffset(n,-s);if(!c)return null;const u=this._curveHelper.getSubCurve(t,0,e-r);if(!u)return null;if(this._curveHelper.isEmpty(u,!1))return null;const h=this._constructOffset(u,s);if(!h)return null;const a=this._constructOffset(u,-s);if(!a)return null;const _=h[h.length-1],f=this._constructArrowBasePoint(h,s/2);if(!f)return null;const p=a[a.length-1],m=this._constructArrowBasePoint(a,-s/2);if(!m)return null;const d=t[t.length-1];this._makeControlPoint(i,!1),this._makeControlPoint(c,!1);const w=new o;return w.addPath(i,!0),this._makeControlPoint(w.path()),w.lineTo(p),w.lineTo(m),this._makeControlPoint(w.path()),w.lineTo(d),this._makeControlPoint(w.path()),w.lineTo(f),this._makeControlPoint(w.path()),w.lineTo(_),this._makeControlPoint(w.path()),w.addPath(c,!1),{paths:[w.path()]}}_constructOffset(t,e){return this._curveHelper.offset(t,e,i.Rounded,4,this._offsetFlattenError)}_constructArrowBasePoint(t,e){if(!t||t.length<2)return null;const r=t[t.length-2],n=t[t.length-1],o=[n[0]-r[0],n[1]-r[1]];return this._curveHelper.normalize(o),[n[0]+o[1]*e,n[1]-o[0]*e]}_makeControlPoint(t,r=!1){e(r?t[0]:t[t.length-1],1)}}export{h as EffectArrow};