license import { GPGPUProgram } from './gpgpu_math' ; import { UniformType } from './shader_compiler' ; export class ClipProgram implements GPGPUProgram { variableNames = [ 'A' ] ; userCode : string ; outputShape : number [ ] ; customUniforms = [ { name : 'minVal' , type : 'float' as UniformType } , { name : 'maxVal' , type : 'float' as UniformType } ] ; constructor ( aShape ) { this . outputShape = aShape ; this . userCode = `

      void main() {
        float value = getAAtOutCoords();
        if (isnan(value)) {
          setOutput(value);
          return;
        }

        setOutput(clamp(value, minVal, maxVal));
      }
    ` ; } }