Skip to content

Commit b3efa49

Browse files
committed
Use std-namespaced math functions and cmath header
This should fix a reported issue with building for Android with C++23 enabled.
1 parent 6851f41 commit b3efa49

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

Source/Core/Element.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "../../Include/RmlUi/Core/ElementScroll.h"
3636
#include "../../Include/RmlUi/Core/ElementUtilities.h"
3737
#include "../../Include/RmlUi/Core/Factory.h"
38+
#include "../../Include/RmlUi/Core/Math.h"
3839
#include "../../Include/RmlUi/Core/Profiling.h"
3940
#include "../../Include/RmlUi/Core/PropertiesIteratorView.h"
4041
#include "../../Include/RmlUi/Core/PropertyDefinition.h"
@@ -769,7 +770,7 @@ bool Element::Project(Vector2f& point) const noexcept
769770
Vector3f ray = local_points[1] - local_points[0];
770771

771772
// Only continue if we are not close to parallel with the plane.
772-
if (std::fabs(ray.z) > 1.0f)
773+
if (Math::Absolute(ray.z) > 1.0f)
773774
{
774775
// Solving the line equation p = p0 + t*ray for t, knowing that p.z = 0, produces the following.
775776
float t = -local_points[0].z / ray.z;

Source/Core/Math.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828

2929
#include "../../Include/RmlUi/Core/Math.h"
3030
#include "../../Include/RmlUi/Core/Types.h"
31-
#include <math.h>
32-
#include <stdlib.h>
33-
#include <time.h>
31+
#include <cmath>
32+
#include <cstdlib>
3433

3534
namespace Rml {
3635

@@ -45,52 +44,52 @@ namespace Math {
4544

4645
RMLUICORE_API float Absolute(float value)
4746
{
48-
return fabsf(value);
47+
return std::abs(value);
4948
}
5049

5150
RMLUICORE_API int Absolute(int value)
5251
{
53-
return abs(value);
52+
return std::abs(value);
5453
}
5554

5655
RMLUICORE_API Vector2f Absolute(Vector2f value)
5756
{
58-
return {fabsf(value.x), fabsf(value.y)};
57+
return {std::abs(value.x), std::abs(value.y)};
5958
}
6059

6160
RMLUICORE_API float Cos(float angle)
6261
{
63-
return cosf(angle);
62+
return std::cos(angle);
6463
}
6564

6665
RMLUICORE_API float ACos(float value)
6766
{
68-
return acosf(value);
67+
return std::acos(value);
6968
}
7069

7170
RMLUICORE_API float Sin(float angle)
7271
{
73-
return sinf(angle);
72+
return std::sin(angle);
7473
}
7574

7675
RMLUICORE_API float ASin(float value)
7776
{
78-
return asinf(value);
77+
return std::asin(value);
7978
}
8079

8180
RMLUICORE_API float Tan(float angle)
8281
{
83-
return tanf(angle);
82+
return std::tan(angle);
8483
}
8584

8685
RMLUICORE_API float ATan2(float y, float x)
8786
{
88-
return atan2f(y, x);
87+
return std::atan2(y, x);
8988
}
9089

9190
RMLUICORE_API float Exp(float value)
9291
{
93-
return expf(value);
92+
return std::exp(value);
9493
}
9594

9695
RMLUICORE_API int Log2(int value)
@@ -116,35 +115,35 @@ namespace Math {
116115

117116
RMLUICORE_API float NormaliseAngle(float angle)
118117
{
119-
float result = fmodf(angle, RMLUI_PI * 2.0f);
118+
float result = std::fmod(angle, RMLUI_PI * 2.0f);
120119
if (result < 0.f)
121120
result += RMLUI_PI * 2.0f;
122121
return result;
123122
}
124123

125124
RMLUICORE_API float SquareRoot(float value)
126125
{
127-
return sqrtf(value);
126+
return std::sqrt(value);
128127
}
129128

130129
RMLUICORE_API float Round(float value)
131130
{
132-
return floorf(value + 0.5f);
131+
return std::floor(value + 0.5f);
133132
}
134133

135134
RMLUICORE_API double Round(double value)
136135
{
137-
return floor(value + 0.5);
136+
return std::floor(value + 0.5);
138137
}
139138

140139
RMLUICORE_API float RoundUp(float value)
141140
{
142-
return ceilf(value);
141+
return std::ceil(value);
143142
}
144143

145144
RMLUICORE_API float RoundDown(float value)
146145
{
147-
return floorf(value);
146+
return std::floor(value);
148147
}
149148

150149
RMLUICORE_API int RoundToInteger(float value)
@@ -157,17 +156,17 @@ namespace Math {
157156

158157
RMLUICORE_API int RoundUpToInteger(float value)
159158
{
160-
return int(ceilf(value));
159+
return int(std::ceil(value));
161160
}
162161

163162
RMLUICORE_API int RoundDownToInteger(float value)
164163
{
165-
return int(floorf(value));
164+
return int(std::floor(value));
166165
}
167166

168167
RMLUICORE_API float DecomposeFractionalIntegral(float value, float* integral)
169168
{
170-
return modff(value, integral);
169+
return std::modf(value, integral);
171170
}
172171

173172
RMLUICORE_API void SnapToPixelGrid(float& offset, float& width)
@@ -238,12 +237,12 @@ namespace Math {
238237

239238
RMLUICORE_API float RandomReal(float max_value)
240239
{
241-
return (rand() / (float)RAND_MAX) * max_value;
240+
return (std::rand() / (float)RAND_MAX) * max_value;
242241
}
243242

244243
RMLUICORE_API int RandomInteger(int max_value)
245244
{
246-
return (rand() % max_value);
245+
return (std::rand() % max_value);
247246
}
248247

249248
RMLUICORE_API bool RandomBool()

0 commit comments

Comments
 (0)