12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import t from"../../geometry/Point.js";import{segmentIntersects as n}from"../../geometry/support/intersectsBase.js";function e(t,n,e){return Math.sqrt((t[0]-n[0])**2+(t[1]-n[1])**2+(void 0!==t[2]&&void 0!==n[2]?(t[2]*e-n[2]*e)**2:0))}const r=[];for(const v of[[9002,56146130,6131,6132,8050,8051,8228],[9003,5702,6358,6359,6360,8052,8053],[9095,5754]]){const t=v[0];for(let n=1;n<v.length;n++)r[v[n]]=t}const o=[];function s(t){return t.vcsWkid&&void 0!==r[t.vcsWkid]?o[r[t.vcsWkid]]:t.latestVcsWkid&&void 0!==r[t.latestVcsWkid]?o[r[t.latestVcsWkid]]:1}function c(t,n,e){const r={x:0,y:0};n&&(r.z=0),e&&(r.m=0);let o=0,s=t[0];for(let c=0;c<t.length;c++){const a=t[c];if(!1===f(a,s)){const t=h(s,a,n),c=i(s,a,n,e);c.x*=t,c.y*=t,r.x+=c.x,r.y+=c.y,n&&(c.z*=t,r.z+=c.z),e&&(c.m*=t,r.m+=c.m),o+=t,s=a}}return o>0?(r.x/=o,r.y/=o,n&&(r.z/=o),e&&(r.m/=o)):(r.x=t[0][0],r.y=t[0][1],n&&(r.z=t[0][2]),e&&n?r.m=t[0][3]:e&&(r.m=t[0][2])),r}function i(t,n,e,r){const o={x:(t[0]+n[0])/2,y:(t[1]+n[1])/2};return e&&(o.z=(t[2]+n[2])/2),e&&r?o.m=(t[3]+n[3])/2:r&&(o.m=(t[2]+n[2])/2),o}function a(t,n){if(t.length<=1)return 0;let e=0;for(let r=1;r<t.length;r++)e+=h(t[r-1],t[r],n);return e}function h(t,n,e){const r=n[0]-t[0],o=n[1]-t[1];if(e){const t=n[2]-n[2];return Math.sqrt(r*r+o*o+t*t)}return Math.sqrt(r*r+o*o)}function f(t,n){if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;return!0}function l(n){const e={x:0,y:0,spatialReference:n.spatialReference.toJSON()},r={x:0,y:0,spatialReference:n.spatialReference.toJSON()};let o=0,s=0;for(let t=0;t<n.paths.length;t++){if(0===n.paths[t].length)continue;const i=a(n.paths[t],!0===n.hasZ);if(0===i){const r=c(n.paths[t],!0===n.hasZ,!0===n.hasM);e.x+=r.x,e.y+=r.y,!0===n.hasZ&&(e.z+=r.z),!0===n.hasM&&(e.m+=r.m),++o}else{const e=c(n.paths[t],!0===n.hasZ,!0===n.hasM);r.x+=e.x*i,r.y+=e.y*i,!0===n.hasZ&&(r.z+=e.z*i),!0===n.hasM&&(r.m+=e.m*i),s+=i}}return s>0?(r.x/=s,r.y/=s,!0===n.hasZ&&(r.z/=s),!0===n.hasM&&(r.m/=s),new t(r)):o>0?(e.x/=o,e.y/=o,!0===n.hasZ&&(r.z/=o),!0===n.hasM&&(e.m/=o),new t(e)):null}function u(n){if(0===n.points.length)return null;let e=0,r=0,o=0,s=0;for(let t=0;t<n.points.length;t++){const c=n.getPoint(t);!0===c.hasZ&&(o+=c.z),!0===c.hasM&&(s+=c.m),e+=c.x,r+=c.y,s+=c.m}const c={x:e/n.points.length,y:r/n.points.length,spatialReference:null};return c.spatialReference=n.spatialReference.toJSON(),!0===n.hasZ&&(c.z=o/n.points.length),!0===n.hasM&&(c.m=s/n.points.length),new t(c)}function y(t,n){return t.x*n.x+t.y*n.y}function x(t,n){return t.x*n.y-n.x*t.y}function m(t,n,e=0){for(;t<e;)t+=n;const r=e+n;for(;t>=r;)t-=n;return t}function g(t,n){return Math.atan2(n.y-t.y,n.x-t.x)}function p(t,n){return m(g(t,n),2*Math.PI)*(180/Math.PI)}function M(t,n){return m(Math.PI/2-g(t,n),2*Math.PI)*(180/Math.PI)}function z(t,n,e){const r={x:t.x-n.x,y:t.y-n.y},o={x:e.x-n.x,y:e.y-n.y};return Math.atan2(x(r,o),y(r,o))}function P(t,n,e){return m(z(t,n,e),2*Math.PI)*(180/Math.PI)}function d(t,n,e){return m(-1*z(t,n,e),2*Math.PI)*(180/Math.PI)}o[9002]=.3048,o[9003]=.3048006096012192,o[9095]=.3048007491;const I=[0,0];function Z(t){for(let e=0;e<t.length;e++){const r=t[e];for(let s=0;s<r.length-1;s++){const o=r[s],c=r[s+1];for(let r=e+1;r<t.length;r++)for(let e=0;e<t[r].length-1;e++){const s=t[r][e],i=t[r][e+1];if(n(o,c,s,i,I)&&!(I[0]===o[0]&&I[1]===o[1]||I[0]===s[0]&&I[1]===s[1]||I[0]===c[0]&&I[1]===c[1]||I[0]===i[0]&&I[1]===i[1]))return!0}}const o=r.length;if(!(o<3))for(let t=0;t<=o-2;t++){const e=r[t],s=r[t+1];for(let c=t+2;c<=o-2;c++){const t=r[c],o=r[c+1];if(n(e,s,t,o,I)&&!(I[0]===e[0]&&I[1]===e[1]||I[0]===t[0]&&I[1]===t[1]||I[0]===s[0]&&I[1]===s[1]||I[0]===o[0]&&I[1]===o[1]))return!0}}}return!1}export{p as angle2D,P as angleBetween2D,z as angleBetweenRad,g as angleRad,M as bearing2D,d as bearingBetween2D,u as centroidMultiPoint,l as centroidPolyline,s as getMetersPerVerticalUnitForSR,Z as pathsSelfIntersecting,e as segmentLength3d};
|