1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use algebr::Angle;
use shape::{Keypoint, Keypoints, Path};

use crate::{
    shape::{self, Style},
    Rect, Shape,
};

use super::Arc;

#[derive(Debug, Clone, PartialEq)]
pub struct ThickArc {
    pub(crate) pos: Rect,
    pub(crate) inner_radius: f32,
    pub(crate) outer_radius: f32,
    pub(crate) start_angle: Angle,
    pub(crate) end_angle: Angle,
    pub(crate) style: Option<Style>,
}
crate::impl_pos_at!(ThickArc);
crate::impl_pos_anchor!(ThickArc);
crate::impl_style!(ThickArc);
impl ThickArc {
    pub const fn new() -> Self {
        ThickArc {
            pos: Rect::new(),
            inner_radius: 0.0,
            outer_radius: 0.0,
            start_angle: Angle::radians(0.0),
            end_angle: Angle::radians(0.0),
            style: None,
        }
    }

    pub const fn with_inner_radius(mut self, inner_radius: f32) -> Self {
        self.inner_radius = inner_radius;
        self
    }

    pub const fn with_outer_radius(mut self, outer_radius: f32) -> Self {
        self.outer_radius = outer_radius;
        self
    }

    pub const fn with_start_angle(mut self, start_angle: Angle) -> Self {
        self.start_angle = start_angle;
        self
    }

    pub const fn with_end_angle(mut self, end_angle: Angle) -> Self {
        self.end_angle = end_angle;
        self
    }
}

impl Into<Shape> for ThickArc {
    fn into(self) -> Shape {
        let outer: Keypoints = Arc::new()
            .at(self.pos.pos)
            .with_anchor(self.pos.anchor)
            .with_radius(self.outer_radius)
            .with_start_angle(self.start_angle)
            .with_end_angle(self.end_angle)
            .into();

        let inner: Keypoints = Arc::new()
            .at(self.pos.pos)
            .with_anchor(self.pos.anchor)
            .with_radius(self.inner_radius)
            .with_start_angle(self.start_angle)
            .with_end_angle(self.end_angle)
            .into();

        let inner = inner.reversed();

        let p = if let Keypoint::Point(p) = inner.0.first().unwrap() {
            *p
        } else {
            unreachable!()
        };

        Path::new()
            .then_do(outer)
            .then(p)
            .then_do(inner)
            .close()
            .with_maybe_style(self.style)
            .into()
    }
}