/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{isUint8Array as r}from"../../../../core/typedArrayUtil.js";import{newIndexArray as t,getContinuousIndexArray as e}from"../../../../geometry/support/Indices.js";import{PrimitiveType as n}from"../../../webgl/enums.js";function o(r,t){switch(t){case n.TRIANGLES:return f(r);case n.TRIANGLE_STRIP:return u(r);case n.TRIANGLE_FAN:return i(r)}}function f(t){return"number"==typeof t?e(t):r(t)?new Uint16Array(t):t}function u(r){const e="number"==typeof r?r:r.length;if(e<3)return[];const n=e-2,o=t(3*n);if("number"==typeof r){let r=0;for(let t=0;t<n;t+=1)t%2==0?(o[r++]=t,o[r++]=t+1,o[r++]=t+2):(o[r++]=t+1,o[r++]=t,o[r++]=t+2)}else{let t=0;for(let e=0;e<n;e+=1)e%2==0?(o[t++]=r[e],o[t++]=r[e+1],o[t++]=r[e+2]):(o[t++]=r[e+1],o[t++]=r[e],o[t++]=r[e+2])}return o}function i(r){const t="number"==typeof r?r:r.length;if(t<3)return new Uint16Array(0);const e=t-2,n=e<=65536?new Uint16Array(3*e):new Uint32Array(3*e);if("number"==typeof r){let r=0;for(let t=0;t<e;++t)n[r++]=0,n[r++]=t+1,n[r++]=t+2;return n}const o=r[0];let f=r[1],u=0;for(let i=0;i<e;++i){const t=r[i+2];n[u++]=o,n[u++]=f,n[u++]=t,f=t}return n}export{o as convertPrimitiveToTriangles};
