svgbob/buffer/fragment_buffer/
direction.rs

1use crate::buffer::CellGrid;
2
3#[derive(Debug, Clone, PartialEq, Eq, Copy)]
4pub enum Direction {
5    TopLeft,
6    Top,
7    TopRight,
8    Left,
9    Right,
10    BottomLeft,
11    Bottom,
12    BottomRight,
13}
14
15impl Direction {
16    /// return the opposite direction of self
17    pub(crate) fn opposite(&self) -> Self {
18        match self {
19            Direction::TopLeft => Direction::BottomRight,
20            Direction::Top => Direction::Bottom,
21            Direction::TopRight => Direction::BottomLeft,
22            Direction::Left => Direction::Right,
23            Direction::Right => Direction::Left,
24            Direction::BottomLeft => Direction::TopRight,
25            Direction::Bottom => Direction::Top,
26            Direction::BottomRight => Direction::TopLeft,
27        }
28    }
29
30    /// calculate the threshold length which is the basis
31    /// if the arrow and the line is connected
32    pub(crate) fn threshold_length(&self) -> f32 {
33        match self {
34            Direction::TopLeft
35            | Direction::TopRight
36            | Direction::BottomLeft
37            | Direction::BottomRight => CellGrid::diagonal_length(),
38            Direction::Left | Direction::Right => CellGrid::width(),
39            Direction::Top | Direction::Bottom => CellGrid::height(),
40        }
41    }
42}