/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as t,__param as e}from"tslib";import{pt2px as i}from"../../../../../../../core/screenUtils.js";import{dashSdfRasterizationScale as o,dashSdfDistanceNormalization as s}from"../../../../../../../symbols/cim/constants.js";import{location as r,uniform as a,texture as l,input as n}from"../../GraphShaderModule.js";import{Float as p,Vec2 as c,Vec4 as m,Sampler2D as u,max as d,fract as y,mix as h,texture2D as f,cond as w,equal as b,sqrt as x,pow as g,clamp as v,ifElse as D,greaterThan as S,dot as T}from"../../graph/glsl.js";import{BaseHittestVertexInput as j}from"./AFeatureShader.js";import{bitsetLineScaleDash as A,bitsetLineIsSdf as z,bitsetGenericConsiderAlphaOnly as F}from"./constants.js";import{LineVertexInput as L,LineShader as _,getLineVertexData as C,getLineAntialiasing as O,LineFragmentInput as P}from"./LineShader.js";import{MosaicInfo as W}from"./MosaicInfo.js";import{getBit as I,rgba2float as R}from"./utils.js";class H extends L{}t([r(9,p)],H.prototype,"accumulatedDistance",void 0),t([r(10,c)],H.prototype,"segmentDirection",void 0),t([r(11,p)],H.prototype,"offsetAlongLine",void 0),t([r(12,p)],H.prototype,"capType",void 0),t([r(13,m)],H.prototype,"tlbr",void 0);class M extends P{}class G extends _{constructor(){super(...arguments),this.type="TexturedLineShader"}_getDistanceRatio(t,e){const o=I(t.bitset,A);return o.multiply(d(e,new p(.25)).multiply(new p(2))).add(new p(1).subtract(o).multiply(i(1)))}_getSDFAlpha(t){const{halfWidth:e,normal:i,tlbr:r,patternSize:a,accumulatedDistance:l,offsetAlongLine:n,dashToPx:u,capType:D}=t,S=a.x.divide(o).multiply(u),T=y(l.add(n).divide(S)),j=h(r.xy,r.zw,new c(T,.5)),A=R(f(this.mosaicTexture,j)).multiply(2).subtract(1).multiply(s).multiply(u),z=i.y.multiply(e),F=w([b(D,new p(1)),A.subtract(e)],[b(D,new p(2)),x(g(d(A,new p(0)),new p(2)).add(z.multiply(z))).subtract(e)],[!0,A]),L=v(new p(.25).subtract(F),new p(0),new p(1));return new m(L)}_getPatternColor(t){const{halfWidth:e,normal:i,color:o,accumulatedDistance:s,patternSize:r,sampleAlphaOnly:a,tlbr:l}=t,n=r.y.multiply(new p(2).multiply(e).divide(r.x)),u=y(s.divide(n)),d=new p(.5).multiply(i.y).add(new p(.5)),w=h(l.xy,l.zw,new c(d,u));let b=f(this.mosaicTexture,w);return null!=this.visualVariableColor&&(b=D(S(a,new p(.5)),new m(o.a),o)),b}vertex(t,e){const{segmentDirection:i,tlbr:o,bitset:s}=t,r=C(this,t),a=t.accumulatedDistance.divide(this.view.displayZoomFactor).add(T(i,r.scaledOffset)),l=new c(o.z.subtract(o.x),o.w.subtract(o.y)),n=o.divide(this.mosaicInfo.size.xyxy),m=I(s,z),u=I(s,F),d=D(S(m,new p(.5)),this._getDistanceRatio(t,r.scaledHalfWidth),new p(1));return{...r,tlbr:n,patternSize:l,accumulatedDistance:a,isSDF:m,sampleAlphaOnly:u,dashToPx:d,offsetAlongLine:t.offsetAlongLine,capType:t.capType,...this.maybeRunHittest(t,e,r.halfWidth)}}fragment(t){const{color:e,opacity:i,isSDF:o}=t,s=O(t,this.antialiasingControls.blur),r=D(S(o,new p(.5)),this._getSDFAlpha(t),this._getPatternColor(t)),a=e.multiply(i).multiply(s).multiply(r);return this.getFragmentOutput(a,t)}}t([a(W)],G.prototype,"mosaicInfo",void 0),t([l(u)],G.prototype,"mosaicTexture",void 0),t([e(0,n(H)),e(1,n(j))],G.prototype,"vertex",null);export{M as TexturedLineFragmentInput,G as TexturedLineShader,H as TexturedLineVertexInput};
