use crate::*;
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct EllipseShape {
pub center: Pos2,
pub radius: Vec2,
pub fill: Color32,
pub stroke: Stroke,
pub angle: f32,
}
impl EllipseShape {
#[inline]
pub fn filled(center: Pos2, radius: Vec2, fill_color: impl Into<Color32>) -> Self {
Self {
center,
radius,
fill: fill_color.into(),
stroke: Default::default(),
angle: 0.0,
}
}
#[inline]
pub fn stroke(center: Pos2, radius: Vec2, stroke: impl Into<Stroke>) -> Self {
Self {
center,
radius,
fill: Default::default(),
stroke: stroke.into(),
angle: 0.0,
}
}
#[inline]
pub fn with_angle(mut self, angle: f32) -> Self {
self.angle = angle;
self
}
#[inline]
pub fn with_angle_and_pivot(mut self, angle: f32, pivot: Pos2) -> Self {
self.angle = angle;
let rot = emath::Rot2::from_angle(angle);
self.center = pivot + rot * (self.center - pivot);
self
}
pub fn visual_bounding_rect(&self) -> Rect {
if self.fill == Color32::TRANSPARENT && self.stroke.is_empty() {
Rect::NOTHING
} else {
let rect = Rect::from_center_size(
Pos2::ZERO,
self.radius * 2.0 + Vec2::splat(self.stroke.width),
);
rect.rotate_bb(emath::Rot2::from_angle(self.angle))
.translate(self.center.to_vec2())
}
}
}
impl From<EllipseShape> for Shape {
#[inline(always)]
fn from(shape: EllipseShape) -> Self {
Self::Ellipse(shape)
}
}