#[derive(Debug, Clone, Copy, PartialEq)]
pub struct BorderRadius {
pub top_left: f32,
pub top_right: f32,
pub bottom_right: f32,
pub bottom_left: f32,
}
impl BorderRadius {
pub fn all(radius: f32) -> Self {
Self {
top_left: radius,
top_right: radius,
bottom_right: radius,
bottom_left: radius,
}
}
pub fn zero() -> Self {
Self::all(0.0)
}
pub fn is_zero(&self) -> bool {
self.top_left == 0.0
&& self.top_right == 0.0
&& self.bottom_right == 0.0
&& self.bottom_left == 0.0
}
}
impl Default for BorderRadius {
fn default() -> Self {
Self::zero()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn border_radius_all_sets_all_corners_equal() {
let br = BorderRadius::all(8.0);
assert_eq!(br.top_left, 8.0);
assert_eq!(br.top_right, 8.0);
assert_eq!(br.bottom_right, 8.0);
assert_eq!(br.bottom_left, 8.0);
}
#[test]
fn border_radius_zero_all_corners_are_zero() {
let br = BorderRadius::zero();
assert_eq!(br.top_left, 0.0);
assert_eq!(br.top_right, 0.0);
assert_eq!(br.bottom_right, 0.0);
assert_eq!(br.bottom_left, 0.0);
}
#[test]
fn border_radius_zero_is_zero() {
assert!(BorderRadius::zero().is_zero());
}
#[test]
fn border_radius_non_zero_is_not_zero() {
assert!(!BorderRadius::all(1.0).is_zero());
}
#[test]
fn border_radius_default_is_zero() {
assert!(BorderRadius::default().is_zero());
}
#[test]
fn border_radius_partial_non_zero_is_not_zero() {
let br = BorderRadius {
top_left: 5.0,
top_right: 0.0,
bottom_right: 0.0,
bottom_left: 0.0,
};
assert!(!br.is_zero());
}
}