/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../core/floatRGBA","../../chunks/vec3f64","./BufferObject","./doublePrecisionUtils","./enums","./FramebufferObject","./VertexArrayObject","./VertexElementDescriptor"],(function(e,n,t,o,r,i,a,c,s){"use strict";function l(e,l){const u=new a.FramebufferObject(e,{colorTarget:i.TargetType.TEXTURE,depthStencilTarget:i.DepthStencilTargetType.NONE},{target:i.TextureType.TEXTURE_2D,wrapMode:i.TextureWrapMode.CLAMP_TO_EDGE,pixelFormat:i.PixelFormat.RGBA,dataType:i.PixelType.UNSIGNED_BYTE,samplingMode:i.TextureSamplingMode.NEAREST,width:1,height:1});function p(n,t){const o=`\n\n  precision highp float;\n\n  attribute vec2 position;\n\n  uniform vec3 u_highA;\n  uniform vec3 u_lowA;\n  uniform vec3 u_highB;\n  uniform vec3 u_lowB;\n\n  varying vec4 v_color;\n\n  ${l?"#define DOUBLE_PRECISION_REQUIRES_OBFUSCATION":""}\n\n  #ifdef DOUBLE_PRECISION_REQUIRES_OBFUSCATION\n\n  vec3 dpPlusFrc(vec3 a, vec3 b) {\n    return mix(a, a + b, vec3(notEqual(b, vec3(0))));\n  }\n\n  vec3 dpMinusFrc(vec3 a, vec3 b) {\n    return mix(vec3(0), a - b, vec3(notEqual(a, b)));\n  }\n\n  vec3 dpAdd(vec3 hiA, vec3 loA, vec3 hiB, vec3 loB) {\n    vec3 t1 = dpPlusFrc(hiA, hiB);\n    vec3 e = dpMinusFrc(t1, hiA);\n    vec3 t2 = dpMinusFrc(hiB, e) + dpMinusFrc(hiA, dpMinusFrc(t1, e)) + loA + loB;\n    return t1 + t2;\n  }\n\n  #else\n\n  vec3 dpAdd(vec3 hiA, vec3 loA, vec3 hiB, vec3 loB) {\n    vec3 t1 = hiA + hiB;\n    vec3 e = t1 - hiA;\n    vec3 t2 = ((hiB - e) + (hiA - (t1 - e))) + loA + loB;\n    return t1 + t2;\n  }\n\n  #endif\n\n  const float MAX_RGBA_FLOAT =\n    255.0 / 256.0 +\n    255.0 / 256.0 / 256.0 +\n    255.0 / 256.0 / 256.0 / 256.0 +\n    255.0 / 256.0 / 256.0 / 256.0 / 256.0;\n\n  const vec4 FIXED_POINT_FACTORS = vec4(1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0);\n\n  vec4 float2rgba(const float value) {\n    // Make sure value is in the domain we can represent\n    float valueInValidDomain = clamp(value, 0.0, MAX_RGBA_FLOAT);\n\n    // Decompose value in 32bit fixed point parts represented as\n    // uint8 rgba components. Decomposition uses the fractional part after multiplying\n    // by a power of 256 (this removes the bits that are represented in the previous\n    // component) and then converts the fractional part to 8bits.\n    vec4 fixedPointU8 = floor(fract(valueInValidDomain * FIXED_POINT_FACTORS) * 256.0);\n\n    // Convert uint8 values (from 0 to 255) to floating point representation for\n    // the shader\n    const float toU8AsFloat = 1.0 / 255.0;\n\n    return fixedPointU8 * toU8AsFloat;\n  }\n\n  void main() {\n    vec3 val = dpAdd(u_highA, u_lowA, -u_highB, -u_lowB);\n\n    v_color = float2rgba(val.z / 25.0);\n\n    gl_Position = vec4(position * 2.0 - 1.0, 0.0, 1.0);\n  }\n  `,i="\n  precision highp float;\n\n  varying vec4 v_color;\n\n  void main() {\n    gl_FragColor = v_color;\n  }\n  ",a=e.programCache.acquire(o,i,new Map([["position",0]])),c=new Float32Array(6);r.encodeDoubleArray(n,c,3);const s=new Float32Array(6);return r.encodeDoubleArray(t,s,3),e.useProgram(a),a.setUniform3f("u_highA",c[0],c[2],c[4]),a.setUniform3f("u_lowA",c[1],c[3],c[5]),a.setUniform3f("u_highB",s[0],s[2],s[4]),a.setUniform3f("u_lowB",s[1],s[3],s[5]),a}const v=o.BufferObject.createVertex(e,i.Usage.STATIC_DRAW,new Uint16Array([0,0,1,0,0,1,1,1])),f=new c.VertexArrayObject(e,new Map([["position",0]]),{geometry:[new s.VertexElementDescriptor("position",2,i.DataType.UNSIGNED_SHORT,0,4)]},{geometry:v}),d=t.fromValues(5633261.287538229,2626832.878767164,1434988.0495278358),A=t.fromValues(5633271.46742708,2626873.6381334523,1434963.231608387),h=p(d,A),m=e.getBoundFramebufferObject(),{x:_,y:T,width:b,height:g}=e.getViewport();e.bindFramebuffer(u),e.setViewport(0,0,1,1),e.bindVAO(f),e.drawArrays(i.PrimitiveType.TRIANGLE_STRIP,0,4);const B=new Uint8Array(4);u.readPixels(0,0,1,1,i.PixelFormat.RGBA,i.PixelType.UNSIGNED_BYTE,B),h.dispose(),f.dispose(!1),v.dispose(),u.dispose(),e.setViewport(_,T,b,g),e.bindFramebuffer(m);const E=(d[2]-A[2])/25,F=n.unpackFloatRGBA(B);return Math.abs(E-F)}e.testDoublePrecisionArithmetic=l,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
