1 | /** |
2 | * Copyright (c) 2006-2023 LOVE Development Team |
3 | * |
4 | * This software is provided 'as-is', without any express or implied |
5 | * warranty. In no event will the authors be held liable for any damages |
6 | * arising from the use of this software. |
7 | * |
8 | * Permission is granted to anyone to use this software for any purpose, |
9 | * including commercial applications, and to alter it and redistribute it |
10 | * freely, subject to the following restrictions: |
11 | * |
12 | * 1. The origin of this software must not be misrepresented; you must not |
13 | * claim that you wrote the original software. If you use this software |
14 | * in a product, an acknowledgment in the product documentation would be |
15 | * appreciated but is not required. |
16 | * 2. Altered source versions must be plainly marked as such, and must not be |
17 | * misrepresented as being the original software. |
18 | * 3. This notice may not be removed or altered from any source distribution. |
19 | **/ |
20 | |
21 | #ifndef LOVE_MATH_H |
22 | #define LOVE_MATH_H |
23 | |
24 | #include <climits> // for CHAR_BIT |
25 | #include <cstdlib> // for rand() and RAND_MAX |
26 | |
27 | /* Definitions of useful mathematical constants |
28 | * M_E - e |
29 | * M_LOG2E - log2(e) |
30 | * M_LOG10E - log10(e) |
31 | * M_LN2 - ln(2) |
32 | * M_LN10 - ln(10) |
33 | * M_PI - pi |
34 | * M_PI_2 - pi/2 |
35 | * M_PI_4 - pi/4 |
36 | * M_1_PI - 1/pi |
37 | * M_2_PI - 2/pi |
38 | * M_2_SQRTPI - 2/sqrt(pi) |
39 | * M_SQRT2 - sqrt(2) |
40 | * M_SQRT1_2 - 1/sqrt(2) |
41 | */ |
42 | |
43 | #define LOVE_M_E 2.71828182845904523536 |
44 | #define LOVE_M_LOG2E 1.44269504088896340736 |
45 | #define LOVE_M_LOG10E 0.434294481903251827651 |
46 | #define LOVE_M_LN2 0.693147180559945309417 |
47 | #define LOVE_M_LN10 2.30258509299404568402 |
48 | #define LOVE_M_PI 3.14159265358979323846 |
49 | #define LOVE_M_PI_2 1.57079632679489661923 |
50 | #define LOVE_M_PI_4 0.785398163397448309616 |
51 | #define LOVE_M_1_PI 0.318309886183790671538 |
52 | #define LOVE_M_2_PI 0.636619772367581343076 |
53 | #define LOVE_M_2_SQRTPI 1.12837916709551257390 |
54 | #define LOVE_M_SQRT2 1.41421356237309504880 |
55 | #define LOVE_M_SQRT1_2 0.707106781186547524401 |
56 | #define LOVE_M_TORAD (float)(LOVE_M_PI/180.0) |
57 | #define LOVE_M_TODEG (float)(180.0/LOVE_M_PI) |
58 | #define LOVE_TORAD(x) (float)(x*LOVE_M_TORAD) |
59 | #define LOVE_TODEG(x) (float)(x*LOVE_M_TODEG) |
60 | |
61 | namespace love |
62 | { |
63 | |
64 | struct Rect |
65 | { |
66 | int x, y; |
67 | int w, h; |
68 | |
69 | bool operator == (const Rect &rhs) const |
70 | { |
71 | return x == rhs.x && y == rhs.y && w == rhs.w && h == rhs.h; |
72 | } |
73 | }; |
74 | |
75 | inline int nextP2(int x) |
76 | { |
77 | x += (x == 0); |
78 | x--; |
79 | for (unsigned int i = 1; i < sizeof(int)*CHAR_BIT; i <<= 1) x |= x >> i; |
80 | return ++x; |
81 | } |
82 | |
83 | inline float nextP2(float x) |
84 | { |
85 | return (float) nextP2((int) x); |
86 | } |
87 | |
88 | } // love |
89 | |
90 | #endif // LOVE_MATH_H |
91 | |