use crate::geometry::*;
use crate::real::Real;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub enum Mode {
Corner,
Corners,
Center,
Radius,
}
impl Mode {
pub fn interpret<Num>(
&self,
x: Num,
y: Num,
width: Num,
height: Num,
) -> (Point2<Num>, Size2<Num>)
where
Num: Real,
{
use Mode::*;
match self {
Corner => (
Point2 {
x: x + width.div2(),
y: y + height.div2(),
},
Size2 { width, height },
),
Corners => (
Point2 {
x: x + (width - x).div2(),
y: y + (height - y).div2(),
},
Size2 {
width: width - x,
height: height - y,
},
),
Center => (Point2 { x, y }, Size2 { width, height }),
Radius => (
Point2 { x, y },
Size2 {
width: width.mul2(),
height: height.mul2(),
},
),
}
}
}