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
use algebr::Vec2;

use crate::{position::Rect, style::Style, Shape, ShapeType};

#[derive(Debug, Clone)]
pub struct Circle {
    pub(crate) pos: Rect,
    pub(crate) radius: f32,
    pub(crate) style: Option<Style>,
}
crate::impl_pos_at!(Circle);
crate::impl_pos_anchor!(Circle);
crate::impl_style!(Circle);
impl Circle {
    /// Default circle.
    pub const fn new() -> Circle {
        Circle {
            pos: Rect::new(),
            radius: 0.0,
            style: None,
        }
    }

    /// Create circle with radius.
    pub const fn with_radius(mut self, radius: f32) -> Self {
        self.radius = radius;
        self
    }
}

impl Into<Shape> for Circle {
    fn into(self) -> Shape {
        let size = Vec2::ones() * self.radius * 2.;

        Shape {
            pos: self.pos.with_size(size),
            style: self.style,
            shape_type: ShapeType::Circle {
                radius: self.radius,
            },
        }
    }
}