Skip to content

Commit af6dc32

Browse files
authored
Merge pull request #1 from VictorSohier/jon/common-defs
Migrate HEAD:master to stdtypes
2 parents 531ffab + 13767b3 commit af6dc32

19 files changed

Lines changed: 348 additions & 346 deletions

engine/native/core/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_modules_library(definitions PIC)
22
add_modules_library(math)
33
add_modules_library(memory)
4-
target_link_libraries(math PUBLIC definitions)
4+
target_link_libraries(math PUBLIC definitions)
5+
target_link_libraries(memory PUBLIC definitions)

engine/native/core/definitions/definitions.cppm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module;
44

55
export module core.defs;
66
export import core.version;
7+
export import core.stdtypes;
78

89
static_assert(__cplusplus >= 202207L, "Minimum of C++23 required. Consider upgrading your compiler.");
910

engine/native/core/math/constants.cppm

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ export namespace draco::math {
1111
// Limit the depth of recursive algorithms
1212
constexpr int MAX_RECURSIONS = 100;
1313

14-
constexpr float SQRT2 = std::numbers::sqrt2_v<float>;
15-
constexpr float SQRT3 = std::numbers::sqrt3_v<float>;
16-
constexpr float SQRT12 = 1. / SQRT2;
17-
constexpr float SQRT13 = std::numbers::inv_sqrt3_v<float>;
18-
constexpr float LN2 = std::numbers::ln2_v<float>;
19-
constexpr float LN10 = std::numbers::ln10_v<float>;
20-
constexpr float PI = std::numbers::pi_v<float>;
21-
constexpr float PI2 = PI * .5;
22-
constexpr float TAU = 2. * PI;
23-
constexpr float E = std::numbers::e_v<float>;
24-
constexpr float INF = std::numeric_limits<float>::infinity();
25-
constexpr float NaN = std::numeric_limits<float>::quiet_NaN();
26-
constexpr float DB_CONVERSION_GAIN = 8.6858896380650365530225783783321;
27-
constexpr float GAIN_CONVERSION_DB = 0.11512925464970228420089957273422;
28-
constexpr float UINT32_MAX_F = 1.f / std::numeric_limits<u32>::max();
29-
constexpr float DECIMAL_LIMIT_F = 8388608.0f;
14+
constexpr f32 SQRT2 = std::numbers::sqrt2_v<f32>;
15+
constexpr f32 SQRT3 = std::numbers::sqrt3_v<f32>;
16+
constexpr f32 SQRT12 = 1. / SQRT2;
17+
constexpr f32 SQRT13 = std::numbers::inv_sqrt3_v<f32>;
18+
constexpr f32 LN2 = std::numbers::ln2_v<f32>;
19+
constexpr f32 LN10 = std::numbers::ln10_v<f32>;
20+
constexpr f32 PI = std::numbers::pi_v<f32>;
21+
constexpr f32 PI2 = PI * .5;
22+
constexpr f32 TAU = 2. * PI;
23+
constexpr f32 E = std::numbers::e_v<f32>;
24+
constexpr f32 INF = std::numeric_limits<f32>::infinity();
25+
constexpr f32 NaN = std::numeric_limits<f32>::quiet_NaN();
26+
constexpr f32 DB_CONVERSION_GAIN = 8.6858896380650365530225783783321;
27+
constexpr f32 GAIN_CONVERSION_DB = 0.11512925464970228420089957273422;
28+
constexpr f32 UINT32_MAX_F = 1.f / std::numeric_limits<u32>::max();
29+
constexpr f32 DECIMAL_LIMIT_F = 8388608.0f;
3030

31-
constexpr float CMP_EPSILON = 0.000001f;
32-
constexpr float CMP_EPSILON2 = CMP_EPSILON * CMP_EPSILON;
31+
constexpr f32 CMP_EPSILON = 0.000001f;
32+
constexpr f32 CMP_EPSILON2 = CMP_EPSILON * CMP_EPSILON;
3333

34-
constexpr float CMP_NORMALIZE_TOLERANCE = 0.000001f;
35-
constexpr float CMP_NORMALIZE_TOLERANCE2 = CMP_NORMALIZE_TOLERANCE * CMP_NORMALIZE_TOLERANCE;
36-
constexpr float CMP_POINT_IN_PLANE_EPSILON = 0.00001f;
34+
constexpr f32 CMP_NORMALIZE_TOLERANCE = 0.000001f;
35+
constexpr f32 CMP_NORMALIZE_TOLERANCE2 = CMP_NORMALIZE_TOLERANCE * CMP_NORMALIZE_TOLERANCE;
36+
constexpr f32 CMP_POINT_IN_PLANE_EPSILON = 0.00001f;
3737
}

engine/native/core/math/functions.cppm

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module;
88
export module core.math.functions;
99
import core.math.constants;
1010
import core.defs;
11+
import core.stdtypes;
1112

1213
export namespace draco::math {
1314
template <arithmetic T>
@@ -32,7 +33,7 @@ export namespace draco::math {
3233
template <arithmetic T>
3334
constexpr T abs(T value) noexcept {
3435
// Manually compute abs for signed types.
35-
// Also avoids potential int8_t -> int issues.
36+
// Also avoids potential i8 -> i32 issues.
3637
if constexpr (std::floating_point<T>) {
3738
return value < T{0} ? -value : value;
3839
} else if constexpr (std::signed_integral<T>) {
@@ -65,27 +66,27 @@ export namespace draco::math {
6566
}
6667
}
6768

68-
constexpr float floor(float value) noexcept {
69+
constexpr f32 floor(f32 value) noexcept {
6970
if (value != value || abs(value) >= DECIMAL_LIMIT_F) {
7071
return value;
7172
}
72-
const float truncated = static_cast<int>(value);
73+
const f32 truncated = static_cast<i32>(value);
7374
return truncated - (value < truncated);
7475
}
7576

76-
constexpr float ceil(float value) noexcept {
77+
constexpr f32 ceil(f32 value) noexcept {
7778
return -floor(-value);
7879
}
7980

80-
constexpr float trunc(float value) noexcept {
81+
constexpr f32 trunc(f32 value) noexcept {
8182
if (value != value || abs(value) >= DECIMAL_LIMIT_F) {
8283
return value;
8384
}
84-
return static_cast<int>(value);
85+
return static_cast<i32>(value);
8586
}
8687

87-
constexpr float round(float value) noexcept {
88-
const float s = sign(value);
88+
constexpr f32 round(f32 value) noexcept {
89+
const f32 s = sign(value);
8990
return s * floor(s * value + 0.5f);
9091
}
9192

engine/native/core/math/math.cppm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export import core.math.constants;
44
export import core.math.functions;
55
export import core.math.types;
66
export import core.defs;
7+
export import core.stdtypes;

engine/native/core/math/math.test.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131

3232
import core.math;
3333

34+
using namespace draco;
35+
3436
TEST_SUITE("math") {
3537
TEST_CASE("pow") {
36-
float result = draco::math::pow(2.0f, 0.5f);
37-
constexpr float expected = draco::math::SQRT2;
38+
f32 result = draco::math::pow(2.0f, 0.5f);
39+
constexpr f32 expected = draco::math::SQRT2;
3840
CHECK_EQ(result, expected);
3941
}
4042

@@ -308,8 +310,8 @@ TEST_SUITE("vector2") {
308310
);
309311

310312
SUBCASE("float") {
311-
static constexpr float smaller_length = 1.0f;
312-
static constexpr float larger_length = 10.0f;
313+
static constexpr f32 smaller_length = 1.0f;
314+
static constexpr f32 larger_length = 10.0f;
313315

314316
const Vector2 result_smaller = min_length(a, smaller_length);
315317
const Vector2 result_swapped = min_length(smaller_length, a);
@@ -357,8 +359,8 @@ TEST_SUITE("vector2") {
357359
);
358360

359361
SUBCASE("float") {
360-
static constexpr float smaller_length = 1.0f;
361-
static constexpr float larger_length = 10.0f;
362+
static constexpr f32 smaller_length = 1.0f;
363+
static constexpr f32 larger_length = 10.0f;
362364

363365
const Vector2 result_smaller = max_length(a, smaller_length);
364366
const Vector2 result_swapped = max_length(larger_length, a);
@@ -763,8 +765,8 @@ TEST_SUITE("vector3") {
763765
);
764766

765767
SUBCASE("float") {
766-
static constexpr float smaller_length = 1.0f;
767-
static constexpr float larger_length = 10.0f;
768+
static constexpr f32 smaller_length = 1.0f;
769+
static constexpr f32 larger_length = 10.0f;
768770

769771
const Vector3 result_smaller = min_length(a, smaller_length);
770772
const Vector3 result_swapped = min_length(smaller_length, a);
@@ -812,8 +814,8 @@ TEST_SUITE("vector3") {
812814
);
813815

814816
SUBCASE("float") {
815-
static constexpr float smaller_length = 1.0f;
816-
static constexpr float larger_length = 10.0f;
817+
static constexpr f32 smaller_length = 1.0f;
818+
static constexpr f32 larger_length = 10.0f;
817819

818820
const Vector3 result_smaller = max_length(a, smaller_length);
819821
const Vector3 result_swapped = max_length(larger_length, a);
@@ -1254,8 +1256,8 @@ TEST_SUITE("vector4") {
12541256
);
12551257

12561258
SUBCASE("float") {
1257-
static constexpr float smaller_length = 1.0f;
1258-
static constexpr float larger_length = 10.0f;
1259+
static constexpr f32 smaller_length = 1.0f;
1260+
static constexpr f32 larger_length = 10.0f;
12591261

12601262
const Vector4 result_smaller = min_length(a, smaller_length);
12611263
const Vector4 result_swapped = min_length(smaller_length, a);
@@ -1303,8 +1305,8 @@ TEST_SUITE("vector4") {
13031305
);
13041306

13051307
SUBCASE("float") {
1306-
static constexpr float smaller_length = 1.0f;
1307-
static constexpr float larger_length = 10.0f;
1308+
static constexpr f32 smaller_length = 1.0f;
1309+
static constexpr f32 larger_length = 10.0f;
13081310

13091311
const Vector4 result_smaller = max_length(a, smaller_length);
13101312
const Vector4 result_swapped = max_length(larger_length, a);

0 commit comments

Comments
 (0)