libRocket
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Math.h
Go to the documentation of this file.
1 /*
2  * This source file is part of libRocket, the HTML/CSS Interface Middleware
3  *
4  * For the latest information, see http://www.librocket.com
5  *
6  * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  *
26  */
27 
28 #ifndef ROCKETCOREMATH_H
29 #define ROCKETCOREMATH_H
30 
31 #include "Header.h"
32 
33 namespace Rocket {
34 namespace Core {
35 namespace Math {
36 
37 // The constant PI.
38 extern ROCKETCORE_API const float ROCKET_PI;
39 
40 template < typename Type >
41 Type Max(Type a, Type b)
42 {
43  return (a > b) ? a : b;
44 }
45 
46 template< typename Type >
47 Type Min(Type a, Type b)
48 {
49  return (a < b) ? a : b;
50 }
51 
52 template < typename Type >
53 Type ClampLower(Type value, Type min)
54 {
55  return (value < min) ? min : value;
56 }
57 
58 template < typename Type >
59 Type ClampUpper(Type value, Type max)
60 {
61  return (value > max) ? max: value;
62 }
63 
64 template< typename Type >
65 Type Clamp(Type value, Type min, Type max)
66 {
67  return (value < min) ? min : (value > max) ? max : value;
68 }
69 
73 ROCKETCORE_API bool IsZero(float value);
79 ROCKETCORE_API bool AreEqual(float value_0, float value_1);
80 
84 ROCKETCORE_API float AbsoluteValue(float value);
85 
89 ROCKETCORE_API float Cos(float angle);
93 ROCKETCORE_API float ACos(float value);
97 ROCKETCORE_API float Sin(float angle);
101 ROCKETCORE_API float ASin(float angle);
105 ROCKETCORE_API float Tan(float angle);
110 ROCKETCORE_API float ATan2(float y, float x);
111 
115 ROCKETCORE_API float RadiansToDegrees(float angle);
119 ROCKETCORE_API float DegreesToRadians(float angle);
123 ROCKETCORE_API float NormaliseAngle(float angle);
124 
128 ROCKETCORE_API float SquareRoot(float value);
129 
133 ROCKETCORE_API int Round(float value);
137 ROCKETCORE_API int RoundUp(float value);
141 ROCKETCORE_API int RoundDown(float value);
142 
146 ROCKETCORE_API int RealToInteger(float value);
147 
151 ROCKETCORE_API int ToPowerOfTwo(int value);
152 
156 ROCKETCORE_API int HexToDecimal(char hex_digit);
157 
161 ROCKETCORE_API float RandomReal(float max_value);
165 ROCKETCORE_API int RandomInteger(int max_value);
169 
170 }
171 }
172 }
173 
174 #endif
Type Min(Type a, Type b)
Definition: Math.h:47
#define ROCKETCORE_API
Definition: Header.h:73
ROCKETCORE_API int RoundUp(float value)
ROCKETCORE_API float Sin(float angle)
ROCKETCORE_API float Cos(float angle)
Type Clamp(Type value, Type min, Type max)
Definition: Math.h:65
ROCKETCORE_API float NormaliseAngle(float angle)
Definition: Clipboard.h:33
ROCKETCORE_API int RoundDown(float value)
ROCKETCORE_API float AbsoluteValue(float value)
ROCKETCORE_API bool RandomBool()
ROCKETCORE_API float ACos(float value)
ROCKETCORE_API bool IsZero(float value)
ROCKETCORE_API int RandomInteger(int max_value)
Type ClampUpper(Type value, Type max)
Definition: Math.h:59
ROCKETCORE_API float RandomReal(float max_value)
ROCKETCORE_API float DegreesToRadians(float angle)
ROCKETCORE_API int ToPowerOfTwo(int value)
ROCKETCORE_API float Tan(float angle)
ROCKETCORE_API int RealToInteger(float value)
Type ClampLower(Type value, Type min)
Definition: Math.h:53
ROCKETCORE_API bool AreEqual(float value_0, float value_1)
ROCKETCORE_API float ATan2(float y, float x)
Type Max(Type a, Type b)
Definition: Math.h:41
ROCKETCORE_API const float ROCKET_PI
ROCKETCORE_API float SquareRoot(float value)
ROCKETCORE_API float ASin(float angle)
ROCKETCORE_API float RadiansToDegrees(float angle)
ROCKETCORE_API int HexToDecimal(char hex_digit)
ROCKETCORE_API int Round(float value)