/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../geometry/support/jsonUtils","../CurveHelper","../enums","../GeometryWalker"],(function(t,e,i,n,s){"use strict";let h=function(){function t(){}return t.local=function(){return null===t.instance&&(t.instance=new t),t.instance},t.prototype.execute=function(t,e,i,n){return new r(t,e,i)},t}();h.instance=null;let r=function(){function t(t,e,i){this._inputGeometries=t,this._height=(void 0!==e.amplitude?e.amplitude:2)*i,this._period=(void 0!==e.period?e.period:3)*i,this._style=e.waveform,this._height<=0&&(this._height=Math.abs(this._height)),this._period<=0&&(this._period=Math.abs(this._period)),this._pattern=new s.DashPattern,this._pattern.addValue(this._period),this._pattern.addValue(this._period),this._walker=new s.GeometryWalker,this._walker.updateTolerance(i)}var h=t.prototype;return h.next=function(){let t=this._inputGeometries.next();for(;t;){if(0===this._height||0===this._period)return t;if(e.isPolyline(t)){const e=this._processGeom(t.paths);if(e.length)return{paths:e}}if(e.isPolygon(t)){const e=this._processGeom(t.rings);if(e.length)return{rings:e}}t=this._inputGeometries.next()}return null},h._processGeom=function(t){const e=[];for(const i of t)if(this._walker.init(i,this._pattern))switch(this._style){case n.GeometricEffectWaveform.Sinus:default:e.push(this._constructCurve(i,!1));break;case n.GeometricEffectWaveform.Square:e.push(this._constructSquare(i));break;case n.GeometricEffectWaveform.Triangle:e.push(this._constructTriangle(i));break;case n.GeometricEffectWaveform.Random:e.push(this._constructCurve(i,!0))}else e.push(i);return e},h._constructCurve=function(t,e){const n=new i.PathHelper,s=this._walker.calculatePathLength(t);let h=Math.round(s/this._period);0===h&&(h=1);const r=h*16+1,a=s/h,o=this._period/16,l=1/r,c=2*Math.PI*s/a,u=2*Math.PI*Math.random(),_=2*Math.PI*Math.random(),p=2*Math.PI*Math.random(),d=.75-Math.random()/2,f=.75-Math.random()/2,g={};this._walker.curPointAndAngle(g),n.startPath(g.pt);let P=0;for(;;){if(!this._walker.nextPointAndAngle(o,g)){n.lineTo(t[t.length-1]);break}{const t=P;let i;if(P+=l,e){const e=this._height/2*(1+.3*Math.sin(d*c*t+u));i=e*Math.sin(c*t+_),i+=e*Math.sin(f*c*t+p),i/=2}else i=.5*this._height*Math.sin(.5*c*t);n.lineTo([g.pt[0]-i*g.sa,g.pt[1]+i*g.ca])}}return n.path()},h._constructSquare=function(t){const e=new i.PathHelper,n=this._walker.calculatePathLength(t);Math.round(n/this._period);let s=!0;for(;;){let t=!1;if(this._walker.curPositionIsValid()){const i={};this._walker.curPointAndAngle(i);const n={};if(this._walker.nextPointAndAngle(this._period,n)){const h={};this._walker.nextPointAndAngle(this._period,h)&&(s?(e.startPath(i.pt),s=!1):e.lineTo(i.pt),e.lineTo([i.pt[0]-this._height/2*i.sa,i.pt[1]+this._height/2*i.ca]),e.lineTo([n.pt[0]-this._height/2*n.sa,n.pt[1]+this._height/2*n.ca]),e.lineTo([n.pt[0]+this._height/2*n.sa,n.pt[1]-this._height/2*n.ca]),e.lineTo([h.pt[0]+this._height/2*h.sa,h.pt[1]-this._height/2*h.ca]),t=!0)}}if(!t){e.lineTo(this._walker.getPathEnd());break}}return e.path()},h._constructTriangle=function(t){const e=new i.PathHelper,n=this._walker.calculatePathLength(t);Math.round(n/this._period);let s=!0;for(;;){let t=!1;if(this._walker.curPositionIsValid()){const i={};this._walker.curPointAndAngle(i);const n={};if(this._walker.nextPointAndAngle(this._period/2,n)){const h={};this._walker.nextPointAndAngle(this._period,h)&&(this._walker.nextPosition(this._period/2)&&(s?(e.startPath(i.pt),s=!1):e.lineTo(i.pt),e.lineTo([n.pt[0]-this._height/2*n.sa,n.pt[1]+this._height/2*n.ca]),e.lineTo([h.pt[0]+this._height/2*h.sa,h.pt[1]-this._height/2*h.ca])),t=!0)}}if(!t){e.lineTo(this._walker.getPathEnd());break}}return e.path()},t}();t.EffectWave=h,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
