lgeo/shapes/
circle.rs

1use std::fmt::{Display, Formatter};
2use lmaths::*;
3use crate::Shape;
4
5#[allow(dead_code)]
6#[derive(Clone, Copy, Default, PartialEq, Debug)]
7/// A circle represented by a position and a radius
8pub struct Circle {
9    pub position:Vector2,
10    pub radius:f64
11}
12
13#[allow(dead_code)]
14impl Circle {
15    /// Create a new circle at the specified location, with a certain radius
16    pub fn new (position:Vector2, radius:f64) -> Self {
17        Self { position, radius }
18    }
19}
20
21impl Shape for Circle {
22    fn position(&self) -> Vector2 {
23        self.position
24    }
25
26    fn support_point(&self, direction: Vector2) -> Vector2 {
27        (direction.normalized() * self.radius) + self.position()
28    }
29}
30
31impl Display for Circle {
32    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
33        write!(f, "Circle pos ({0}), radius: {1}", self.position, self.radius)
34    }
35}