use crate::model::Shape;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ShapeStyle {
pub fill: &'static str,
pub stroke: &'static str,
}
pub fn shape_style(shape: Shape) -> ShapeStyle {
match shape {
Shape::Rect => ShapeStyle {
fill: "#eef1fb",
stroke: "#5b6dc0",
},
Shape::Rounded => ShapeStyle {
fill: "#e4f5f4",
stroke: "#199a8e",
},
Shape::Stadium => ShapeStyle {
fill: "#e5f5ea",
stroke: "#33a35c",
},
Shape::Diamond => ShapeStyle {
fill: "#fcf2da",
stroke: "#d99114",
},
Shape::Circle => ShapeStyle {
fill: "#f2ecfa",
stroke: "#8a5cd6",
},
Shape::DoubleCircle => ShapeStyle {
fill: "#e5f5ea",
stroke: "#33a35c",
},
Shape::Cylinder => ShapeStyle {
fill: "#e7eef7",
stroke: "#4d8fbf",
},
Shape::Subroutine => ShapeStyle {
fill: "#eef1fb",
stroke: "#5b6dc0",
},
Shape::Hexagon => ShapeStyle {
fill: "#f2ecfa",
stroke: "#8a5cd6",
},
Shape::Parallelogram | Shape::ParallelogramAlt => ShapeStyle {
fill: "#fcf2da",
stroke: "#d99114",
},
}
}
pub const ACCENTS: &[&str] = &[
"#5b6dc0", "#33a35c", "#d99114", "#c2588c", "#199a8e", "#8a5cd6", "#d96459", "#4d8fbf", ];
pub fn accent(index: usize) -> &'static str {
ACCENTS[index % ACCENTS.len()]
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_shape_has_a_distinct_stroke() {
let shapes = [
Shape::Rect,
Shape::Rounded,
Shape::Stadium,
Shape::Diamond,
Shape::Circle,
];
for (i, a) in shapes.iter().enumerate() {
for b in &shapes[i + 1..] {
assert_ne!(shape_style(*a).stroke, shape_style(*b).stroke);
}
}
}
#[test]
fn accent_wraps_stably() {
assert_eq!(accent(0), accent(ACCENTS.len()));
assert_ne!(accent(0), accent(1));
}
}