@csi-foxbyte/mesh-dem-to-terrain
Version:
A Node.js library that converts DEM meshes (DXF, GeoJSON, etc.) into Cesium Terrain Tiles (quantized-mesh or heightmap) with flexible zoom-level control and multi-threading support.
2 lines • 1.23 kB
JavaScript
function h(e,r){let u,t,n,m,i,l=[];for(let f=1;f<=8;f*=2){for(l=[],u=e[e.length-1],t=!(o(u,r)&f),n=0;n<e.length;n++)m=e[n],i=!(o(m,r)&f),i!==t&&l.push(c(u,m,f,r)),i&&l.push(m),u=m,t=i;if(e=l,!e.length)break}return l}function c(e,r,u,t){let n,m,i,l;if(u&8){if(r[1]===e[1])throw new Error("Segment is horizontal; cannot intersect with top clip edge.");n=(t[3]-e[1])/(r[1]-e[1]),m=e[0]+n*(r[0]-e[0]),i=t[3];}else if(u&4){if(r[1]===e[1])throw new Error("Segment is horizontal; cannot intersect with bottom clip edge.");n=(t[1]-e[1])/(r[1]-e[1]),m=e[0]+n*(r[0]-e[0]),i=t[1];}else if(u&2){if(r[0]===e[0])throw new Error("Segment is vertical; cannot intersect with right clip edge.");n=(t[2]-e[0])/(r[0]-e[0]),m=t[2],i=e[1]+n*(r[1]-e[1]);}else if(u&1){if(r[0]===e[0])throw new Error("Segment is vertical; cannot intersect with left clip edge.");n=(t[0]-e[0])/(r[0]-e[0]),m=t[0],i=e[1]+n*(r[1]-e[1]);}else throw new Error("Invalid edge value");if(n>1||n<0)throw new Error("Calculated parameter t is out of range.");return l=e[2]+n*(r[2]-e[2]),[m,i,l]}function o(e,r){let u=0;return e[0]<r[0]?u|=1:e[0]>r[2]&&(u|=2),e[1]<r[1]?u|=4:e[1]>r[3]&&(u|=8),u}export{h as polygonclip};//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map