#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum AxisSide {
Left,
Right,
Bottom,
Top,
}
impl AxisSide {
pub fn is_vertical(self) -> bool {
matches!(self, AxisSide::Left | AxisSide::Right)
}
pub fn is_horizontal(self) -> bool {
!self.is_vertical()
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LegendSide {
Left,
Right,
Top,
Bottom,
InPanel { anchor: Anchor, inset_pt: f64 },
}
impl Eq for LegendSide {}
impl std::hash::Hash for LegendSide {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
std::mem::discriminant(self).hash(state);
if let LegendSide::InPanel { anchor, inset_pt } = self {
anchor.hash(state);
inset_pt.to_bits().hash(state);
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Anchor {
TopLeft,
TopCenter,
TopRight,
CenterLeft,
Center,
CenterRight,
BottomLeft,
BottomCenter,
BottomRight,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn axis_side_orientation() {
assert!(AxisSide::Left.is_vertical());
assert!(AxisSide::Right.is_vertical());
assert!(AxisSide::Bottom.is_horizontal());
assert!(AxisSide::Top.is_horizontal());
assert!(!AxisSide::Left.is_horizontal());
assert!(!AxisSide::Bottom.is_vertical());
}
}