/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{PathTransformationCursor as t}from"../CIMCursor.js";import{GeometryWalker as e,DashPattern as s,Pos as i}from"../GeometryWalker.js";class n{static{this.instance=null}static local(){return null===n.instance&&(n.instance=new n),n.instance}execute(t,e,s){return new a(t,e,s)}}class a extends t{constructor(t,i,n){super(t),this._geometryWalker=new e,this._geometryWalker.updateTolerance(n),this._angleToLine=i.angleToLine??!0,this._keepUpright=i.keepUpright??!1,this._offset=(i.offset?i.offset:0)*n,this._originalEndings=i.endings??"WithHalfGap",this._offsetAtEnd=(i.customEndingOffset?i.customEndingOffset:0)*n,this._position=-(i.offsetAlongLine?i.offsetAlongLine:0)*n,this._pattern=new s,this._pattern.init(i.placementTemplate),this._pattern.scale(n),this._endings=this._originalEndings}processPath(t){if(this._pattern.isEmpty())return null;let e;if(this.iteratePath)e=this._pattern.nextValue();else{"WithFullGap"===this._originalEndings&&this.isClosed?this._endings="WithMarkers":this._endings=this._originalEndings,this._pattern.extPtGap=0;let s,i=!0;switch(this._endings){case"NoConstraint":s=-this._position,s=this._adjustPosition(s),i=!1;break;case"WithHalfGap":default:s=-this._pattern.lastValue()/2;break;case"WithFullGap":s=-this._pattern.lastValue(),this._pattern.extPtGap=this._pattern.lastValue();break;case"WithMarkers":s=0;break;case"Custom":s=-this._position,s=this._adjustPosition(s),this._pattern.extPtGap=.5*this._offsetAtEnd}if(!this._geometryWalker.init(t,this._pattern,i))return null;this._pattern.reset();let n=0;for(;s>n;)s-=n,n=this._pattern.nextValue();n-=s,e=n,this.iteratePath=!0}const s=new i;return this._geometryWalker.nextPointAndAngle(e,s)?"WithFullGap"===this._endings&&this._geometryWalker.isPathEnd()?(this.iteratePath=!1,null):"WithMarkers"===this._endings&&this._geometryWalker.isPathEnd()&&(this.iteratePath=!1,this.isClosed)?null:(this.internalPlacement.setTranslate(s.pt[0]-this._offset*s.sa,s.pt[1]+this._offset*s.ca),this._angleToLine&&this.internalPlacement.setRotateCS(s.ca,s.sa),this.internalPlacement):(this.iteratePath=!1,null)}_adjustPosition(t){let e=t/this._pattern.length();return e-=Math.floor(e),e*this._pattern.length()}}export{n as PlacementAlongLineSameSize};
