/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{isArrayWithReadonly as t}from"../../../../core/arrayUtils.js";import{JSONMap as e}from"../../../../core/jsonMap.js";import i from"../../engine/webgl/effects/highlight/HighlightGradient.js";import{MultiHighlightGradient as n}from"../../engine/webgl/effects/highlight/MultiHighlightGradient.js";import{getFeaturePipelineState as s}from"../../engine/webgl/shaderGraph/techniques/featureTechniqueUtils.js";const r=new e({esriGeometryPoint:"point",esriGeometryMultipoint:"multipoint",esriGeometryPolyline:"polyline",esriGeometryPolygon:"polygon",esriGeometryMultiPatch:"multipatch",mesh:"mesh"});function l(t){return r.toJSON(t)}function o(t,e,i){const n=[],s=[];let r=0,l=0;for(const o of t){const t=l;let a=o[0][0],h=o[0][1];n[l++]=a,n[l++]=h;let p=0;for(let e=1;e<o.length;++e){const t=a,i=h;a=o[e][0],h=o[e][1],p+=h*t-a*i,n[l++]=a,n[l++]=h}e(p/2),p>0?(t-r>0&&(i(r,t,n,s),r=t),s.length=0):p<0&&t-r>0?s.push(.5*(t-r)):l=t}l-r>0&&i(r,l,n,s)}function a(t){const{bandCount:e,attributeTable:i,colormap:n,pixelType:s}=t.raster.rasterInfo;return 1===e&&(null!=i||null!=n||"u8"===s||"s8"===s)}function h(e,s){return null==s?(e?.destroy(),null):("single"===e?.type&&Array.isArray(s)&&(e.destroy(),e=null),"multi"!==e?.type||Array.isArray(s)||(e.destroy(),e=null),e||(e=Array.isArray(s)?new n:new i),t(s)?"multi"===e.type&&e.setHighlightOptions(s):"single"===e.type&&e.setHighlightOptions(s),e)}function p(t,e,i,n){const{painter:r,highlightGradient:l}=t,{highlight:o}=r.effects;if(!l)return;const a=t.passOptions,h=l.getReasonsWithGradients();for(let p=0;p<h.length;p++){const l={...t,passOptions:{type:"highlight",activeGradient:null!=n?h[n].activeGradient:h[p].activeGradient,activeReasons:h[p].activeReasons,stepType:"burn",highlightAll:e}};if(o.bind(l),i(l),p<h.length-1){let s=0;for(let t=p+1;t<h.length;t++)s|=h[t].activeReasons;i({...t,passOptions:{type:"highlight",activeGradient:null!=n?h[n].activeGradient:h[p].activeGradient,activeReasons:s,stepType:"clear",highlightAll:e}})}const a={...t,passOptions:{type:"highlight",activeGradient:null!=n?h[n].activeGradient:h[p].activeGradient,activeReasons:h[p].activeReasons,stepType:"draw",highlightAll:e}};r.setPipelineState(s(t)),r.updatePipelineState(t.context),o.draw(a),o.unbind()}t.passOptions=a}export{o as analyzeRings,a as canUseMajorityInterpolationOnDataSource,h as createOrReuseHighlightGradient,p as renderHighlight,l as toJSONGeometryType};
