LCOV - code coverage report
Current view: top level - source/maths - MathUtil.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 8 17 47.1 %
Date: 2023-01-19 00:18:29 Functions: 7 13 53.8 %

          Line data    Source code
       1             : /* Copyright (C) 2022 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef INCLUDED_MATHUTIL
      19             : #define INCLUDED_MATHUTIL
      20             : 
      21             : #define DEGTORAD(a)                 ((a) * ((float)M_PI/180.0f))
      22             : #define RADTODEG(a)                 ((a) * (180.0f/(float)M_PI))
      23             : #define SQR(x)                      ((x) * (x))
      24             : 
      25             : template<typename T>
      26          83 : inline T Interpolate(const T& a, const T& b, float t)
      27             : {
      28          83 :     return a + (b - a) * t;
      29             : }
      30             : 
      31             : template<typename T>
      32    14368738 : inline T Clamp(T value, T min, T max)
      33             : {
      34    14368738 :     if (value <= min)
      35      666831 :         return min;
      36    13701907 :     else if (value >= max)
      37      500990 :         return max;
      38    13200917 :     return value;
      39             : }
      40             : 
      41             : template<typename T>
      42           0 : inline T SmoothStep(T edge0, T edge1, T value)
      43             : {
      44           0 :     value = Clamp<T>((value - edge0) / (edge1 - edge0), 0, 1); 
      45           0 :     return value * value * (3 - 2 * value);
      46             : }
      47             : 
      48             : template<typename T>
      49           0 : inline T Sign(const T value)
      50             : {
      51           0 :     if (value > T(0))
      52           0 :         return T(1);
      53           0 :     if (value < T(0))
      54           0 :         return T(-1);
      55           0 :     return T(0);
      56             : }
      57             : 
      58             : #endif // INCLUDED_MATHUTIL

Generated by: LCOV version 1.13