use crate::PlotInset;
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct DrawingArea {
pub width: f64,
pub height: f64,
pub left: f64,
pub top: f64,
pub plot_width: f64,
pub plot_height: f64,
}
pub fn compute_drawing_area(width: f64, height: f64, inset: PlotInset) -> DrawingArea {
let plot_width = (width - inset.left - inset.right).max(0.0);
let plot_height = (height - inset.top - inset.bottom).max(0.0);
DrawingArea {
width,
height,
left: inset.left,
top: inset.top,
plot_width,
plot_height,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn compute_drawing_area_applies_inset() {
let area = compute_drawing_area(
400.0,
300.0,
PlotInset {
top: 20.0,
bottom: 30.0,
left: 40.0,
right: 10.0,
},
);
assert_eq!(area.plot_width, 350.0);
assert_eq!(area.plot_height, 250.0);
assert_eq!(area.left, 40.0);
assert_eq!(area.top, 20.0);
}
}