#![allow(dead_code)]
pub const ARROW_HEAD_CHARS: &str = ">v<^V";
pub const POINT_CHARS: &str = "o*◌○◍●⊕";
pub const JUMP_CHARS: &str = "()";
pub const UNDIRECTED_VERTEX_CHARS: &str = "+";
pub const VERTEX_CHARS: &str = "+.',`";
pub const GRAY_CHARS: &str = "▁▂▃█";
pub const TRI_CHARS: &str = "◢◣◤◥";
#[inline]
pub fn is_vertex(c: char) -> bool {
VERTEX_CHARS.contains(c)
}
#[inline]
pub fn is_undirected_vertex(c: char) -> bool {
c == '+'
}
#[inline]
pub fn is_top_vertex(c: char) -> bool {
c == '.' || c == ',' || c == '+'
}
#[inline]
pub fn is_bottom_vertex(c: char) -> bool {
c == '\'' || c == '`' || c == '+'
}
#[inline]
pub fn is_top_vertex_or_decoration(c: char) -> bool {
is_top_vertex(c) || c == '^'
}
#[inline]
pub fn is_bottom_vertex_or_decoration(c: char) -> bool {
is_bottom_vertex(c) || c == 'v' || c == 'V'
}
#[inline]
pub fn is_vertex_or_left_decoration(c: char) -> bool {
is_vertex(c) || c == '<' || is_point(c)
}
#[inline]
pub fn is_vertex_or_right_decoration(c: char) -> bool {
is_vertex(c) || c == '>' || is_point(c)
}
#[inline]
pub fn is_solid_h_line(c: char) -> bool {
c == '-' || c == '─' || c == '+' || c == '(' || c == ')'
}
#[inline]
pub fn is_squiggle_h_line(c: char) -> bool {
c == '~' || c == '+' || c == '(' || c == ')'
}
#[inline]
pub fn is_double_h_line(c: char) -> bool {
c == '=' || c == '═' || c == '+' || c == '(' || c == ')'
}
#[inline]
pub fn is_any_h_line(c: char) -> bool {
is_solid_h_line(c) || is_squiggle_h_line(c) || is_double_h_line(c)
}
#[inline]
pub fn is_solid_v_line(c: char) -> bool {
c == '|' || c == '│' || c == '+'
}
#[inline]
pub fn is_double_v_line(c: char) -> bool {
c == '║' || c == '+'
}
#[inline]
pub fn is_solid_d_line(c: char) -> bool {
c == '/' || c == '╱'
}
#[inline]
pub fn is_solid_b_line(c: char) -> bool {
c == '\\' || c == '╲'
}
#[inline]
pub fn is_gray(c: char) -> bool {
GRAY_CHARS.contains(c)
}
#[inline]
pub fn is_tri(c: char) -> bool {
TRI_CHARS.contains(c)
}
#[inline]
pub fn is_arrow_head(c: char) -> bool {
ARROW_HEAD_CHARS.contains(c)
}
#[inline]
pub fn is_point(c: char) -> bool {
POINT_CHARS.contains(c)
}
#[inline]
pub fn is_jump(c: char) -> bool {
c == '(' || c == ')'
}
#[inline]
pub fn is_decoration(c: char) -> bool {
is_arrow_head(c) || is_point(c) || is_gray(c) || is_tri(c)
}
#[inline]
pub fn is_ascii_letter(c: char) -> bool {
c.is_ascii_alphabetic()
}
pub fn gray_level(c: char) -> u8 {
match c {
'▁' => 64,
'▂' => 128,
'▃' => 191,
'█' => 255,
_ => 0,
}
}
pub fn tri_angle(c: char) -> f64 {
match c {
'◢' => 0.0,
'◣' => 90.0,
'◤' => 180.0,
'◥' => 270.0,
_ => 0.0,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_vertex_detection() {
assert!(is_vertex('+'));
assert!(is_vertex('.'));
assert!(is_vertex('\''));
assert!(is_vertex(','));
assert!(is_vertex('`'));
assert!(!is_vertex('-'));
assert!(!is_vertex('|'));
}
#[test]
fn test_line_detection() {
assert!(is_solid_h_line('-'));
assert!(is_solid_h_line('─'));
assert!(is_solid_h_line('+'));
assert!(!is_solid_h_line('|'));
assert!(is_solid_v_line('|'));
assert!(is_solid_v_line('│'));
assert!(is_solid_v_line('+'));
assert!(!is_solid_v_line('-'));
assert!(is_solid_d_line('/'));
assert!(is_solid_b_line('\\'));
}
#[test]
fn test_arrow_detection() {
assert!(is_arrow_head('>'));
assert!(is_arrow_head('<'));
assert!(is_arrow_head('^'));
assert!(is_arrow_head('v'));
assert!(is_arrow_head('V'));
assert!(!is_arrow_head('-'));
}
#[test]
fn test_point_detection() {
assert!(is_point('o'));
assert!(is_point('*'));
assert!(is_point('●'));
assert!(is_point('○'));
assert!(!is_point('+'));
}
#[test]
fn test_gray_levels() {
assert_eq!(gray_level('▁'), 64);
assert_eq!(gray_level('▂'), 128);
assert_eq!(gray_level('▃'), 191);
assert_eq!(gray_level('█'), 255);
assert_eq!(gray_level('x'), 0);
}
}