use super::dimensions::Dimension;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BoxDirection {
Horizontal,
Vertical,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TeXBox {
pub direction: BoxDirection,
pub width: Dimension,
pub height: Dimension,
pub depth: Dimension,
}
impl TeXBox {
pub fn hbox_empty() -> Self {
Self {
direction: BoxDirection::Horizontal,
width: Dimension::from_sp(0),
height: Dimension::from_sp(0),
depth: Dimension::from_sp(0),
}
}
pub fn total_height(&self) -> Dimension {
Dimension::from_sp(self.height.sp() + self.depth.sp())
}
pub fn hbox(width: Dimension, height: Dimension, depth: Dimension) -> Self {
Self {
direction: BoxDirection::Horizontal,
width,
height,
depth,
}
}
pub fn vbox(width: Dimension, height: Dimension, depth: Dimension) -> Self {
Self {
direction: BoxDirection::Vertical,
width,
height,
depth,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hbox_total_height() {
let height = Dimension::parse("10pt").unwrap();
let depth = Dimension::parse("2pt").unwrap();
let b = TeXBox::hbox(Dimension::parse("50pt").unwrap(), height, depth);
assert_eq!(b.total_height().pt(), 12.0);
}
#[test]
fn empty_hbox_is_zero() {
let b = TeXBox::hbox_empty();
assert_eq!(b.width.sp(), 0);
assert_eq!(b.total_height().sp(), 0);
}
}