UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 1.43 kB
import{clone as s}from"../../../core/lang.js";import{isPolygon as t,isPolyline as e,isExtent as i}from"../../../geometry/support/jsonUtils.js";import{setId as n}from"../CIMCursor.js";class o{static local(){return null===o.instance&&(o.instance=new o),o.instance}execute(s,t,e,i,n){return new r(s,t,e)}}o.instance=null;class r{constructor(s,t,e){this._inputGeometries=s,this._angleTolerance=void 0!==t.angleTolerance?t.angleTolerance:120,this._maxCosAngle=Math.cos((1-Math.abs(this._angleTolerance)/180)*Math.PI)}next(){let n=this._inputGeometries.next();for(;n;){if(t(n)){this._isClosed=!0;const t=s(n);return this._processMultipath(t.rings),t}if(e(n)){this._isClosed=!1;const t=s(n);return this._processMultipath(t.paths),t}if(i(n)){if(this._maxCosAngle)return n;this._isClosed=!0;const s=[[n.xmin,n.ymin],[n.xmin,n.ymax],[n.xmax,n.ymax],[n.xmax,n.ymin],[n.xmin,n.ymin]];return this._processPath(s),{rings:[s]}}n=this._inputGeometries.next()}return null}_processMultipath(s){if(s)for(const t of s)this._processPath(t)}_processPath(s){if(s){let t,e,i,o,r,l,a=s.length,h=s[0];this._isClosed&&++a;for(let c=1;c<a;++c){let m;m=this._isClosed&&c===a-1?s[0]:s[c];const _=m[0]-h[0],u=m[1]-h[1],p=Math.sqrt(_*_+u*u);if(c>1&&p>0&&i>0){(t*_+e*u)/p/i<=this._maxCosAngle&&n(h,1)}1===c&&(o=_,r=u,l=p),p>0&&(h=m,t=_,e=u,i=p)}if(this._isClosed&&i>0&&l>0){(t*o+e*r)/l/i<=this._maxCosAngle&&n(s[0],1)}}}}export{o as EffectAddControlPoints};