UNPKG

@arcgis/core

Version:

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

6 lines (5 loc) • 28.8 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{b as e,c as t}from"./tslib.es6.js";import{G as s,a as i,j as n,t as r,k as m,e as o,l as a,m as h,f as l,d as c,g as u}from"./Geometry.js";import{G as f}from"./SimpleGeometryCursor.js";import{C as _,c as g,P as d,E as p,s as b}from"./Envelope.js";import{i as P,m as y,P as x,h as C,d as D,a as w}from"./Point2D.js";import{L as T,D as v,a as S,P as I,i as M,E,n as V}from"./MultiPathImpl.js";import{Envelope2D as k}from"./Envelope2D.js";import{T as B}from"./Transformation2D.js";import{c as R}from"./GeometryCleaner-BEJM7I4l.js";import{j as A,O as X,p as Y}from"./ProjectionTransformation.js";import{O as j}from"./OperatorSimplifyOGC.js";import{O as F}from"./OperatorGeneralize.js";var L;function q(e,t,s,i,n,r){return{m_from:e.clone(),m_to:t.clone(),m_center:s.clone(),m_next:n,m_type:i}}function z(e,t,s,i,n){return{m_from:e.clone(),m_to:t.clone(),m_next:s,m_type:4,m_center:new x}}!function(e){e[e.enumDummy=256]="enumDummy",e[e.enumLine=1]="enumLine",e[e.enumArc=2]="enumArc",e[e.enumMiter=8]="enumMiter",e[e.enumBevel=16]="enumBevel",e[e.enumJoinMask=26]="enumJoinMask",e[e.enumConnectionMask=27]="enumConnectionMask"}(L||(L={}));class G extends f{constructor(e,t,s,i,n,r,m,o,a,h){super(),this.m_index=0,this.m_bufferedPolygon=null,this.m_x=0,this.m_y=0,this.m_progressTracker=h,this.m_parent=e,this.m_mp=t,this.m_distance=s,this.m_spatialReference=i,this.m_densifyDist=o,this.m_maxVertexInCompleteCircle=a,this.m_joins=n,this.m_caps=r,this.m_miterLimit=m}next(){const e=new d;for(;;){if(this.m_index===this.m_mp.getPointCount())return null;if(1===this.m_caps)return this.m_index=this.m_mp.getPointCount(),new S({vd:this.m_mp.getDescription()});if(this.m_mp.getPointByVal(this.m_index,e),this.m_index++,!e.isEmpty())break}let t,s=!1;if(null===this.m_bufferedPolygon&&(this.m_x=e.getX(),this.m_y=e.getY(),this.m_bufferedPolygon=this.m_parent.buffer(e,this.m_distance,this.m_spatialReference,this.m_joins,this.m_caps,this.m_miterLimit,this.m_densifyDist,this.m_maxVertexInCompleteCircle),s=!0),t=this.m_index<this.m_mp.getPointCount()?this.m_bufferedPolygon.clone():this.m_bufferedPolygon,!s){const s=new B,i=e.getX()-this.m_x,n=e.getY()-this.m_y;s.setShiftCoords(i,n),t.applyTransformation(s)}return b(t,0),t}getGeometryID(){return 0}getRank(){return 1}tock(){return!0}}class N extends f{constructor(e){super(),this.m_currentPathIndex=0,this.m_polyline=e}next(){if(!this.m_polyline)return null;const e=this.m_polyline.getImpl(),t=e.getPathCount();if(this.m_currentPathIndex<t){const t=this.m_currentPathIndex;if(this.m_currentPathIndex++,!e.isClosedPathInXYPlane(t)){let s=e.getXY(e.getPathEnd(t)-1);for(;this.m_currentPathIndex<e.getPathCount();){const t=e.getXY(e.getPathStart(this.m_currentPathIndex));if(e.isClosedPathInXYPlane(this.m_currentPathIndex))break;if(!t.equals(s))break;s=e.getXY(e.getPathEnd(this.m_currentPathIndex)-1),this.m_currentPathIndex++}}if(0===t&&this.m_currentPathIndex===this.m_polyline.getPathCount()){const e=this.m_polyline;return this.m_polyline=null,e}const s=new I({vd:this.m_polyline.getDescription()});s.addPath(this.m_polyline,t,!0);for(let i=t+1;i<this.m_currentPathIndex;i++)s.addSegmentsFromPath(this.m_polyline,i,0,e.getSegmentCountPath(i),!1);return this.m_currentPathIndex===this.m_polyline.getPathCount()&&(this.m_polyline=null),s}return null}getGeometryID(){return 0}getRank(){return 1}tock(){return!0}}class O extends f{constructor(e,t,s){super(),this.m_geometry=null,this.m_index=0,this.m_bufferer=e,this.m_geoms=t,this.m_index=0,this.m_bFilter=s}next(){if(null===this.m_geometry&&(this.m_index=0,this.m_geometry=this.m_geoms.next(),!this.m_geometry))return null;const e=this.m_geometry.getImpl();if(this.m_index<e.getPathCount()){const e=this.m_index;this.m_index++;return this.m_bufferer.bufferPolylinePath(this.m_geometry,e,this.m_bFilter)}return this.m_geometry=null,this.next()}getGeometryID(){return 0}getRank(){return 1}tock(){return!0}}class J extends f{constructor(e){super(),this.m_index=0,this.m_bufferer=e}next(){const e=this.m_bufferer.m_geometry;if(this.m_index<e.getPathCount()){const t=this.m_index,s=e.calculateRingArea2D(this.m_index);for(u(s>0),this.m_index++;this.m_index<e.getPathCount();){if(e.calculateRingArea2D(this.m_index)>0)break;this.m_index++}let i;return i=0===t&&this.m_index===e.getPathCount()?this.m_bufferer.bufferPolygonImpl(e,0,e.getPathCount()):this.m_bufferer.bufferPolygonImpl(e,t,this.m_index),i}return null}getGeometryID(){return 0}getRank(){return 1}tock(){return!0}}class U{constructor(e){this.m_geometry=null,this.m_bufferCommands=[],this.m_originalGeomType=s.enumUnknown,this.m_maxVertexInCompleteCircle=-1,this.m_circleTemplateSize=-1,this.m_oldCircleTemplateSize=0,this.m_spatialReference=null,this.m_tolerance=new _(0,0),this.m_smallTolerance=new _(0,0),this.m_filterTolerance=0,this.m_densifyDist=-1,this.m_distance=Number.NaN,this.m_absDistance=0,this.m_absDistanceReversed=0,this.m_dA=-1,this.m_miterLimit=4,this.m_joins=0,this.m_caps=0,this.m_bRoundBuffer=!0,this.m_bOutputLoops=!0,this.m_bFilter=!0,this.m_circleTemplate=[],this.m_leftStack=[],this.m_middleStack=[],this.m_helperLine1=new T,this.m_helperLine2=new T,this.m_helperArray=[],this.m_progressCounter=0,this.m_densificator=v.constructDefault(e),this.m_progressTracker=e}buffer(e,t,s,l,c,u,f,_){if(e||i("Geometry.Bufferer.Impl.Buffer"),f<0&&i("Geometry.Bufferer.Impl.Buffer"),n(e.getGeometryType())&&r("Unsupported geometry type."),e.isEmpty())return new S({vd:e.getDescription()});if(this.m_joins=l,this.m_caps=c,this.m_bRoundBuffer=!1,this.m_miterLimit=u,this.m_originalGeomType=e.getGeometryType(),m(this.m_originalGeomType)?this.m_bRoundBuffer=0===this.m_joins:o(this.m_originalGeomType)?this.m_bRoundBuffer=0===this.m_caps:a(this.m_originalGeomType)&&(this.m_bRoundBuffer=0===this.m_joins&&0===this.m_caps),this.m_bFilter=this.m_bRoundBuffer,this.m_geometry=R(e),this.m_geometry.isEmpty())return new S({vd:e.getDescription()});const d=new k;this.m_geometry.queryLooseEnvelope(d),t>0&&d.inflateCoords(t,t),this.m_tolerance=g(s,d,!0),this.m_smallTolerance=g(null,d,!0),_<=0&&(_=96),this.m_spatialReference=s,this.m_distance=t,this.m_absDistance=Math.abs(this.m_distance),this.m_absDistanceReversed=0!==this.m_absDistance?1/this.m_absDistance:0,Number.isNaN(f)||0===f?f=1e-5*this.m_absDistance:f>.5*this.m_absDistance&&(f=.5*this.m_absDistance),_<12&&(_=12);const p=Math.abs(t)*(1-Math.cos(Math.PI/_));if(p>f)f=p;else if(0!==t){const e=Math.PI/Math.acos(1-f/Math.abs(t));e<_-1&&(_=Math.trunc(e))<12&&(_=12,f=Math.abs(t)*(1-Math.cos(Math.PI/_)))}this.m_densifyDist=f,this.m_maxVertexInCompleteCircle=_,this.m_filterTolerance=this.m_bRoundBuffer?Math.min(this.m_smallTolerance.total(),.25*this.m_densifyDist):0,this.m_circleTemplateSize=this.calcN(),this.m_circleTemplateSize!==this.m_oldCircleTemplateSize&&(this.m_circleTemplate.length=0,this.m_oldCircleTemplateSize=this.m_circleTemplateSize),this.m_densifyDist>0&&h(this.m_geometry)&&(this.m_geometry=this.m_densificator.densifyEx(this.m_geometry,0,this.m_densifyDist,0,0!==this.m_joins,P()));const b=this.bufferImpl();return this.m_geometry=null,b}generateCircleTemplate(){if(this.m_circleTemplate.length)return;const e=this.m_circleTemplateSize,t=Math.trunc((e+3)/4),s=.5*Math.PI/t;this.m_dA=s,this.m_circleTemplate=y(x,4*t);const i=Math.cos(s),n=Math.sin(s),r=x.construct(0,1);for(let m=0;m<t;m++)this.m_circleTemplate[m+0*t].setCoords(r.y,-r.x),this.m_circleTemplate[m+1*t].setCoords(-r.x,-r.y),this.m_circleTemplate[m+2*t].setCoords(-r.y,r.x),this.m_circleTemplate[m+3*t].setCoords(r.x,r.y),r.rotateReverse(i,n)}bufferImpl(){const e=this.m_geometry.getGeometryType();if(l(e)){const e=new I({vd:this.m_geometry.getDescription()});return e.addSegment(this.m_geometry,!0),this.m_geometry=e,this.bufferImpl()}if(this.m_distance<=this.m_tolerance.total()){if(!m(e))return new S({vd:this.m_geometry.getDescription()});if(this.m_distance<0){const e=new k;if(this.m_geometry.queryEnvelope(e),e.width()<=2*this.m_absDistance||e.height()<=2*this.m_absDistance)return new S({vd:this.m_geometry.getDescription()})}}switch(this.m_geometry.getGeometryType()){case s.enumPoint:return this.bufferPoint();case s.enumMultiPoint:return this.bufferMultiPoint();case s.enumPolyline:return this.bufferPolyline();case s.enumPolygon:return this.bufferPolygon();case s.enumEnvelope:return this.bufferEnvelope();default:c("")}}bufferPolyline(){if(this.isDegenerateGeometry(this.m_geometry)){const e=new d;this.m_geometry.getPointByVal(0,e);const t=new k;return this.m_geometry.queryEnvelope(t),e.setXY(t.getCenter()),this.bufferDegeneratePath(e,!0)}const e=this.m_geometry,t=this.m_geometry.getDescription();this.m_geometry=null;const s=new N(e);let i,n;i=0===this.m_joins?(new F).executeMany(s,.25*this.m_densifyDist,!1,this.m_progressTracker):s,n=this.m_bRoundBuffer?(new j).executeMany(i,null,!0,this.m_progressTracker):i;const r=new O(this,n,this.m_bFilter),m=(new A).executeMany(r,this.m_spatialReference,this.m_progressTracker,2),o=(new X).executeMany(m,this.m_spatialReference,!1,this.m_progressTracker).next();return null!==o?o:new S({vd:t})}bufferPolygon(){if(0===this.m_distance)return this.m_geometry;this.generateCircleTemplate();const e=(new X).execute(this.m_geometry,null,!1,this.m_progressTracker);if(this.m_distance<0){if(this.m_geometry=e,this.m_geometry.isEmpty())return this.m_geometry;const t=this.m_geometry,s=this.bufferPolygonImpl(t,0,t.getPathCount());return(new X).execute(s,this.m_spatialReference,!1,this.m_progressTracker)}{if(this.m_geometry=e,this.isDegenerateGeometry(this.m_geometry)){const e=new d;this.m_geometry.getPointByVal(0,e);const t=new k;return this.m_geometry.queryEnvelope(t),e.setXY(t.getCenter()),this.bufferDegeneratePath(e,!0)}const t=new J(this),s=(new A).executeMany(t,this.m_spatialReference,this.m_progressTracker,2),i=(new X).executeMany(s,this.m_spatialReference,!1,this.m_progressTracker).next();return null!==i?i:new S({vd:this.m_geometry.getDescription()})}}bufferPolygonImpl(e,t,s){const i=e,n=i.getImpl();let r=new S({vd:e.getDescription()});for(let m=t;m<s;m++){if(n.getPathSize(m)<1)continue;const t=n.calculateRingArea2D(m),s=new k;if(n.queryPathEnvelope(m,s),this.m_distance>0)if(t>0)if(this.isDegeneratePath(n,m)){const e=new d;n.getPointByVal(n.getPathStart(m),e),e.setXY(s.getCenter()),r.add(this.bufferDegeneratePath(e,!0),!1)}else{const t=new I({vd:e.getDescription()}),s=t.getImpl();if(M(this.m_geometry,m)){const e=this.bufferConvexPath(i,m);r.add(e,!1)}else{this.bufferClosedPath(this.m_geometry,m,s,this.m_bRoundBuffer,1);const e=this.bufferCleanup(t);r.add(e,!1)}}else{if(s.width()+this.m_tolerance.total()<=2*this.m_absDistance||s.height()+this.m_tolerance.total()<=2*this.m_absDistance)continue;const t=new I({vd:e.getDescription()}),i=t.getImpl();if(this.bufferClosedPath(this.m_geometry,m,i,this.m_bRoundBuffer,1),!t.isEmpty()){const e=s,n=Math.max(1,this.m_absDistance),m=e.clone();m.inflateCoords(n,n),i.addEnvelope(m,!1);const o=this.bufferCleanup(t);r.reserve(r.getPointCount()+o.getPointCount()-4),ee(o,r,m,!0)}}else if(t>0){if(s.width()+this.m_tolerance.total()<=2*this.m_absDistance||s.height()+this.m_tolerance.total()<=2*this.m_absDistance)continue;const t=new I({vd:e.getDescription()}),i=t.getImpl();if(this.bufferClosedPath(this.m_geometry,m,i,this.m_bRoundBuffer,-1),!t.isEmpty()){const e=new k;i.queryLooseEnvelope(e);const s=Math.max(1,this.m_absDistance),n=e.clone();n.inflateCoords(s,s),i.addEnvelope(n,!1);ee(this.bufferCleanup(t),r,n,!0)}}else{const t=new I({vd:e.getDescription()}),s=t.getImpl();this.bufferClosedPath(this.m_geometry,m,s,this.m_bRoundBuffer,-1);const i=this.bufferCleanup(t);for(let e=0,n=i.getPathCount();e<n;e++)r.addPath(i,e,!0)}}if(this.m_distance>0){if(r.getPathCount()>1){return this.bufferCleanup(r)}return H(r)}{const e=new k;if(r.queryLooseEnvelope(e),r.isEmpty())return H(r);{const t=Math.max(1,this.m_absDistance),s=e.clone();s.inflateCoords(t,t),r.addEnvelope(s,!1);const i=this.bufferCleanup(r);r=new S;const n=new S({vd:i.getDescription()});return ee(i,n,s,!1),H(n)}}}bufferPoint(){return this.bufferPointImpl(this.m_geometry)}bufferPointImpl(e){const t=new S({vd:e.getDescription()});return 0===this.m_caps?(this.addCircle(t.getImpl(),e),this.setStrongSimple(t)):2===this.m_caps?(this.addSquare(t.getImpl(),e),this.setStrongSimple(t)):t}bufferDegeneratePath(e,t){const s=new S({vd:e.getDescription()});return t&&0===this.m_joins||!t&&0===this.m_caps?(this.addCircle(s.getImpl(),e),this.setStrongSimple(s)):t||2!==this.m_caps?s:(this.addSquare(s.getImpl(),e),this.setStrongSimple(s))}bufferMultiPoint(){const e=new G(this,this.m_geometry,this.m_distance,this.m_spatialReference,this.m_joins,this.m_caps,this.m_miterLimit,this.m_densifyDist,this.m_maxVertexInCompleteCircle,this.m_progressTracker);return(new A).executeMany(e,this.m_spatialReference,this.m_progressTracker,2).next()}bufferEnvelope(){let e=new S({vd:this.m_geometry.getDescription()});if(this.m_distance<=0){if(0===this.m_distance)e.addEnvelope(this.m_geometry,!1),K(this.m_geometry,this.m_tolerance.total())&&(e=this.setStrongSimple(e));else{const t=new p;this.m_geometry.queryEnvelope(t),t.inflateCoords(this.m_distance,this.m_distance),e.addEnvelope(t,!1),K(t,this.m_tolerance.total())&&(e=this.setStrongSimple(e))}return e}if(1===this.m_joins){const t=new p({copy:this.m_geometry});return t.inflateCoords(this.m_absDistance,this.m_absDistance),e.addEnvelope(t,!1),e}const t=this.m_geometry.clone();if(0===t.width()||0===t.height()){if(0===t.width()&&0===t.height()){const e=new d({vd:this.m_geometry.getDescription()});return t.queryCornerByVal(0,e),this.m_geometry=e,this.bufferImpl()}const e=new I({vd:this.m_geometry.getDescription()}),s=new d;return t.queryCornerByVal(0,s),e.startPathPoint(s),t.queryCornerByVal(2,s),e.lineToPoint(s),this.m_geometry=e,this.bufferImpl()}return e.addEnvelope(this.m_geometry,!1),this.m_geometry=e,this.bufferConvexPath(e,0)}bufferConvexPath(e,t){this.generateCircleTemplate();const s=e.hasAttribute(10),i=new S({vd:e.getDescription()}),n=i.getImpl();i.reserve((this.m_circleTemplate.length/10+4)*e.getPathSize(t));const r=new x,m=new x,o=new x,a=new x(0,0),h=new x,l=new x,u=e.getImpl(),f=e.getPathSize(t),_=e.getPathStart(t);for(let g=0,d=e.getPathSize(t);g<d;g++){const e=u.getXY(_+g),t=u.getXY(_+(g+1)%f),i=u.getXY(_+(g+2)%f);h.setSub(t,e),0===h.length()&&c("");const d=s&&!!(1&u.getAttributeAsInt(10,(g+1)%f,0));h.normalize();const p=h.clone();h.leftPerpendicularThis(),h.scale(this.m_absDistance),r.setAdd(h,e),m.setAdd(h,t),0===g?n.startPath(r):n.lineTo(r),n.lineTo(m),l.setSub(i,t),0===l.length()&&c(""),l.normalize();const b=l.clone();l.leftPerpendicularThis(),l.scale(this.m_absDistance),o.setAdd(l,t);let P=L.enumArc;const y=d?0:this.m_joins;if(2===y)P=L.enumBevel;else if(1===y){const e=-p.crossProduct(b);a.setSub(p,b),a.scale(this.m_absDistance/e),a.length()<this.m_miterLimit*this.m_absDistance?(a.addThis(t),P=L.enumMiter):P=L.enumBevel}else a.assign(t);this.addJoin(P,n,a,m,o,!1,!1)}return H(i)}bufferPolylinePath(e,t,s){this.generateCircleTemplate();const i=e,n=i.getImpl();if(n.getPathSize(t)<1)return null;let r;if(r=this.m_bRoundBuffer?n.isClosedPathInXYPlane(t):n.isClosedPath(t),this.isDegeneratePath(n,t)&&this.m_distance>0){const e=new d;n.getPointByVal(n.getPathStart(t),e);const s=new k;return n.queryPathEnvelope(t,s),e.setXY(s.getCenter()),this.bufferDegeneratePath(e,r)}const m=new I({vd:e.getDescription()});m.reserve((Math.trunc(this.m_circleTemplate.length/10)+4)*n.getPathSize(t));const o=m.getImpl();return r?2!==this.bufferClosedPath(i,t,o,s,1)&&this.bufferClosedPath(i,t,o,s,-1):this.bufferOpenPath(i,t,o,s),this.bufferCleanup(m)}progress_(){}bufferCleanup(e,t=!1){const s=t?this.m_tolerance:this.m_smallTolerance;return Y(e,s,!0,!t,-1,this.m_progressTracker,0,!1)}calcN(){const e=4;if(0===this.m_densifyDist)return this.m_maxVertexInCompleteCircle;const t=1-this.m_densifyDist*Math.abs(this.m_absDistanceReversed);let s=e;return s=t<-1?e:2*Math.PI/Math.acos(t)+.5,s<e?s=e:s>this.m_maxVertexInCompleteCircle&&(s=this.m_maxVertexInCompleteCircle),Math.trunc(s)}addJoin(e,t,s,i,n,r,m){if(this.generateCircleTemplate(),r&&(t.startPath(i),r=!1),e===L.enumBevel)return void(m&&t.lineTo(n));if(e===L.enumMiter){const e=s.clone();return t.lineTo(e),void(m&&t.lineTo(n))}const o=new x;o.setSub(i,s),o.scale(this.m_absDistanceReversed);const a=new x;a.setSub(n,s),a.scale(this.m_absDistanceReversed);let h=Math.atan2(o.y,o.x)/this.m_dA;h<0&&(h=this.m_circleTemplate.length+h),h=this.m_circleTemplate.length-h;let l=Math.atan2(a.y,a.x)/this.m_dA;l<0&&(l=this.m_circleTemplate.length+l),l=this.m_circleTemplate.length-l,l<h&&(l+=this.m_circleTemplate.length);let c=Math.trunc(l),u=Math.ceil(h),f=this.m_circleTemplate[u%this.m_circleTemplate.length].clone();f.scaleAddThis(this.m_absDistance,s);const _=10*this.m_tolerance.total();f.sub(i).length()<_&&(u+=1),f=this.m_circleTemplate[c%this.m_circleTemplate.length].clone(),f.scaleAddThis(this.m_absDistance,s),f.sub(n).length()<_&&(c-=1);let g=c-u;g++;for(let d=0,p=u%this.m_circleTemplate.length;d<g;d++,p=(p+1)%this.m_circleTemplate.length)f=this.m_circleTemplate[p].clone(),f.scaleAddThis(this.m_absDistance,s),t.lineTo(f),this.progress_();m&&t.lineTo(n)}bufferClosedPath(e,t,s,i,n){const r=new E,m=r.addPathFromMultiPath(e,t,!0);return this.bufferClosedPathImpl(r,m,s,i,n)}bufferClosedPathImpl(e,t,s,i,n){const r=e.getFirstVertex(e.getFirstPath(t)),m=new d;e.queryPoint(r,m),e.filterClosePoints(this.m_filterTolerance,!1,!1,!1,-1);if(e.getPointCount(t)<2)return n<0?0:(this.m_bRoundBuffer&&this.addCircle(s,m),2);u(e.getFirstPath(t)!==V),u(e.getFirstVertex(e.getFirstPath(t))!==V);const o=e.getXY(e.getFirstVertex(e.getFirstPath(t))),a=new B;if(a.setShift(o.negate()),e.applyTransformation(a),i){const i=$(e,t,n,!0,this.m_absDistance,this.m_filterTolerance,this.m_densifyDist);if(u(1===i),e.getPointCount(t)<2)return n<0?0:(this.addCircle(s,m),2)}const h=0!==this.m_joins&&e.getVertexDescription().hasAttribute(10);this.m_bufferCommands.length=0;const l=e.getFirstPath(t);let c=e.getFirstVertex(l),f=1===n?e.getPrevVertex(c):e.getNextVertex(c),_=1===n?e.getNextVertex(c):e.getPrevVertex(c),g=!0;const p=new x,b=new x,P=new x,y=new x,C=new x,D=new x,w=new x,T=new x,v=this.m_absDistance,S=e.getPathSize(l),I=new x(0,0);for(let u=0;u<S;u++){b.assign(e.getXY(_)),g&&(p.assign(e.getXY(c)),P.assign(e.getXY(f)),D.setSub(p,P),D.normalize(),T.leftPerpendicularOther(D),T.scale(v),y.setAdd(T,p));const t=h&&!!(1&e.getAttributeAsDbl(10,c,0));C.setSub(b,p),C.normalize(),w.leftPerpendicularOther(C),w.scale(v);const s=new x;s.setAdd(p,w);const i=D.crossProduct(C),r=D.dotProduct(C);if(i<0||r<0&&i<Math.abs(r)*Number.EPSILON*8){let e=!1;const n=t?0:this.m_joins;if(1===n){const t=-i;I.setSub(D,C),I.scale(this.m_absDistance/t),I.length()<this.m_miterLimit*this.m_absDistance&&(I.addThis(p),e=!0),this.m_bufferCommands.push(q(y,s,I,e?L.enumMiter:L.enumBevel,this.m_bufferCommands.length+1))}else this.m_bufferCommands.push(q(y,s,p,0===n?L.enumArc:L.enumBevel,this.m_bufferCommands.length+1))}else y.equals(s)||(this.m_bufferCommands.push(z(y,p,this.m_bufferCommands.length+1)),this.m_bufferCommands.push(z(p,s,this.m_bufferCommands.length+1)));const m=new x;m.setAdd(b,w),this.m_bufferCommands.push(q(s,m,p,L.enumLine,this.m_bufferCommands.length+1)),y.setCoordsPoint2D(m),T.setCoordsPoint2D(w),P.setCoordsPoint2D(p),p.setCoordsPoint2D(b),D.setCoordsPoint2D(C),f=c,c=_,g=!1,_=1===n?e.getNextVertex(c):e.getPrevVertex(c)}return this.m_bufferCommands.at(-1).m_next=0,this.processBufferCommands(s),a.setShift(o),s.applyTransformationToPath(a,s.getPathCount()-1),1}bufferOpenPath(e,t,s,i){if(this.m_bRoundBuffer){const n=new I({vd:e.getDescription()});return n.addPath(e,t,!1),n.addSegmentsFromPath(e,t,0,e.getSegmentCountPath(t),!1),this.bufferClosedPath(n,0,s,i,1)}let n=0;const r=new I({vd:e.getDescription()}),m=new x(0,0);{const i=new E,o=i.addPathFromMultiPath(e,t,!1),a=i.getFirstVertex(i.getFirstPath(o)),h=new d;i.queryPoint(a,h),m.assign(h.getXY()),i.filterClosePoints(0,!1,!1,!1,-1);if(i.getPointCount(o)<2)return this.m_bRoundBuffer&&this.addCircle(s,h),2;const l=i.getGeometry(i.getFirstGeometry());r.addPath(l,0,!1),n=r.getPointCount()-1,r.addSegmentsFromPath(l,0,0,l.getSegmentCountPath(0)-1,!1)}const o=new E,a=o.addPathFromMultiPath(r,0,!0);u(o.getFirstPath(a)!==V),u(o.getFirstVertex(o.getFirstPath(a))!==V);const h=new B;h.setShift(m.negate()),o.applyTransformation(h),this.m_bufferCommands.length=0;const l=o.getFirstPath(a),c=0!==this.m_joins&&o.getVertexDescription().hasAttribute(10);let f=o.getFirstVertex(l),_=o.getPrevVertex(f),g=o.getNextVertex(f),p=!0;const b=new x,P=new x,y=new x,C=new x,D=new x,w=new x,T=new x,v=new x,S=this.m_absDistance,M=o.getPathSize(l),k=new x(0,0);for(let u=0;u<M;u++){let e=!1;0!==u&&u!==n||(e=!0),P.assign(o.getXY(g)),p&&(b.assign(o.getXY(f)),y.assign(o.getXY(_)),w.setSub(b,y),w.normalize(),v.leftPerpendicularOther(w),v.scale(S),C.setAdd(v,b));const t=c&&!!(1&o.getAttributeAsDbl(10,f,0));D.setSub(P,b),D.normalize(),T.leftPerpendicularOther(D),T.scale(S);const s=new x;s.setAdd(b,T);const i=w.crossProduct(D),r=w.dotProduct(D);if(i<0||r<0&&i<Math.abs(r)*Number.EPSILON*8)if(e)if(0===this.m_caps)this.m_bufferCommands.push(q(C,s,b,L.enumArc,this.m_bufferCommands.length+1));else if(1===this.m_caps)this.m_bufferCommands.push(q(C,s,b,L.enumLine,this.m_bufferCommands.length+1));else{const e=D.mul(this.m_absDistance).negate(),t=e.clone();e.addThis(C),t.addThis(s),this.m_bufferCommands.push(q(C,e,b,L.enumLine,this.m_bufferCommands.length+1)),this.m_bufferCommands.push(q(e,t,b,L.enumLine,this.m_bufferCommands.length+1)),this.m_bufferCommands.push(q(t,s,b,L.enumLine,this.m_bufferCommands.length+1))}else{let e=!1;const n=t?0:this.m_joins;if(1===n){const t=-i;k.setSub(w,D),k.scale(this.m_absDistance/t),k.length()<this.m_miterLimit*this.m_absDistance&&(k.addThis(b),e=!0),this.m_bufferCommands.push(q(C,s,k,e?L.enumMiter:L.enumBevel,this.m_bufferCommands.length+1))}else this.m_bufferCommands.push(q(C,s,b,0===n?L.enumArc:L.enumBevel,this.m_bufferCommands.length+1))}else C.equals(s)||(this.m_bufferCommands.push(z(C,b,this.m_bufferCommands.length+1)),this.m_bufferCommands.push(z(b,s,this.m_bufferCommands.length+1)));const m=new x;m.setAdd(P,T),this.m_bufferCommands.push(q(s,m,b,L.enumLine,this.m_bufferCommands.length+1)),C.setCoordsPoint2D(m),v.setCoordsPoint2D(T),y.setCoordsPoint2D(b),b.setCoordsPoint2D(P),w.setCoordsPoint2D(D),_=f,f=g,p=!1,g=o.getNextVertex(f)}return this.m_bufferCommands.at(-1).m_next=0,this.processBufferCommands(s),h.setShift(m),s.applyTransformationToPath(h,s.getPathCount()-1),1}processBufferCommands(e){const t=this.cleanupBufferCommands();let s=!0,i=t+1;for(let n=t;i!==t;n=i){const t=this.m_bufferCommands[n];i=-1!==t.m_next?t.m_next:(n+1)%this.m_bufferCommands.length,t.m_type&&(s&&(e.startPath(t.m_from),s=!1),t.m_type&L.enumJoinMask?this.addJoin(t.m_type,e,t.m_center,t.m_from,t.m_to,!1,!0):e.lineTo(t.m_to))}}cleanupBufferCommands(){this.m_helperArray=y(x,9);let e=0;for(let s=0,i=this.m_bufferCommands.length;s<i;){const t=this.m_bufferCommands[s];if(t.m_type&L.enumConnectionMask){e=s;break}s=t.m_next}let t=e+1;for(let s=e;t!==e;s=t){const e=this.m_bufferCommands[s];t=e.m_next;let i=1,n=null;for(;t!==s&&(n=this.m_bufferCommands[t],!(n.m_type&L.enumConnectionMask));)t=n.m_next,i++;if(1!==i&&(e.m_type&n.m_type)===L.enumLine){this.m_helperLine1.setStartXY(e.m_from),this.m_helperLine1.setEndXY(e.m_to),this.m_helperLine2.setStartXY(n.m_from),this.m_helperLine2.setEndXY(n.m_to);1===this.m_helperLine1.intersect(this.m_helperLine2,this.m_helperArray,null,null,this.m_smallTolerance.total())&&(e.m_to.assign(this.m_helperArray[0]),n.m_from.assign(this.m_helperArray[0]),e.m_next=t)}}return e}isDegeneratePath(e,t){if(1===e.getPathSize(t))return!0;if(0===this.m_joins&&0===this.m_caps){const s=new k;if(e.queryPathEnvelope(t,s),Math.max(s.width(),s.height())<.5*this.m_densifyDist)return!0}return!1}isDegenerateGeometry(e){if(0===this.m_joins&&0===this.m_caps){const t=new k;if(e.queryEnvelope(t),Math.max(t.width(),t.height())<.5*this.m_densifyDist)return!0}return!1}addCircle(e,t){const s=t.getXY();if(0!==this.m_circleTemplate.length){let t=this.m_circleTemplate[0].clone();t.scaleAddThis(this.m_absDistance,s),e.startPath(t);for(let i=1,n=this.m_circleTemplate.length;i<n;i++)t=this.m_circleTemplate[i].clone(),t.scaleAddThis(this.m_absDistance,s),e.lineTo(t);return}const i=this.m_circleTemplateSize,n=Math.trunc((i+3)/4),r=.5*Math.PI/n;e.reserve(4*n);const m=Math.cos(r),o=Math.sin(r);for(let a=3;a>=0;a--){const t=x.construct(0,this.m_absDistance);switch(a){case 0:for(let i=0;i<n;i++)e.lineToCoords(t.x+s.x,t.y+s.y),t.rotateReverse(m,o);break;case 1:for(let i=0;i<n;i++)e.lineToCoords(-t.y+s.x,t.x+s.y),t.rotateReverse(m,o);break;case 2:for(let i=0;i<n;i++)e.lineToCoords(-t.x+s.x,-t.y+s.y),t.rotateReverse(m,o);break;default:e.startPathCoords(t.y+s.x,-t.x+s.y);for(let i=1;i<n;i++)t.rotateReverse(m,o),e.lineToCoords(t.y+s.x,-t.x+s.y)}this.progress_()}}addSquare(e,t){const s=new p({vd:t.getDescription()});s.setCoords(t.getX(),t.getY(),t.getX(),t.getY()),s.inflateCoords(this.m_absDistance,this.m_absDistance),e.addEnvelope(s,!1)}setStrongSimple(e){return e.getImpl().setIsSimple(4,this.m_tolerance.total()),e.getImpl().updateOGCFlagsProtected(),e}}function H(e){return b(e,0),e}function K(e,t){return!!e.isEmpty()||Math.min(e.width(),e.height())>t}function Q(e,t,s,i,n,r,m,o){const a=e.getXY(s),h=e.getXY(i);if(a.equals(h))return-1;const l=.25*m,c=.25*m,f=new x;f.setSub(h,a);const _=f.length(),g=_*_*.25,d=r*r-g;if(d<=g)return-1;const p=Math.sqrt(d);f.normalize();const b=f.clone();b.rightPerpendicularThis();const P=g/p,y=P<=c,C=x.lerp(h,a,.5),T=b.clone(),v=P-l;T.scaleAddThis(Math.max(0,v),C);b.negate().scaleAddThis(p,C);const S=3.61*w(r-c),I=T.sub(a),M=T.sub(h);let E=!1,V=0;const k=D(64,0);u(o===k.length);{for(let o=e.getPrevVertexEx(i,n);o!==s;){if(1===e.getUserIndex(o,t))return-1;if(!e.getXY(o).equals(h))break;{const t=e.getPrevVertexEx(o,n);e.removeVertex(o,!1),o=t}}const r=new x,m=a.clone();k[V++]=1;for(let o=e.getNextVertexEx(s,n);o!==i;){if(1===e.getUserIndex(o,t))return-1;const s=e.getXY(o);if(s.equals(m)){const t=e.getNextVertexEx(o,n);e.removeVertex(o,!1),o=t;continue}k[V++]=0;const i=new x;if(i.setSub(s,a),i.dotProduct(b)<0)return 0;(x.sqrDistance(s,a)>S||x.sqrDistance(s,h)>S)&&(E=!0);let l=0;s.sub(a).crossProduct(I)>=0&&(l=1);if(s.sub(h).crossProduct(M)<=0&&(l|=2),0===l)return 0;k[V-1]=l,r.assign(m),m.assign(s),o=e.getNextVertexEx(o,n)}if(1===V)return 0;u(V<k.length),k[V++]=2}let B=!0;for(let u=1,x=0;u<V;u++)if(k[u]!==k[u-1]&&(x++,B=x<3&&(1===x&&3===k[u]||2===x&&2===k[u]),!B))return 0;if(V>2&&B&&(3===V||!E)){let t=0,r=e.getNextVertexEx(s,n);for(y||(e.setXY(r,T),r=e.getNextVertexEx(r,n));r!==i;){const s=e.getNextVertexEx(r,n);e.removeVertex(r,!1),r=s,++t}return t}if(u(3!==V),E&&V>3)return 0;const R=a.clone();let A=s;const X=a.clone();let Y=1,j=-1,F=A,L=0;for(V=1;F!==i;){F=e.getNextVertexEx(F,n);const t=k[V++];if(0===t){if(F===i)break;continue}const s=e.getXY(F);if(-1!==j){if(3&(j&Y&t)){e.removeVertex(A,!0),L++,A=F,X.setCoordsPoint2D(s),Y=t;continue}if(3===Y&&0!==j&&0!==t){if(X.setCoordsPoint2D(T),y||X.equals(R)){e.removeVertex(A,!0),L++,A=F,X.setCoordsPoint2D(s),Y=t;continue}e.setXY(A,X)}}j=Y,R.setCoordsPoint2D(X),A=F,Y=t,X.setCoordsPoint2D(s)}return L}function W(e,t,s,i){let n=-1;const r=new x,m=new x,o=new x;for(let a=0,h=e.getPathSize(i),l=e.getFirstVertex(i);a<h;++a){-1===n&&(e.queryXY(l,m),n=e.getPrevVertex(l),-1!==n&&(e.queryXY(n,r),o.setSub(m,r),o.normalize()));const s=e.getNextVertex(l);if(-1===s)break;const i=e.getXY(s),a=i.sub(m);if(a.normalize(),-1!==n){a.dotProduct(o)<-.99&&Math.abs(a.crossProduct(o))<1e-7&&e.setUserIndex(l,t,1)}n=l,l=s,r.assign(m),m.assign(i),o.assign(a)}}function Z(s,i,n,r,m,o,a){const h={stack:[],error:void 0,hasError:!1};try{const t=s.getFirstPath(i),r=s.createUserIndex();e(h,C((()=>{s.removeUserIndex(r)}),!1),!1),W(s,r,i,t);for(let e=0;e<100;++e){if(0===s.getPathSize(t))return 1;let e=s.getFirstVertex(t),i=s.getPathSize(t);if(i<3)return 1;s.isClosedPath(t)||(i-=1);const o=64;let h=0,l=!1;for(let t=0;t<i&&e!==V;t++){let c=0,u=e;for(let h=1,l=Math.min(o,i-t);h<l;h++)if(u=s.getNextVertexEx(u,n),h>1){const t=Q(s,r,e,u,n,m,a,o);if(-1===t)break;c+=t,i-=t}if(h+=c,l=c>0,l){const t=s.getPrevVertexEx(e,n);if(-1!==t){e=t,i++;continue}}e=s.getNextVertexEx(e,n)}if(0===h)break}return s.filterClosePoints(o,!1,!1,!1,-1),1}catch(l){h.error=l,h.hasError=!0}finally{t(h)}}function $(e,t,s,i,n,r,m){return Z(e,t,s,i,n,r,m)}function ee(e,t,s,i){for(let n=0,r=e.getPathCount();n<r;n++){const r=e.getXY(e.getPathStart(n));r.x!==s.xmin&&r.x!==s.xmax&&t.addPath(e,n,i)}}export{U as B};