diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..05b26ab --- /dev/null +++ b/.dockerignore @@ -0,0 +1,40 @@ +# Rust build artifacts +target/ +debug/ +release/ + +# Cargo metadata / local caches +.cargo/ + +# Git +.git/ +.gitignore + +# IDE / editor +.vscode/ +.idea/ +*.swp +*.swo + +# OS files +.DS_Store +Thumbs.db + +# Environment / secrets +.env +.env.* + +# Logs +*.log + +# Docker / compose overrides (optional) +docker-compose.override.yml + +# Test / temp outputs +*.tmp +*.bak + +# Generated artifacts +*.png +*.svg +*.pdf \ No newline at end of file diff --git a/src/functions.rs b/src/functions.rs index 1ef0759..0362357 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -2,3 +2,7 @@ pub mod polynomial; pub mod rational; pub mod radical; + +mod exponential; +mod logarithmic; +pub mod piecewise; diff --git a/src/functions/exponential.rs b/src/functions/exponential.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/functions/exponential.rs @@ -0,0 +1 @@ + diff --git a/src/functions/logarithmic.rs b/src/functions/logarithmic.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/functions/logarithmic.rs @@ -0,0 +1 @@ + diff --git a/src/functions/piecewise.rs b/src/functions/piecewise.rs new file mode 100644 index 0000000..f6f27bc --- /dev/null +++ b/src/functions/piecewise.rs @@ -0,0 +1,15 @@ +use crate::core::traits::Function; + +pub struct Piecewise { + functions: Vec>, +} + +impl Piecewise { + pub fn count(&self) -> usize { + self.functions.len() + } + + pub fn functions(&self) -> &[Box] { + &self.functions + } +} diff --git a/src/functions/polynomial.rs b/src/functions/polynomial.rs index 77d0384..8b0d69c 100644 --- a/src/functions/polynomial.rs +++ b/src/functions/polynomial.rs @@ -1,4 +1,4 @@ -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Polynomial { /// Coefficients in descending degree order. /// Example: x^2 - 4x + 3 => vec![1.0, -4.0, 3.0] @@ -64,11 +64,6 @@ impl Polynomial { Polynomial::new(result) } - pub fn evaluate(&self, x: f64) -> f64 { - // Horner's method - self.coefficients.iter().fold(0.0, |acc, &c| acc * x + c) - } - pub fn derivative(&self) -> Self { let degree = self.degree(); @@ -94,6 +89,11 @@ impl Polynomial { self.evaluate(0.0) } + pub fn evaluate(&self, x: f64) -> f64 { + // Horner's method + self.coefficients.iter().fold(0.0, |acc, &c| acc * x + c) + } + pub fn leading_coefficient(&self) -> f64 { self.coefficients[0] } diff --git a/src/functions/rational.rs b/src/functions/rational.rs index d6a88e4..479de9d 100644 --- a/src/functions/rational.rs +++ b/src/functions/rational.rs @@ -4,8 +4,8 @@ use crate::functions::polynomial::Polynomial; pub struct Rational { /// Coefficients in descending degree order. /// Example: x^2 - 4x + 3 => vec![1.0, -4.0, 3.0] - pub numerator: Polynomial, - pub denominator: Polynomial, + numerator: Polynomial, + denominator: Polynomial, } impl Rational { @@ -15,4 +15,33 @@ impl Rational { denominator, } } + + pub fn asymptote(&self) -> Polynomial { + let numerator = &self.numerator; + let denominator = &self.denominator; + if numerator.degree() == denominator.degree() { + let ratio = numerator.leading_coefficient() / denominator.leading_coefficient(); + Polynomial::new(vec![ratio]) + } else if numerator.degree() > denominator.degree() { + Polynomial::new(vec![]) + } else { + Polynomial::new(vec![0.0]) + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn expect_horizontal_asymptote_zero() { + let numerator = Polynomial::new(vec![1.0, 1.0]); + let denominator = Polynomial::new(vec![1.0, 1.0, 1.0]); + let rational = Rational::new(numerator, denominator); + let asymptote: Polynomial = rational.asymptote(); + + let horizontal_expected: Polynomial = Polynomial::new(vec![0.0]); + assert_eq!(asymptote, horizontal_expected); + } }