animate/canvas/rough/fillers/zigzag_line.rs
1use super::RenderHelper;
2use crate::{
3 canvas::rough::{geometry::line_length, Line, Op, OpSet, RoughOptions},
4 Point,
5};
6
7//implements PatternFiller
8pub struct ZigZagLineFiller<H: RenderHelper> {
9 helper: H
10}
11
12impl<H: RenderHelper> ZigZagLineFiller<H> {
13 pub fn new(helper: H) -> Self {
14 Self { helper }
15 }
16
17 fn fill_polygon(points: Vec<Point<f64>>, options: &RoughOptions) -> OpSet {
18 // let gap = o.hachureGap < 0 ? (o.strokeWidth * 4) : o.hachureGap;
19 // let zo = o.zigzagOffset < 0 ? gap : o.zigzagOffset;
20 // o = Object.assign({}, o, { hachureGap: gap + zo });
21 // let lines = polygonHachureLines(points, o);
22 // return { type: 'fillSketch', ops: self.zigzagLines(lines, zo, o) };
23 unimplemented!()
24 }
25
26 fn zigzag_lines(lines: Vec<Line<f64>>, zo: f64, options: &RoughOptions) -> Vec<Op> {
27 // let ops: Op[] = [];
28 // lines.forEach((line) => {
29 // let length = line_length(line);
30 // let count = Math.round(length / (2 * zo));
31 // let p1 = line[0];
32 // let p2 = line[1];
33 // if (p1[0] > p2[0]) {
34 // p1 = line[1];
35 // p2 = line[0];
36 // }
37 // let alpha = Math.atan((p2[1] - p1[1]) / (p2[0] - p1[0]));
38 // for (let i = 0; i < count; i++) {
39 // let lstart = i * 2 * zo;
40 // let lend = (i + 1) * 2 * zo;
41 // let dz = Math.sqrt(2 * Math.pow(zo, 2));
42 // let start: Point = [p1[0] + (lstart * Math.cos(alpha)), p1[1] + lstart * Math.sin(alpha)];
43 // let end: Point = [p1[0] + (lend * Math.cos(alpha)), p1[1] + (lend * Math.sin(alpha))];
44 // let middle: Point = [start[0] + dz * Math.cos(alpha + Math.PI / 4), start[1] + dz * Math.sin(alpha + Math.PI / 4)];
45 // ops.push(
46 // ...self.helper.doubleLineOps(start[0], start[1], middle[0], middle[1], o),
47 // ...self.helper.doubleLineOps(middle[0], middle[1], end[0], end[1], o)
48 // );
49 // }
50 // });
51 // return ops;
52 unimplemented!()
53 }
54}