Circle-Packings/fractal_dimension/circle_counting_new/src/main.rs

108 lines
2.8 KiB
Rust
Raw Normal View History

2021-07-06 19:29:22 -07:00
#![allow(dead_code)]
2021-07-05 12:52:54 -07:00
2021-07-06 19:29:22 -07:00
use crate::{lib::fractal_dimension, parser::read_file};
use std::process;
use structopt::StructOpt;
2021-07-05 12:52:54 -07:00
2021-07-06 19:29:22 -07:00
use ansi_term::Color::Yellow;
2021-07-05 12:52:54 -07:00
2021-07-06 19:29:22 -07:00
mod lib;
mod parser;
2021-07-05 12:52:54 -07:00
2021-07-06 19:29:22 -07:00
/// Compute fractal dimension of crystallographic packings via the circle counting method
#[derive(StructOpt)]
#[structopt(name = "Circle Counter")]
struct Opt {
/// File containing data in the order generators, root, faces
#[structopt(name = "data file")]
data_file: String,
2021-07-05 12:52:54 -07:00
2021-07-06 19:29:22 -07:00
/// Activate debug mode
#[structopt(short, long)]
debug: bool,
2021-07-05 12:52:54 -07:00
2021-07-06 19:29:22 -07:00
/// Number of sample points in linear regression
#[structopt(short, long, default_value = "50")]
n: usize,
2021-07-05 12:52:54 -07:00
2021-07-06 19:29:22 -07:00
/// Maximum curvature of circles
#[structopt(short, long, default_value = "1000000")]
max: f64,
/// Whether or not to time excecution (automatically enabled by --debug)
#[structopt(short, long)]
time: bool,
2021-07-05 12:52:54 -07:00
}
fn main() {
2021-07-06 19:29:22 -07:00
let opt = Opt::from_args();
let debug = opt.debug;
let time = debug || opt.time;
let beginning = std::time::Instant::now();
let (generators, root, faces) = read_file(&opt.data_file).unwrap_or_else(|err| {
eprintln!("{}", err);
process::exit(-1);
});
2021-07-05 12:52:54 -07:00
2021-07-06 19:29:22 -07:00
let after_parsing = std::time::Instant::now();
if time {
let duration = after_parsing.duration_since(beginning);
println!(
"Took {}s to parse {}",
duration.as_secs_f64(),
opt.data_file
);
}
if debug {
println!(
"{} (parsed from command args):\t{}",
Yellow.paint("max"),
opt.max
);
println!(
"{} (parsed from command args):\t{}",
Yellow.paint("n"),
opt.n
);
}
2021-07-05 12:52:54 -07:00
2021-07-06 19:29:22 -07:00
if debug {
println!(
"{} (parsed from file {})",
Yellow.paint("Generators"),
opt.data_file
);
for generator in &generators {
println!("{}", generator);
}
println!(
"{} (parsed from file {}):",
Yellow.paint("Root Tuple"),
opt.data_file
);
println!("{}", root);
println!(
"{} (parsed from file {}):",
Yellow.paint("Faces"),
opt.data_file
);
println!("{:?}\n", faces);
}
let delta = fractal_dimension(generators, root, faces, opt.max, opt.n, debug).unwrap();
let after_computing = std::time::Instant::now();
if time {
let duration1 = after_computing.duration_since(after_parsing);
let duration2 = after_computing.duration_since(beginning);
println!(
"\nTook {}s to compute fractal dimension; {}s total",
duration1.as_secs_f64(),
duration2.as_secs_f64()
);
}
println!("\n{}", delta);
2021-07-05 12:52:54 -07:00
}