import{rotatePoints as e,rotateLines as t}from"../geometry.js";export function polygonHachureLines(n,h){const o=[0,0],a=Math.round(h.hachureAngle+90);a&&e(n,o,a);const r=function straightHachureLines(e,t){const n=[...e];n[0].join(",")!==n[n.length-1].join(",")&&n.push([n[0][0],n[0][1]]);const h=[];if(n&&n.length>2){let e=t.hachureGap;e<0&&(e=4*t.strokeWidth),e=Math.max(e,.1);const o=[];for(let e=0;e<n.length-1;e++){const t=n[e],h=n[e+1];if(t[1]!==h[1]){const e=Math.min(t[1],h[1]);o.push({ymin:e,ymax:Math.max(t[1],h[1]),x:e===t[1]?t[0]:h[0],islope:(h[0]-t[0])/(h[1]-t[1])})}}if(o.sort(((e,t)=>e.ymin<t.ymin?-1:e.ymin>t.ymin?1:e.x<t.x?-1:e.x>t.x?1:e.ymax===t.ymax?0:(e.ymax-t.ymax)/Math.abs(e.ymax-t.ymax))),!o.length)return h;let a=[],r=o[0].ymin;for(;a.length||o.length;){if(o.length){let e=-1;for(let t=0;t<o.length&&!(o[t].ymin>r);t++)e=t;o.splice(0,e+1).forEach((e=>{a.push({s:r,edge:e})}))}if(a=a.filter((e=>!(e.edge.ymax<=r))),a.sort(((e,t)=>e.edge.x===t.edge.x?0:(e.edge.x-t.edge.x)/Math.abs(e.edge.x-t.edge.x))),a.length>1)for(let e=0;e<a.length;e+=2){const t=e+1;if(t>=a.length)break;const n=a[e].edge,o=a[t].edge;h.push([[Math.round(n.x),r],[Math.round(o.x),r]])}r+=e,a.forEach((t=>{t.edge.x=t.edge.x+e*t.edge.islope}))}}return h}(n,h);return a&&(e(n,o,-a),t(r,o,-a)),r}