#![allow(dead_code)]
#[derive(Debug, Clone)]
pub struct TopologyView {
pub enabled: bool,
pub show_poles: bool,
pub show_irregular: bool,
}
pub fn new_topology_view() -> TopologyView {
TopologyView {
enabled: false,
show_poles: true,
show_irregular: true,
}
}
pub fn tv_enable(v: &mut TopologyView) {
v.enabled = true;
}
pub fn tv_disable(v: &mut TopologyView) {
v.enabled = false;
}
pub fn tv_set_show_poles(v: &mut TopologyView, show: bool) {
v.show_poles = show;
}
pub fn tv_set_show_irregular(v: &mut TopologyView, show: bool) {
v.show_irregular = show;
}
pub fn tv_valence_color(valence: u32) -> [f32; 3] {
match valence {
3 => [1.0, 0.4, 0.0], 4 => [0.2, 0.8, 0.2], 5 => [0.4, 0.4, 1.0], _ => [1.0, 0.0, 0.0], }
}
pub fn tv_is_pole(valence: u32) -> bool {
valence == 3 || valence >= 5
}
pub fn tv_to_json(v: &TopologyView) -> String {
format!(
r#"{{"enabled":{},"show_poles":{},"show_irregular":{}}}"#,
v.enabled, v.show_poles, v.show_irregular
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_defaults() {
let v = new_topology_view();
assert!(!v.enabled);
assert!(v.show_poles);
assert!(v.show_irregular);
}
#[test]
fn test_enable() {
let mut v = new_topology_view();
tv_enable(&mut v);
assert!(v.enabled);
}
#[test]
fn test_disable() {
let mut v = new_topology_view();
tv_enable(&mut v);
tv_disable(&mut v);
assert!(!v.enabled);
}
#[test]
fn test_valence_color_regular() {
let c = tv_valence_color(4);
assert!(c[1] > c[0]);
}
#[test]
fn test_valence_color_pole_3() {
let c = tv_valence_color(3);
assert!(c[0] > c[1]);
}
#[test]
fn test_is_pole_3() {
assert!(tv_is_pole(3));
}
#[test]
fn test_is_pole_4_not() {
assert!(!tv_is_pole(4));
}
#[test]
fn test_is_pole_5() {
assert!(tv_is_pole(5));
}
#[test]
fn test_to_json() {
assert!(tv_to_json(&new_topology_view()).contains("enabled"));
}
}