@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.14 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{e as t}from"../../../../../../chunks/earcut.js";import{triangulate as e}from"../../../../../../geometry/libtess.js";import{TileClipper as n,GeometryType as o}from"../../../../../../geometry/support/TileClipper.js";import r from"../../../../../../layers/graphics/OptimizedGeometry.js";import{tileSize as s}from"../../definitions.js";import{bufcut as l}from"../bufcut.js";const i=1e-5,f=new n(0,0,0,1,0),c=new n(0,0,0,1,0);function u(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 h(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}=e,r=0,s=t;let f=0;for(let c=0;c<o.length;){let t=c,e=o[c],a=u(n,f,e);const g=[];for(;++t<o.length;){const r=o[t],s=u(n,f+e,r);if(!(s>0))break;a+=s,g.push(f+e),e+=r}const p=s.length;l(s,n,f,f+e,g,2,r);const m=h(s,n,p,s.length,r),x=Math.abs(a);if(Math.abs((m-x)/Math.max(1e-7,x))>i)return s.length=0,!1;c=t,f+=e}return!0}function g(e,n,o){const{coords:r,lengths:s}=n;let l=0;for(let i=0;i<s.length;){let f=i,c=s[i];const h=[];for(;++f<s.length;){const t=s[f];if(!(u(r,l+c,t)>0))break;h.push(l+c-l),c+=t}const a=l+c,g=n.coords.slice(2*l,2*a),p=t(g,h,2);for(const t of p)e.push(t+o+l);i=f,l+=c}return!0}function p(t){const{coords:n,lengths:o}=t,{buffer:r}=e(n,o);return r}function m(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 x(t,e){if(null==t)return null;if(!m(t,-128,s+128))return t;f.setPixelMargin(e),f.reset(o.Polygon);let n=0;for(let o=0;o<t.lengths.length;o++){const e=t.lengths[o];let r=t.coords[2*(0+n)],s=t.coords[2*(0+n)+1];f.moveTo(r,s);for(let o=1;o<e;o++)r=t.coords[2*(o+n)],s=t.coords[2*(o+n)+1],f.lineTo(r,s);f.close(),n+=e}const l=f.result(!1);if(!l)return null;const i=[],c=[];for(const o of l){let t=0;for(const e of o)c.push(e.x),c.push(e.y),t++;i.push(t)}return new r(i,c)}function d(t,e){c.setPixelMargin(e);const n=c,r=-e,l=s+e;let i=[],f=!1;if(!t.nextPath())return null;let u=t.pathLength(),h=!0;for(;h;){t.seekPathStart();const e=[];if(!t.pathSize)return null;n.reset(o.LineString),t.nextPoint();let s=t.x,c=t.y;if(f)n.moveTo(s,c);else{if(s<r||s>l||c<r||c>l){f=!0;continue}e.push({x:s,y:c})}let a=!1;for(;t.nextPoint();)if(s=t.x,c=t.y,f)n.lineTo(s,c);else{if(s<r||s>l||c<r||c>l){a=!0;break}e.push({x:s,y:c})}if(a)f=!0;else{if(f){const t=n.resultWithStarts();if(t)for(const e of t)i.push({...e,pathLength:u})}else i.push({line:e,start:0,pathLength:u});h=t.nextPath(),u=h?t.pathLength():0,f=!1}}return i=i.filter((t=>t.line.length>1)),0===i.length?null:i}f.setExtent(s),c.setExtent(s);export{u as area,d as clipLinesMarshall,x as clipMarshall,h as triangleAreaArray,a as triangulate,g as triangulateEarcut,p as triangulateLibtess};