use crate::{Color32, Pos2, Rect, Shape, Stroke, Vec2}; /// How to paint a circle. #[derive(Copy, Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct CircleShape { pub center: Pos2, pub radius: f32, pub fill: Color32, pub stroke: Stroke, } impl CircleShape { #[inline] pub fn filled(center: Pos2, radius: f32, fill_color: impl Into) -> Self { Self { center, radius, fill: fill_color.into(), stroke: Default::default(), } } #[inline] pub fn stroke(center: Pos2, radius: f32, stroke: impl Into) -> Self { Self { center, radius, fill: Default::default(), stroke: stroke.into(), } } /// The visual bounding rectangle (includes stroke width) pub fn visual_bounding_rect(&self) -> Rect { if self.fill == Color32::TRANSPARENT && self.stroke.is_empty() { Rect::NOTHING } else { Rect::from_center_size( self.center, Vec2::splat(self.radius * 2.0 + self.stroke.width), ) } } } impl From for Shape { #[inline(always)] fn from(shape: CircleShape) -> Self { Self::Circle(shape) } }