<commit_before>
//! A module contains implementation of ease functions.

use std::f64::consts::{
    PI,
    PI_2,
};
use std::num::{
    Float,
    FloatMath,
};

pub use ease::EaseFunction::{
    EaseQuadraticIn,
    EaseQuadraticOut,
    EaseQuadraticInOut,

    EaseCubicIn,
    EaseCubicOut,
    EaseCubicInOut,

    EaseQuarticIn,
    EaseQuarticOut,
    EaseQuarticInOut,

    EaseQuinticIn,
    EaseQuinticOut,
    EaseQuinticInOut,

    EaseSineIn,
    EaseSineOut,
    EaseSineInOut,

    EaseCircularIn,
    EaseCircularOut,
    EaseCircularInOut,

    EaseExponentialIn,
    EaseExponentialOut,
    EaseExponentialInOut,

    EaseElasticIn,
    EaseElasticOut,
    EaseElasticInOut,

    EaseBackIn,
    EaseBackOut,
    EaseBackInOut,

    EaseBounceIn,
    EaseBounceOut,
    EaseBounceInOut,
};

#[allow(missing_docs)]
#[deriving(Copy, Clone, PartialEq)]
pub enum EaseFunction {
    EaseQuadraticIn,
    EaseQuadraticOut,
    EaseQuadraticInOut,

    EaseCubicIn,
    EaseCubicOut,
    EaseCubicInOut,

    EaseQuarticIn,
    EaseQuarticOut,
    EaseQuarticInOut,

    EaseQuinticIn,
    EaseQuinticOut,
    EaseQuinticInOut,

    EaseSineIn,
    EaseSineOut,
    EaseSineInOut,

    EaseCircularIn,
    EaseCircularOut,
    EaseCircularInOut,

    EaseExponentialIn,
    EaseExponentialOut,
    EaseExponentialInOut,

    EaseElasticIn,
    EaseElasticOut,
    EaseElasticInOut,

    EaseBackIn,
    EaseBackOut,
    EaseBackInOut,

    EaseBounceIn,
    EaseBounceOut,
    EaseBounceInOut,
}

impl EaseFunction {
    /// Calculate the eased value, normalized
    pub fn calc<T>(self, p: T) -> T
        where
            T: Float + FromPrimitive + FloatMath
    {
        match self {
            EaseQuadraticIn => quadratic_in(p),
            EaseQuadraticOut => quadratic_out(p),
            EaseQuadraticInOut => quadratic_in_out(p),

            EaseCubicIn => cubic_in(p),
            EaseCubicOut => cubic_out(p),
            EaseCubicInOut => cubic_in_out(p),

            EaseQuarticIn => quartic_in(p),
            EaseQuarticOut => quartic_out(p),
            EaseQuarticInOut => quartic_in_out(p),

            EaseQuinticIn => quintic_in(p),
            EaseQuinticOut => quintic_out(p),
            EaseQuinticInOut => quintic_in_out(p),

            EaseSineIn => sine_in(p),
            EaseSineOut => sine_out(p),
            EaseSineInOut => sine_in_out(p),

            EaseCircularIn => circular_in(p),
            EaseCircularOut => circular_out(p),
            EaseCircularInOut => circular_in_out(p),

            EaseExponentialIn => exponential_in(p),
            EaseExponentialOut => exponential_out(p),
            EaseExponentialInOut => exponential_in_out(p),

            EaseElasticIn => elastic_in(p),
            EaseElasticOut => elastic_out(p),
            EaseElasticInOut => elastic_in_out(p),

            EaseBackIn => back_in(p),
            EaseBackOut => back_out(p),
            EaseBackInOut => back_in_out(p),

            EaseBounceIn => bounce_in(p),
            EaseBounceOut => bounce_out(p),
            EaseBounceInOut => bounce_in_out(p),
        }
    }
}


/// Applies EaseQuadraticIn function to the input value.
/// Value below 0.0 is interpreted as 0.0, and value above 1.0 is interpreted as 1.0.
pub fn quadratic_in<T>(mut p: T) -> T
    where
        T: Float + FromPrimitive
{
    p = normalized(p);
    p * p
}

/// Applies EaseQuadraticOut function to the input value.
/// Value below 0.0 is interpreted as 0.0, and value above 1.0 is interpreted as 1.0.
pub fn quadratic_out<T>(mut p: T) -> T
    where
        T: Float + FromPrimitive
{
    p = normalized(p);
    let _2: T = FromPrimitive::from_f64(2.0).unwrap();
    -(p * (p - _2))
}

/// Applies EaseQuadraticInOut function to the input value.
/// Value below 0.0 is interpreted as 0.0, and value above 1.0 is interpreted as 1.0.
pub fn quadratic_in_out<T>(mut p: T) -> T
    where
        T: Float + FromPrimitive<commit_msg>Removed `Ease` prefix on enum variants<commit_after>
//! A module contains implementation of ease functions.

use std::f64::consts::{
    PI,
    PI_2,
};
use std::num::{
    Float,
    FloatMath,
};

#[allow(missing_docs)]
#[deriving(Copy, Clone, PartialEq)]
pub enum EaseFunction {
    QuadraticIn,
    QuadraticOut,
    QuadraticInOut,

    CubicIn,
    CubicOut,
    CubicInOut,

    QuarticIn,
    QuarticOut,
    QuarticInOut,

    QuinticIn,
    QuinticOut,
    QuinticInOut,

    SineIn,
    SineOut,
    SineInOut,

    CircularIn,
    CircularOut,
    CircularInOut,

    ExponentialIn,
    ExponentialOut,
    ExponentialInOut,

    ElasticIn,
    ElasticOut,
    ElasticInOut,

    BackIn,
    BackOut,
    BackInOut,

    BounceIn,
    BounceOut,
    BounceInOut,
}

impl EaseFunction {
    /// Calculate the eased value, normalized
    pub fn calc<T>(self, p: T) -> T
        where
            T: Float + FromPrimitive + FloatMath
    {
        match self {
            EaseFunction::QuadraticIn => quadratic_in(p),
            EaseFunction::QuadraticOut => quadratic_out(p),
            EaseFunction::QuadraticInOut => quadratic_in_out(p),

            EaseFunction::CubicIn => cubic_in(p),
            EaseFunction::CubicOut => cubic_out(p),
            EaseFunction::CubicInOut => cubic_in_out(p),

            EaseFunction::QuarticIn => quartic_in(p),
            EaseFunction::QuarticOut => quartic_out(p),
            EaseFunction::QuarticInOut => quartic_in_out(p),

            EaseFunction::QuinticIn => quintic_in(p),
            EaseFunction::QuinticOut => quintic_out(p),
            EaseFunction::QuinticInOut => quintic_in_out(p),

            EaseFunction::SineIn => sine_in(p),
            EaseFunction::SineOut => sine_out(p),
            EaseFunction::SineInOut => sine_in_out(p),

            EaseFunction::CircularIn => circular_in(p),
            EaseFunction::CircularOut => circular_out(p),
            EaseFunction::CircularInOut => circular_in_out(p),

            EaseFunction::ExponentialIn => exponential_in(p),
            EaseFunction::ExponentialOut => exponential_out(p),
            EaseFunction::ExponentialInOut => exponential_in_out(p),

            EaseFunction::ElasticIn => elastic_in(p),
            EaseFunction::ElasticOut => elastic_out(p),
            EaseFunction::ElasticInOut => elastic_in_out(p),

            EaseFunction::BackIn => back_in(p),
            EaseFunction::BackOut => back_out(p),
            EaseFunction::BackInOut => back_in_out(p),

            EaseFunction::BounceIn => bounce_in(p),
            EaseFunction::BounceOut => bounce_out(p),
            EaseFunction::BounceInOut => bounce_in_out(p),
        }
    }
}


/// Applies EaseQuadraticIn function to the input value.
/// Value below 0.0 is interpreted as 0.0, and value above 1.0 is interpreted as 1.0.
pub fn quadratic_in<T>(mut p: T) -> T
    where
        T: Float + FromPrimitive
{
    p = normalized(p);
    p * p
}

/// Applies EaseQuadraticOut function to the input value.
/// Value below 0.0 is interpreted as 0.0, and value above 1.0 is interpreted as 1.0.
pub fn quadratic_out<T>(mut p: T) -> T
    where
        T: Float + FromPrimitive
{
    p = normalized(p);
    let _2: T = FromPrimitive::from_f64(2.0).unwrap();
    -(p * (p - _2))
}

/// Applies EaseQuadraticInOut function to the input value.
/// Value below 0.0 is interpreted as 0.0, and value above 1.0 is interpreted as 1.0.
pub fn quadratic_in_out<T>(mut p: T) -> T
    where
        T: Float + FromPrimitive
{'fraction_non_alphanumeric': 0.10384923817161187, 'fraction_numerical': 0.008821170809943865, 'mean_word_length': 2.490205223880597, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3541738', 'n_tokens_mistral': 2716, 'n_tokens_neox': 2592, 'n_words': 521}