UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 1.68 kB
import{width as t,height as e,intersects as n}from"../../../../geometry/support/aaBoundingRect.js";import{Attribute as r}from"../../webgl-engine/lib/Attribute.js";import{newDoubleArray as i}from"../../webgl-engine/lib/DoubleArray.js";import{newFloatArray as o}from"../../webgl-engine/lib/FloatArray.js";import{Geometry as m}from"../../webgl-engine/lib/Geometry.js";import{createSquareGeometry as l}from"../../webgl-engine/lib/GeometryUtil.js";import{VertexAttribute as g}from"../../webgl-engine/lib/VertexAttribute.js";function h(n,r,i){const o=t(n)/e(n),m={width:i,height:i};return o>1.0001?m.height=i/o:o<.9999&&(m.width=i*o),m.width=Math.round(m.width/(t(n)/t(r))),m.height=Math.round(m.height/(e(n)/e(r))),m}function w(t,e){return l(t,[[e[0],e[1],-1],[e[2],e[1],-1],[e[2],e[3],-1],[e[0],e[3],-1]])}function a(t,e,l){if(!n(e,l))return w(t,l);const h=[e[1]-l[1],Math.min(e[3],l[3])-Math.max(e[1],l[1]),l[3]-e[3],123456],a=[e[0]-l[0],Math.min(e[2],l[2])-Math.max(e[0],l[0]),l[2]-e[2],123456],u=l[2]-l[0],f=l[3]-l[1],s=a[0]>0&&a[2]>0?3:2,c=h[0]>0&&h[2]>0?3:2,p=(c+1)*(s+1),A=i(3*p),M=o(2*p),d=new Array(6*(c*s-1));let j=0,y=0,O=0,x=0,I=0;for(let n=0;n<4;n++){const t=h[n];if(t<=0)continue;let e=0;for(let r=0;r<4;r++){const t=a[r];t<=0||(A[y++]=l[0]+e,A[y++]=l[1]+j,A[y++]=-1,M[O++]=e/u,M[O++]=j/f,r<3&&n<3&&(1!==r||1!==n)&&(d[I++]=x,d[I++]=x+1,d[I++]=x+s+1,d[I++]=x+1,d[I++]=x+s+2,d[I++]=x+s+1),x++,e+=t)}j+=t}const N=new Array(d.length);return new m(t,[[g.POSITION,new r(A,3,!0)],[g.NORMAL,new r(b,3,!0)],[g.UV0,new r(M,2,!0)]],[[g.POSITION,d],[g.NORMAL,N],[g.UV0,d]])}const b=[0,0,1];export{h as computeImageExportSize,w as createGeometryForExtent,a as createOuterImageGeometry};