pub mod csr_sim;
pub mod force;
pub mod quadtree;
pub mod simd;
pub mod simulation;
use crate::graph::VowlGraph;
use crate::Result;
#[cfg_attr(test, mockall::automock)]
pub trait LayoutAlgorithm {
fn initialize(&mut self, graph: &mut VowlGraph) -> Result<()>;
fn tick(&mut self, graph: &mut VowlGraph) -> Result<()>;
fn run(&mut self, graph: &mut VowlGraph, iterations: usize) -> Result<()>;
fn is_finished(&self) -> bool;
fn alpha(&self) -> f64;
}
#[derive(Debug, Clone)]
pub struct LayoutConfig {
pub alpha: f64,
pub alpha_decay: f64,
pub alpha_min: f64,
pub velocity_decay: f64,
pub link_distance: f64,
pub link_strength: f64,
pub charge_strength: f64,
pub center_strength: f64,
pub center: (f64, f64),
pub barnes_hut_theta: f64,
pub use_barnes_hut: bool,
pub seed_radius: f64,
pub preserve_seeded_positions: bool,
}
impl Default for LayoutConfig {
fn default() -> Self {
Self {
alpha: 1.0,
alpha_decay: 0.0228,
alpha_min: 0.001,
velocity_decay: 0.6,
link_distance: 30.0,
link_strength: 1.0,
charge_strength: -30.0,
center_strength: 1.0,
center: (0.0, 0.0),
barnes_hut_theta: 0.9,
use_barnes_hut: true,
seed_radius: 300.0,
preserve_seeded_positions: false,
}
}
}
impl LayoutConfig {
pub fn large_graph() -> Self {
Self {
link_distance: 250.0,
link_strength: 0.5,
charge_strength: -2000.0,
center_strength: 0.001,
seed_radius: 2000.0,
..Self::default()
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_config() {
let config = LayoutConfig::default();
assert_eq!(config.alpha, 1.0);
assert!(config.alpha_decay > 0.0);
assert!(config.alpha_min > 0.0);
}
#[test]
fn test_config_values() {
let config = LayoutConfig {
alpha: 0.5,
link_distance: 50.0,
..Default::default()
};
assert_eq!(config.alpha, 0.5);
assert_eq!(config.link_distance, 50.0);
}
}