import{lineLength as t}from"../geometry.js";import{polygonHachureLines as s}from"./scan-line-hachure.js";export class ZigZagLineFiller{constructor(t){this.helper=t}fillPolygon(t,e){const h=e.hachureGap<0?4*e.strokeWidth:e.hachureGap,a=e.zigzagOffset<0?h:e.zigzagOffset;e=Object.assign({},e,{hachureGap:h+a});const o=s(t,e);return{type:"fillSketch",ops:this.zigzagLines(o,a,e)}}zigzagLines(s,e,h){const a=[];return s.forEach((s=>{const o=t(s),i=Math.round(o/(2*e));let r=s[0],n=s[1];r[0]>n[0]&&(r=s[1],n=s[0]);const c=Math.atan((n[1]-r[1])/(n[0]-r[0]));for(let t=0;t<i;t++){const s=2*t*e,o=2*(t+1)*e,i=Math.sqrt(2*Math.pow(e,2)),n=[r[0]+s*Math.cos(c),r[1]+s*Math.sin(c)],l=[r[0]+o*Math.cos(c),r[1]+o*Math.sin(c)],p=[n[0]+i*Math.cos(c+Math.PI/4),n[1]+i*Math.sin(c+Math.PI/4)];a.push(...this.helper.doubleLineOps(n[0],n[1],p[0],p[1],h),...this.helper.doubleLineOps(p[0],p[1],l[0],l[1],h))}})),a}}