catenary 0.5.0

A library for catenary curves
Documentation
use anyhow::Ok;
use catenary::table::Table;
use clap::Parser;
use clap_derive::ValueEnum;
use std::fs; // Add the missing import statement

/// Generate a table of catenaries normalized by theta[0-90deg] and distance of extremities/length [0-1]
#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Args {
    /// Number of linearly spaced theta values in [0, pi/2]
    #[arg(short, long, default_value = "1000")]
    theta_n: usize,

    /// Number of linearly spaced distance/length values in [0, 1]
    #[arg(short, long, default_value = "1000")]
    length_n: usize,

    /// Output folder for the table export
    #[arg(short, long, default_value = "output")]
    output_folder: String,

    /// Float type to use for the table
    #[arg(value_enum, default_value = "f64")]
    float_type: FloatType,
}

#[derive(Parser, Clone, Copy, Debug, ValueEnum)]
enum FloatType {
    F32,
    F64,
}

fn main() -> anyhow::Result<()> {
    let args = Args::parse();

    match args.float_type {
        FloatType::F32 => println!("Using f32"),
        FloatType::F64 => println!("Using f64"),
    }

    // Create output folder if it doesn't already exist
    fs::create_dir_all(&args.output_folder).unwrap();

    let table_file = format!(
        "{}/{:?}_catenary_table_t{}_d{}.bin",
        args.output_folder, args.float_type, args.theta_n, args.length_n
    )
    .to_lowercase();

    match args.float_type {
        FloatType::F32 => {
            println!("Using f32");
            Table::<f32>::generate(args.theta_n, args.length_n)?
                .save(&table_file)
                .unwrap()
        }
        FloatType::F64 => {
            println!("Using f64");
            Table::<f64>::generate(args.theta_n, args.length_n)?
                .save(&table_file)
                .unwrap()
        }
    };

    println!("Catenary table saved to: {table_file}",);
    println!(
        "File size: {} bytes",
        fs::metadata(&table_file).unwrap().len()
    );
    Ok(())
}