@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.3 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import{PathTransformationCursor as t}from"../CIMCursor.js";import{CurveHelper as e}from"../CurveHelper.js";const s=1e-15;class i{static local(){return null===i.instance&&(i.instance=new i),i.instance}execute(t,e,s,i,o){return new n(t,e,s)}}i.instance=null;class n extends t{constructor(t,s,i){super(t),this._curveHelper=new e,this._angleToLine=void 0===s.angleToLine||s.angleToLine,this._offset=void 0!==s.offset?s.offset*i:0,this._endPoints=void 0===s.placeOnEndPoints||s.placeOnEndPoints,this._controlPoints=void 0===s.placeOnControlPoints||s.placeOnControlPoints,this._regularVertices=void 0===s.placeOnRegularVertices||s.placeOnRegularVertices,this._tags=[],this._tagIterator=0}processPath(t){if(this.iteratePath||(this._preparePath(t),this.iteratePath=!0),this._tagIterator>=this._tags.length)return this._tags.length=0,this._tagIterator=0,this.iteratePath=!1,null;const e=this._tags[this._tagIterator];this._angleToLine&&this.internalPlacement.setRotate(e[2]);let s=e[0],i=e[1];if(0!==this._offset){const t=Math.cos(e[2]),n=Math.sin(e[2]);s-=this._offset*n,i+=this._offset*t}return this.internalPlacement.setTranslate(s,i),this._tagIterator++,this.internalPlacement}_preparePath(t){this._tags.length=0,this._tagIterator=0,t.seekPathStart();const e=t.isClosed();let s=0,i=!1,n=0,r=0;if(t.seekPathStart(),t.nextPoint()){let a=t.x,h=t.y,l=t.getControlPoint(),_=!0,c=t.nextPoint();for(;c;){const g=t.x,P=t.y,u=t.getControlPoint();(this._angleToLine||0!==this._offset)&&(n=this._curveHelper.getAngle(a,h,g,P,0)),_?(_=!1,e?(s=n,i=l):(this._endPoints||this._controlPoints&&l)&&this._tags.push([a,h,n])):l?this._controlPoints&&this._tags.push([a,h,o(r,n)]):this._regularVertices&&this._tags.push([a,h,o(r,n)]),(this._angleToLine||0!==this._offset)&&(r=this._curveHelper.getAngle(a,h,g,P,1)),c=t.nextPoint(),c||(e?u||i?this._controlPoints&&this._tags.push([g,P,o(r,s)]):this._regularVertices&&this._tags.push([g,P,o(r,s)]):(this._endPoints||this._controlPoints&&u)&&this._tags.push([g,P,r])),a=g,h=P,l=u}}this._tagIterator=0}}function o(t,e){const i=Math.PI;for(;Math.abs(e-t)>i+2*s;)e-t>i?e-=2*i:e+=2*i;return(t+e)/2}export{i as PlacementOnVertices};