Math.h

00001 /*
00002  * This source file is part of libRocket, the HTML/CSS Interface Middleware
00003  *
00004  * For the latest information, see http://www.librocket.com
00005  *
00006  * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a copy
00009  * of this software and associated documentation files (the "Software"), to deal
00010  * in the Software without restriction, including without limitation the rights
00011  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012  * copies of the Software, and to permit persons to whom the Software is
00013  * furnished to do so, subject to the following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included in
00016  * all copies or substantial portions of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024  * THE SOFTWARE.
00025  *
00026  */
00027 
00028 #ifndef ROCKETCOREMATH_H
00029 #define ROCKETCOREMATH_H
00030 
00031 #include <Rocket/Core/Header.h>
00032 
00033 namespace Rocket {
00034 namespace Core {
00035 namespace Math {
00036 
00037 // The constant PI / 2.
00038 extern ROCKETCORE_API const float PI_BY_TWO;
00039 // The constant PI.
00040 extern ROCKETCORE_API const float PI;
00041 // The constant 2 * PI / 3.
00042 extern ROCKETCORE_API const float TWO_PI_BY_THREE;
00043 // The constant 2 * PI.
00044 extern ROCKETCORE_API const float TWO_PI;
00045 
00046 
00047 template < typename Type >
00048 Type Max(Type a, Type b)
00049 {
00050         return (a > b) ? a : b;
00051 }
00052 
00053 template< typename Type >
00054 Type Min(Type a, Type b)
00055 {
00056         return (a < b) ? a : b;
00057 }
00058 
00059 template < typename Type >
00060 Type ClampLower(Type value, Type min)
00061 {
00062         return (value < min) ? min : value;
00063 }
00064 
00065 template < typename Type >
00066 Type ClampUpper(Type value, Type max)
00067 {
00068         return (value > max) ? max: value;
00069 }
00070 
00071 template< typename Type >
00072 Type Clamp(Type value, Type min, Type max)
00073 {
00074         return (value < min) ? min : (value > max) ? max : value;
00075 }
00076 
00080 ROCKETCORE_API bool IsZero(float value);
00086 ROCKETCORE_API bool AreEqual(float value_0, float value_1);
00087 
00091 ROCKETCORE_API float AbsoluteValue(float value);
00092 
00096 ROCKETCORE_API float Cos(float angle);
00100 ROCKETCORE_API float ACos(float value);
00104 ROCKETCORE_API float Sin(float angle);
00108 ROCKETCORE_API float ASin(float angle);
00112 ROCKETCORE_API float Tan(float angle);
00117 ROCKETCORE_API float ATan2(float y, float x);
00118 
00122 ROCKETCORE_API float RadiansToDegrees(float angle);
00126 ROCKETCORE_API float DegreesToRadians(float angle);
00130 ROCKETCORE_API float NormaliseAngle(float angle);
00131 
00135 ROCKETCORE_API float SquareRoot(float value);
00136 
00140 ROCKETCORE_API int Round(float value);
00144 ROCKETCORE_API int RoundUp(float value);
00148 ROCKETCORE_API int RoundDown(float value);
00149 
00153 ROCKETCORE_API int RealToInteger(float value);
00154 
00158 ROCKETCORE_API int ToPowerOfTwo(int value);
00159 
00163 ROCKETCORE_API int HexToDecimal(char hex_digit);
00164 
00168 ROCKETCORE_API float RandomReal(float max_value);
00172 ROCKETCORE_API int RandomInteger(int max_value);
00175 ROCKETCORE_API bool RandomBool();
00176 
00177 }
00178 }
00179 }
00180 
00181 #endif