/*
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/maybe","../../../../renderers/PointCloudClassBreaksRenderer","../../../../renderers/PointCloudStretchRenderer","../../../../renderers/PointCloudUniqueValueRenderer","./I3SBinaryReader","./LEPCC"],(function(e,o,r,t,n,l,i){"use strict";function s(e,o,l,i){const{rendererJSON:s,isRGBRenderer:u}=e;let a=null,c=null;if(o&&u)a=o;else if(o&&"pointCloudUniqueValueRenderer"===s.type){c=n.fromJSON(s);const e=c.colorUniqueValueInfos;a=new Uint8Array(3*i);const r=d(c.fieldTransformType);for(let t=0;t<i;t++){const n=(r?r(o[t]):o[t])+"";for(let o=0;o<e.length;o++)if(e[o].values.includes(n)){a[3*t]=e[o].color.r,a[3*t+1]=e[o].color.g,a[3*t+2]=e[o].color.b;break}}}else if(o&&"pointCloudStretchRenderer"===s.type){c=t.fromJSON(s);const e=c.stops;a=new Uint8Array(3*i);const r=d(c.fieldTransformType);for(let t=0;t<i;t++){const n=r?r(o[t]):o[t],l=e.length-1;if(n<e[0].value)a[3*t]=e[0].color.r,a[3*t+1]=e[0].color.g,a[3*t+2]=e[0].color.b;else if(n>=e[l].value)a[3*t]=e[l].color.r,a[3*t+1]=e[l].color.g,a[3*t+2]=e[l].color.b;else for(let o=1;o<e.length;o++)if(n<e[o].value){const r=(n-e[o-1].value)/(e[o].value-e[o-1].value);a[3*t]=e[o].color.r*r+e[o-1].color.r*(1-r),a[3*t+1]=e[o].color.g*r+e[o-1].color.g*(1-r),a[3*t+2]=e[o].color.b*r+e[o-1].color.b*(1-r);break}}}else if(o&&"pointCloudClassBreaksRenderer"===s.type){c=r.fromJSON(s);const e=c.colorClassBreakInfos;a=new Uint8Array(3*i);const t=d(c.fieldTransformType);for(let r=0;r<i;r++){const n=t?t(o[r]):o[r];for(let o=0;o<e.length;o++)if(n>=e[o].minValue&&n<=e[o].maxValue){a[3*r]=e[o].color.r,a[3*r+1]=e[o].color.g,a[3*r+2]=e[o].color.b;break}}}else{a=new Uint8Array(3*i);for(let e=0;e<a.length;e++)a[e]=255}if(l&&c&&c.colorModulation){const e=c.colorModulation.minValue,o=c.colorModulation.maxValue,r=.3;for(let t=0;t<i;t++){const n=l[t],i=n>=o?1:n<=e?r:r+(1-r)*(n-e)/(o-e);a[3*t]=i*a[3*t],a[3*t+1]=i*a[3*t+1],a[3*t+2]=i*a[3*t+2]}}return a}function u(e,r){if(null==e.encoding||""===e.encoding){const t=l.createGeometryIndexFromSchema(r,e);if(o.isNone(t.vertexAttributes.position))return;const n=l.createTypedView(r,t.vertexAttributes.position),i=t.header.fields,s=[i.offsetX,i.offsetY,i.offsetZ],u=[i.scaleX,i.scaleY,i.scaleZ],a=n.length/3,c=new Float64Array(3*a);for(let e=0;e<a;e++)c[3*e]=n[3*e]*u[0]+s[0],c[3*e+1]=n[3*e+1]*u[1]+s[1],c[3*e+2]=n[3*e+2]*u[2]+s[2];return c}if("lepcc-xyz"===e.encoding)return i.decodeXYZ(r).result}function a(e,r,t){return o.isSome(e)&&e.attributeInfo.useElevation?c(r,t):o.isSome(e)?l.readBinaryAttribute(e.attributeInfo.storageInfo,e.buffer,t):null}function c(e,o){const r=new Float64Array(o);for(let t=0;t<o;t++)r[t]=e[3*t+2];return r}function f(e,o,r,t,n){const l=e.length/3;let i=0;for(let s=0;s<l;s++){let l=!0;for(let e=0;e<t.length&&l;e++){const{filterJSON:o}=t[e],r=n[e].values[s];switch(o.type){case"pointCloudValueFilter":{const e="exclude"===o.mode;o.values.includes(r)===e&&(l=!1);break}case"pointCloudBitfieldFilter":{const e=b(o.requiredSetBits),t=b(o.requiredClearBits);(r&e)===e&&0==(r&t)||(l=!1);break}case"pointCloudReturnFilter":{const e=15&r,t=r>>>4&15,n=t>1,i=1===e,s=e===t;let u=!1;for(const r of o.includedReturns)if("last"===r&&s||"firstOfMany"===r&&i&&n||"lastOfMany"===r&&s&&n||"single"===r&&!n){u=!0;break}u||(l=!1);break}}}l&&(r[i]=s,e[3*i]=e[3*s],e[3*i+1]=e[3*s+1],e[3*i+2]=e[3*s+2],o[3*i]=o[3*s],o[3*i+1]=o[3*s+1],o[3*i+2]=o[3*s+2],i++)}return i}function d(e){return null==e||"none"===e?null:"low-four-bit"===e?e=>15&e:"high-four-bit"===e?e=>(240&e)>>4:"absolute-value"===e?e=>Math.abs(e):"modulo-ten"===e?e=>e%10:null}function b(e){let o=0;for(const r of e||[])o|=1<<r;return o}e.elevationFromPositions=c,e.evaluateRenderer=s,e.filterInPlace=f,e.getAttributeValues=a,e.readGeometry=u,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
