//! @warning Use it at your own risk. //! @copyright *this file is FREEWARE. //! @file clamper.hpp //! @author Dejan D. M. Milosavljevic //! @version 1.1 //! @date 2003 //! @description Several methods for clamping. //! @warning Use it at your own risk. //! @copyright *this file is FREEWARE. #ifndef _DDMRM_clamper_HPP_ #define _DDMRM_clamper_HPP_ #include //namespace S_DDMRM //{ //namespace S_math //{ template< typename N_scalar > //_____/----- inline N_scalar ramp ( N_scalar const& P_val ,N_scalar const& P_lo = N_scalar( 0 ) ,N_scalar const& P_hi = N_scalar( 1 ) ) { return ( (P_val) < P_lo ? P_lo : ( P_hi < (P_val) ? P_hi : (P_val) ) ) ; } template< typename N_scalar > // //// N_scalar saw ( N_scalar const& P_val, N_scalar const& P_lo = N_scalar ( 0 ), N_scalar const& P_hi = N_scalar ( 1 ) ) { return ( P_lo < P_val? ( N_scalar( ::fmod( P_val - P_lo, P_hi - P_lo ) ) + P_lo ): ( P_hi - N_scalar( ::fmod( P_lo - P_val, P_hi - P_lo ) ) ) ); } template< typename N_scalar > // /\/\/\/\/ N_scalar wave ( N_scalar const& P_val ,N_scalar const& P_lo = N_scalar ( 0 ) ,N_scalar const& P_hi = N_scalar ( 1 ) ) { N_scalar Ir_result; N_scalar I_size = P_hi - P_lo; if( P_lo < P_val ) { Ir_result = N_scalar( ::fmod( P_val - P_lo, 2 * I_size ) ); } else { Ir_result = N_scalar( ::fmod( P_lo - P_val, 2 * I_size ) ); } if( I_size < Ir_result ) Ir_result = - Ir_result + 2 * I_size; Ir_result += P_lo; return Ir_result; } template< typename N_scalar > N_scalar to_one ( N_scalar const& P_val //!< what goes to [0,1] ,N_scalar const& P_left //!< left side of interval ,N_scalar const& P_right //!< right side of interval ) { return ( P_val - P_left ) / ( P_right - P_left ); } // } // } #endif