/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{equals as t}from"../../core/libs/gl-matrix-2/math/vec2.js";import{clone as n,create as r}from"../../core/libs/gl-matrix-2/factories/vec2f64.js";function e(t,n){const r=[],e=[];return c(r,t,n,0),c(e,r,n,1),c(r,e,n,2),c(e,r,n,3),e}function c(t,r,e,c){const f=s(e,c);if(t.length=0,r.length){1===f(i,r[0],r[0])&&o(t,r[0]);for(let e=0;e<r.length;e++){const c=r[e===r.length-1?0:e+1];switch(f(i,r[e],c)){case 1:o(t,c);break;case 3:o(t,n(i));break;case 2:o(t,n(i)),o(t,c)}}}}function o(n,r){0!==n.length&&t(n.at(-1),r)||n.push(r)}function s(t,n){const r=0===n||2===n?0:1,e=t[n],c=0===n||1===n?1:-1,o=0===r?1:0;return(t,n,s)=>{if(n[r]<e&&s[r]<e)return 1===c?0:1;if(n[r]>e&&s[r]>e)return 1===c?1:0;const i=(s[o]-n[o])/(s[r]-n[r]),f=n[o]+i*(e-n[r]);return t[r]=e,t[o]=f,(n[r]<e?1:-1)*c>0?2:3}}const i=r();export{e as clipPolygonToExtent};
