UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 4.07 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ import{b as t,c as e}from"./tslib.es6.js";import{G as s}from"./SimpleGeometryCursor.js";import{t as i,d as r,e as a,G as n,f as h,h as m,b as l}from"./Geometry.js";import{a as o,P as c,L as u}from"./QuadraticBezier.js";import{P as _}from"./Envelope.js";import{h as g,P as p,b as k}from"./Point2D.js";import{O as f}from"./OperatorDensify.js";class P{getOperatorType(){return 10204}supportsCurves(){return!0}accelerateGeometry(t,e,s){return!1}canAccelerateGeometry(t){return!1}executeMany(t,e,s,i){return new y(t,e,s,i)}execute(t,e,s,r){t||i("null param is not allowed.");return new y(null,e,s,r).generalize(t)}}class y extends s{constructor(t,e,s,i){super(),this.m_pline=null,this.m_point=new _,this.m_stack=[],this.m_resultstack=[],this.m_callCount=0,this.m_progressTracker=i,this.m_geoms=t,this.m_maxDeviation=e,this.m_bRemoveDegenerateParts=s}tock(){return!0}getRank(){return 1}next(){const t=this.m_geoms.next();return null===t?null:(r(t),this.generalize(t))}getGeometryID(){return this.m_geoms.getGeometryID()}generalize(s){const i=s.getGeometryType();if(a(i))return s;if(i===n.enumEnvelope){const t=new o({vd:s.getDescription()});return t.addEnvelope(s,!1),this.generalize(t)}if(h(i)){const t=new c({vd:s.getDescription()});return t.addSegment(s,!0),this.generalize(t)}if(m(i)||l(""),s.isEmpty()||this.m_maxDeviation<=0)return s;const r=(new f).execute(s,0,.05*this.m_maxDeviation,0,this.m_progressTracker);s.hasNonLinearSegments()&&(this.m_maxDeviation*=.95);const _=r,p=s.createInstance();if(p.getGeometryType()===n.enumPolygon){p.setFillRule(s.getFillRule())}this.m_xy=_.getAttributeStreamRef(0);{const s={stack:[],error:void 0,hasError:!1};try{const e=new u;this.m_pline=e,t(s,g((()=>{this.m_pline=null}),!1),!1);for(let t=0,s=_.getPathCount();t<s;t++)this.generalizePath(_.getImpl(),t,p.getImpl())}catch(k){s.error=k,s.hasError=!0}finally{e(s)}}return this.m_resultstack.length=0,this.m_stack.length=0,p}generalizePath(t,e,s){if(t.getPathSize(e)<2)return;this.m_resultstack.length=0,this.m_stack.length=0;const i=t.getPathStart(e),r=t.getPathEnd(e)-1,a=t.isClosedPath(e),n=t.isClosedPathInXYPlane(e);let h=0,m=-1;this.m_stack.push(a?i:r),this.m_stack.push(i);let l=!1,o=!1;for(!this.m_bRemoveDegenerateParts&&n&&(l=!0,o=!0);this.m_stack.length>1;){const e=this.m_stack.at(-1);this.m_stack.pop();const s=this.m_stack.at(-1);let i=t.getXY(e);this.m_pline.setStartXY(i),i=t.getXY(s),this.m_pline.setEndXY(i);const a=[Number.NaN];let n=this.findGreatestDistance(e,s,r,a);n>=0&&(l?l=!1:(o&&a[0]>h&&(h=a[0],m=n),a[0]<=this.m_maxDeviation&&(n=-1))),n>=0?(this.m_stack.push(n),this.m_stack.push(e)):this.m_resultstack.push(e)}a||this.m_resultstack.push(this.m_stack[0]);const c=this.m_resultstack.length;if(c===t.getPathSize(e)&&c===this.m_stack.length)s.addPath(t,e,!0);else if(this.m_resultstack.length>0){if(this.m_bRemoveDegenerateParts&&this.m_resultstack.length<=2){if(a||1===this.m_resultstack.length)return;if(p.distance(t.getXY(this.m_resultstack[0]),t.getXY(this.m_resultstack[1]))<=this.m_maxDeviation)return}if(o&&m>=0&&h<=this.m_maxDeviation){const t=this.m_resultstack.at(-1)>m;this.m_resultstack.push(m),t&&(this.m_resultstack[this.m_resultstack.length-2]=k(this.m_resultstack[this.m_resultstack.length-1],this.m_resultstack[this.m_resultstack.length-1]=this.m_resultstack[this.m_resultstack.length-2]))}for(let e=0,i=this.m_resultstack.length;e<i;e++)t.getPointByVal(this.m_resultstack[e],this.m_point),0===e?s.startPathPoint(this.m_point):s.lineToPoint(this.m_point);if(a){for(let t=this.m_resultstack.length;t<3;t++)s.lineToPoint(this.m_point);s.closePathWithLine()}}}findGreatestDistance(t,e,s,i){let r=e-1;e<=t&&(r=s);let a=-1,n=0;const h=new p;for(let m=t+1;m<=r;m++){this.m_xy.queryPoint2D(2*m,h);const t=h.x,e=h.y,s=this.m_pline.getClosestCoordinate(h,!1);h.assign(this.m_pline.getCoord2D(s)),h.x-=t,h.y-=e;const i=h.length();i>n&&(a=m,n=i),this.m_callCount++}return i[0]=n,a}}export{P as O};