dol 0.8.1

DOL (Design Ontology Language) - A declarative specification language for ontology-first development
// ═══════════════════════════════════════════════════════════════════════════════
// Physics Spirit - Internal Module
// DOL v0.9.0
// ═══════════════════════════════════════════════════════════════════════════════

module physics.internal @ 0.9.0

docs {
    Internal helper functions and types for the physics Spirit.
    This module is not exported and is used only within the Spirit.
}

// ═══════════════════════════════════════════════════════════════════════════════
// INTERNAL TYPES
// ═══════════════════════════════════════════════════════════════════════════════

docs {
    Numerical precision configuration.
}

gen PrecisionConfig {
    has epsilon: f64
    has max_iterations: u32
    has tolerance: f64
}

docs {
    Default precision for calculations.
}

fun default_precision() -> PrecisionConfig {
    return PrecisionConfig {
        epsilon: 1.0e-15,
        max_iterations: 1000,
        tolerance: 1.0e-10
    }
}

// ═══════════════════════════════════════════════════════════════════════════════
// NUMERICAL HELPERS
// ═══════════════════════════════════════════════════════════════════════════════

docs {
    Check if two floats are approximately equal.
}

fun approx_equal(a: f64, b: f64, epsilon: f64) -> bool {
    let diff = a - b
    if diff < 0.0 {
        return -diff < epsilon
    }
    return diff < epsilon
}

docs {
    Clamp a value to a range.
}

fun clamp(value: f64, min: f64, max: f64) -> f64 {
    if value < min {
        return min
    }
    if value > max {
        return max
    }
    return value
}

docs {
    Linear interpolation between two values.
}

fun lerp(a: f64, b: f64, t: f64) -> f64 {
    return a + (b - a) * t
}

docs {
    Safe division that returns a default on zero denominator.
}

fun safe_div(numerator: f64, denominator: f64, default: f64) -> f64 {
    if denominator == 0.0 {
        return default
    }
    return numerator / denominator
}

docs {
    Check if a value is finite (not NaN or Infinity).
}

fun is_finite(x: f64) -> bool {
    return x == x && x != 1.0e308 && x != -1.0e308
}

// ═══════════════════════════════════════════════════════════════════════════════
// VALIDATION HELPERS
// ═══════════════════════════════════════════════════════════════════════════════

docs {
    Validate that a value is non-negative.
}

fun validate_non_negative(value: f64, name: string) -> bool {
    return value >= 0.0
}

docs {
    Validate that a value is positive.
}

fun validate_positive(value: f64, name: string) -> bool {
    return value > 0.0
}

docs {
    Validate that a value is in a range.
}

fun validate_range(value: f64, min: f64, max: f64) -> bool {
    return value >= min && value <= max
}