use crate::model::style::BorderLineType;
use crate::renderer::StrokeDash;
const PRINT_INTERVALS: [[u16; 6]; 16] = [
[3, 4, 17, 9, 34, 9],
[4, 6, 20, 12, 40, 12],
[5, 7, 26, 14, 51, 15],
[7, 10, 34, 21, 68, 21],
[9, 13, 43, 27, 86, 27],
[10, 15, 52, 29, 103, 30],
[14, 21, 69, 42, 138, 42],
[17, 25, 86, 51, 172, 51],
[21, 31, 104, 62, 207, 63],
[24, 36, 121, 72, 242, 72],
[35, 52, 173, 105, 346, 105],
[52, 78, 259, 156, 518, 156],
[69, 103, 347, 206, 693, 207],
[104, 156, 520, 311, 1039, 312],
[139, 208, 693, 417, 1386, 417],
[173, 259, 866, 519, 1732, 519],
];
pub(crate) fn border_dash(kind: BorderLineType, width: u8) -> Option<StrokeDash> {
let &[short, short_gap, long, long_gap, chain, chain_gap] =
PRINT_INTERVALS.get(usize::from(width))?;
let intervals = match kind {
BorderLineType::Dot => [short, short_gap, 0, 0, 0, 0],
BorderLineType::Dash => [long, long_gap, 0, 0, 0, 0],
BorderLineType::DashDot => [chain, chain_gap, short, chain_gap, 0, 0],
BorderLineType::DashDotDot => [chain, chain_gap, short, chain_gap, short, chain_gap],
_ => return None,
};
Some(StrokeDash::Explicit(
intervals.map(|value| f64::from(value) * 96.0 / 600.0),
))
}
const PRINT_CIRCLES: [[u16; 2]; 16] = [
[4, 8],
[4, 10],
[6, 13],
[8, 18],
[10, 23],
[10, 25],
[14, 35],
[18, 43],
[22, 53],
[24, 60],
[36, 88],
[52, 130],
[70, 173],
[104, 260],
[140, 348],
[174, 433],
];
pub(crate) fn border_circle(width: u8) -> (f64, f64) {
let &[diameter, pitch] = PRINT_CIRCLES
.get(usize::from(width))
.unwrap_or(&PRINT_CIRCLES[0]);
(
f64::from(diameter) * 96.0 / 600.0,
f64::from(pitch) * 96.0 / 600.0,
)
}