petektools 0.1.0

Standalone numerics & geostatistics kernels for Rust: scattered-data gridding (minimum-curvature, IDW, nearest) and a curated numeric front-door. Pure leaf; PyO3 bindings planned.
Documentation
//! Oilfield-unit conversion constants and helpers.

/// Square feet per acre.
pub const ACRE_TO_FT2: f64 = 43_560.0;
/// Cubic feet per reservoir/stock-tank barrel.
pub const FT3_PER_BBL: f64 = 5.614_583_333_333_333;

/// Area: acres -> square feet.
#[must_use]
pub fn acres_to_ft2(acres: f64) -> f64 {
    acres * ACRE_TO_FT2
}

/// Volume: acre-feet -> cubic feet.
#[must_use]
pub fn acre_ft_to_ft3(acre_ft: f64) -> f64 {
    acre_ft * ACRE_TO_FT2
}

/// Volume: cubic feet -> acre-feet.
#[must_use]
pub fn ft3_to_acre_ft(ft3: f64) -> f64 {
    ft3 / ACRE_TO_FT2
}

/// Volume: cubic feet -> barrels (reservoir bbl).
#[must_use]
pub fn ft3_to_rb(ft3: f64) -> f64 {
    ft3 / FT3_PER_BBL
}

/// Volume: barrels -> cubic feet.
#[must_use]
pub fn rb_to_ft3(bbl: f64) -> f64 {
    bbl * FT3_PER_BBL
}

/// Temperature: degrees Fahrenheit -> degrees Rankine.
#[must_use]
pub fn degf_to_degr(degf: f64) -> f64 {
    degf + 459.67
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn acre_roundtrips_through_ft3() {
        // 1 acre-ft is 43,560 ft^3 by definition.
        assert!((acre_ft_to_ft3(1.0) - 43_560.0).abs() < 1e-9);
        assert!((ft3_to_acre_ft(43_560.0) - 1.0).abs() < 1e-12);
    }

    #[test]
    fn barrel_roundtrips() {
        let v = 12_345.6_f64;
        assert!((rb_to_ft3(ft3_to_rb(v)) - v).abs() < 1e-6);
    }

    #[test]
    fn rankine_offset() {
        assert!((degf_to_degr(60.0) - 519.67).abs() < 1e-9);
    }
}