2024-02-19 12:40:18 -06:00
|
|
|
use std::num::NonZeroU16;
|
2024-02-20 10:49:44 -06:00
|
|
|
use crate::rectangle::Corners;
|
2024-02-20 10:30:26 -06:00
|
|
|
|
|
|
|
fn point_count(corners: Corners<f32>) -> NonZeroU16 {
|
|
|
|
//Increase for higher quality
|
|
|
|
const VTX_PER_CORER_RADIUS_PIXEL: f32 = 0.5;
|
|
|
|
NonZeroU16::new(
|
|
|
|
(corners.max_f32() * VTX_PER_CORER_RADIUS_PIXEL).round() as u16 + 2
|
|
|
|
).unwrap()
|
2024-02-19 12:40:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
|
|
pub struct RoundedCorners {
|
2024-02-20 10:30:26 -06:00
|
|
|
pub radius: Corners<f32>,
|
2024-02-19 12:40:18 -06:00
|
|
|
pub point_count: NonZeroU16,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RoundedCorners {
|
2024-02-20 10:30:26 -06:00
|
|
|
pub fn from_radius(radius: Corners<f32>) -> Self {
|
2024-02-19 12:40:18 -06:00
|
|
|
Self {
|
|
|
|
radius,
|
2024-02-20 10:30:26 -06:00
|
|
|
point_count: point_count(radius),
|
2024-02-19 12:40:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for RoundedCorners {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2024-02-20 10:30:26 -06:00
|
|
|
radius: Corners::default(),
|
2024-02-19 12:40:18 -06:00
|
|
|
point_count: NonZeroU16::new(8).unwrap(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|