@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 1.37 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{packFloatRGBA as t}from"../../../../core/floatRGBA.js";import{ProceduralTextureRepository as e}from"./ProceduralTextureRepository.js";import{PixelFormat as r,TextureWrapMode as o}from"../../../webgl/enums.js";import{Texture as n}from"../../../webgl/Texture.js";import{TextureDescriptor as i}from"../../../webgl/TextureDescriptor.js";function u(t,u){return new e((e=>{const{encodedData:u,textureSize:c}=a(e),f=new i;return f.internalFormat=r.RGBA,f.width=c,f.height=1,f.wrapMode=o.REPEAT,new n(t,f,u)}),(t=>`${t.pattern.join(",")}-r${t.pixelRatio}`),u)}function a(e){const r=c(e),o=1/e.pixelRatio,n=f(e),i=s(e),u=(Math.floor(.5*(i-1))+.5)*o,a=[];let l=1;for(const t of r){for(let e=0;e<t;e++){const r=l*(Math.min(e,t-1-e)+.5)*o/u*.5+.5;a.push(r)}l=-l}const p=Math.round(r[0]/2),m=[...a.slice(p),...a.slice(0,p)],d=new Uint8Array(4*n);let x=0;for(const c of m)t(c,d,x),x+=4;return{encodedData:d,textureSize:n}}function c(t){return t.pattern.map((e=>Math.round(e*t.pixelRatio)))}function f(t){if(null==t)return 1;const e=c(t);return Math.floor(e.reduce(((t,e)=>t+e)))}function s(t){return c(t).reduce(((t,e)=>Math.max(t,e)))}export{s as computeLongestPattern,f as computeTextureSize,u as createStippleTextureRepository};