use crate::render::Color;
#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) enum Orientation {
Horizontal(f64),
Vertical(f64),
}
#[derive(Debug, Clone)]
pub struct Rule {
pub(crate) orientation: Orientation,
pub(crate) color: Option<Color>,
pub(crate) label: Option<String>,
}
impl Rule {
pub fn h(y: f64) -> Rule {
assert!(y.is_finite(), "Rule::h requires a finite position");
Rule {
orientation: Orientation::Horizontal(y),
color: None,
label: None,
}
}
pub fn v(x: f64) -> Rule {
assert!(x.is_finite(), "Rule::v requires a finite position");
Rule {
orientation: Orientation::Vertical(x),
color: None,
label: None,
}
}
#[must_use]
pub fn color(mut self, color: Color) -> Rule {
self.color = Some(color);
self
}
#[must_use]
pub fn label(mut self, label: impl Into<String>) -> Rule {
self.label = Some(label.into());
self
}
}
#[cfg(test)]
#[path = "tests/rule_tests.rs"]
mod tests;