@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 3.01 kB
JavaScript
import{isNone as t}from"../../../../../../core/maybe.js";import{e}from"../../../../../../chunks/earcut.js";import{triangulate as n}from"../../../../../../geometry/libtess.js";import{TileClipper as o,GeometryType as r}from"../../../../../../geometry/support/TileClipper.js";import s from"../../../../../../layers/graphics/OptimizedGeometry.js";import{TILE_SIZE as l}from"../../definitions.js";import{bufcut as i}from"../bufcut.js";const f=1e-5,c=new o(0,0,0,1,0),u=new o(0,0,0,1,0);function h(t,e,n){let o=0;for(let r=1;r<n;r++){const n=t[2*(e+r-1)],s=t[2*(e+r-1)+1];o+=(t[2*(e+r)]-n)*(t[2*(e+r)+1]+s)}return o}function g(t,e,n,o,r){let s=0;const l=2;for(let i=n;i<o;i+=3){const n=(t[i]-r)*l,o=(t[i+1]-r)*l,f=(t[i+2]-r)*l;s+=Math.abs((e[n]-e[f])*(e[o+1]-e[n+1])-(e[n]-e[o])*(e[f+1]-e[n+1]))}return s}function a(t,e){const{coords:n,lengths:o,hasIndeterminateRingOrder:r}=e,s=0,l=t;if(r)return!1;let c=0;for(let u=0;u<o.length;){let t=u,e=o[u],r=h(n,c,e);const a=[];for(;++t<o.length;){const s=o[t],l=h(n,c+e,s);if(!(l>0))break;r+=l,a.push(c+e),e+=s}const m=l.length;i(l,n,c,c+e,a,2,s);const p=g(l,n,m,l.length,s),d=Math.abs(r);if(Math.abs((p-d)/Math.max(1e-7,d))>f)return l.length=0,!1;u=t,c+=e}return!0}function m(t,n,o){const{coords:r,lengths:s,hasIndeterminateRingOrder:l}=n;if(l)return!1;let i=0;for(let f=0;f<s.length;){let l=f,c=s[f];const u=[];for(;++l<s.length;){const t=s[l];if(!(h(r,i+c,t)>0))break;u.push(i+c-i),c+=t}const g=i+c,a=n.coords.slice(2*i,2*g),m=e(a,u,2);for(const e of m)t.push(e+o+i);f=l,i+=c}return!0}function p(t){const{coords:e,lengths:o}=t,{buffer:r}=n(e,o);return r}function d(t,e,n){let o=0;for(let r=0;r<t.lengths.length;r++){const s=t.lengths[r];for(let r=0;r<s;r++){const s=t.coords[2*(r+o)],l=t.coords[2*(r+o)+1];if(s<e||s>n||l<e||l>n)return!0}o+=s}return!1}function b(e,n){if(t(e))return null;if(!d(e,-128,l+128))return e;c.setPixelMargin(n),c.reset(r.Polygon);let o=0;for(let t=0;t<e.lengths.length;t++){const n=e.lengths[t];let r=e.coords[2*(0+o)],s=e.coords[2*(0+o)+1];c.moveTo(r,s);for(let t=1;t<n;t++)r=e.coords[2*(t+o)],s=e.coords[2*(t+o)+1],c.lineTo(r,s);c.close(),o+=n}const i=c.result(!1);if(!i)return null;const f=[],u=[];for(const t of i){let e=0;for(const n of t)u.push(n.x),u.push(n.y),e++;f.push(e)}return new s(f,u)}function x(t,e){u.setPixelMargin(e);const n=u,o=-e,s=l+e;let i=[],f=!1,c=0;for(;c<t.length;){const e=[],l=t[c];if(!l)return null;n.reset(r.LineString);let[u,h]=l[0];if(f)n.moveTo(u,h);else{if(u<o||u>s||h<o||h>s){f=!0;continue}e.push({x:u,y:h})}let g=!1;const a=l.length;for(let t=1;t<a;++t)if(u+=l[t][0],h+=l[t][1],f)n.lineTo(u,h);else{if(u<o||u>s||h<o||h>s){g=!0;break}e.push({x:u,y:h})}if(g)f=!0;else{if(f){const t=n.resultWithStarts();if(t)for(const e of t)i.push(e)}else i.push({line:e,start:0});c++,f=!1}}return i=i.filter((t=>t.line.length>1)),0===i.length?null:i}c.setExtent(l),u.setExtent(l);export{h as area,x as clipLinesMarshall,b as clipMarshall,g as triangleAreaArray,a as triangulate,m as triangulateEarcut,p as triangulateLibtess};