From 395c8b3e261d60264bebd3ea4f3e546774fe2d7d Mon Sep 17 00:00:00 2001 From: Spectre Date: Sun, 27 Jul 2025 16:29:07 +0200 Subject: [PATCH] Auto commit --- src/lib.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 078ba93..e1b5a28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,9 +35,30 @@ fn normalize(v1: &Vector) -> Vector { y: v1.y / calculate_norm(v1), } } +fn fade(x: f32) -> f32 { + // This is a mathematic equation, it take a value and return the result of the value by that + // equation. That equation if derivate should be easy when close to 0 and 1 and hard in the + // middle. Take a f32 value return f32.Both value are between 0 and 1 + 6_f32 * x.powi(5) - 15_f32 * x.powi(4) + 10_f32 * x.powi(3) +} +/// Linearly interpolates between two scalar values. +/// +/// # Parameters +/// - `a`: start value (when `t = 0.0`) +/// - `b`: end value (when `t = 1.0`) +/// - `t`: interpolation factor in `[0.0, 1.0]` +/// +/// # Returns +/// A value on the line from `a` to `b`: +/// - if `t = 0.0`, yields `a` +/// - if `t = 1.0`, yields `b` +/// - otherwise `a + t * (b - a)` +fn linear_interpolation(a: f32, b: f32, t: f32) -> f32 { + a + t * (b - a) +} #[cfg(test)] mod tests { - use crate::{Vector, calculate_norm, dot_product, normalize}; + use crate::{Vector, calculate_norm, dot_product, linear_interpolation, normalize}; #[test] fn test_dot_product() { assert_eq!( @@ -67,4 +88,10 @@ mod tests { let v1 = Vector { x: 0.5, y: 0.5 }; assert_eq!(calculate_norm(&normalize(&v1)).round(), 1_f32); } + //fn test_fade() {todo!()} + #[test] + fn test_linear_interpolation() { + assert_eq!(linear_interpolation(0.0, 10.0, 0.25), 2.5); + assert_eq!(linear_interpolation(5.0, 15.0, 0.75), 12.5); + } }