Skip to content

Commit 722592d

Browse files
committed
Fix Mesh generator build and test errors
1 parent 33bba7f commit 722592d

File tree

12 files changed

+426
-115
lines changed

12 files changed

+426
-115
lines changed

Modules/Graphics/Mesh/Include/Methane/Graphics/CubeMesh.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Cube mesh generator with customizable vertex type
2525

2626
#include "QuadMesh.hpp"
2727

28+
#include <algorithm>
29+
2830
namespace Methane::Graphics
2931
{
3032

Modules/Graphics/Mesh/Include/Methane/Graphics/IcosahedronMesh.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ class IcosahedronMesh : public BaseMesh<VType>
8585
Mesh::TexCoord& vertex_texcoord = BaseMeshT::template GetVertexField<Mesh::TexCoord>(vertex, Mesh::VertexField::TexCoord);
8686
const Mesh::Position vertex_direction(hlslpp::normalize(vertex_position.AsHlsl()));
8787

88-
vertex_texcoord.SetX(std::atan2(vertex_direction.GetZ(), vertex_direction.GetX()) / (std::numbers::pi * 2.f) + 0.5F);
88+
vertex_texcoord.SetX(std::atan2(vertex_direction.GetZ(), vertex_direction.GetX()) / (std::numbers::pi_v<float> * 2.f) + 0.5F);
8989
assert(0.F <= vertex_texcoord.GetX() && vertex_texcoord.GetX() <= 1.F);
9090

91-
vertex_texcoord.SetY(std::asin(vertex_direction.GetY()) / std::numbers::pi + 0.5F);
91+
vertex_texcoord.SetY(std::asin(vertex_direction.GetY()) / std::numbers::pi_v<float> + 0.5F);
9292
assert(0.F <= vertex_texcoord.GetY() && vertex_texcoord.GetY() <= 1.F);
9393
}
9494
}

Modules/Graphics/Mesh/Include/Methane/Graphics/SphereMesh.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,11 @@ class SphereMesh : public BaseMesh<VType>
114114

115115
VType& vertex = BaseMeshT::GetMutableVertex(vertex_index);
116116

117+
const auto pi = std::numbers::pi_v<float>;
117118
Mesh::Position& vertex_position = BaseMeshT::template GetVertexField<Mesh::Position>(vertex, Mesh::VertexField::Position);
118-
vertex_position.SetX(std::sin(std::numbers::pi * lat_ratio) * std::cos(2.f * std::numbers::pi * long_ratio));
119-
vertex_position.SetZ(std::sin(std::numbers::pi * lat_ratio) * std::sin(2.f * std::numbers::pi * long_ratio));
120-
vertex_position.SetY(std::cos(std::numbers::pi * lat_ratio));
119+
vertex_position.SetX(std::sin(pi * lat_ratio) * std::cos(2.f * pi * long_ratio));
120+
vertex_position.SetZ(std::sin(pi * lat_ratio) * std::sin(2.f * pi * long_ratio));
121+
vertex_position.SetY(std::cos(pi * lat_ratio));
121122

122123
if (has_normals)
123124
{

Modules/Graphics/Mesh/Include/Methane/Graphics/UberMesh.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Uber mesh generator with customizable vertex type
2525

2626
#include "BaseMesh.hpp"
2727

28+
#include <algorithm>
29+
2830
namespace Methane::Graphics
2931
{
3032

Tests/Graphics/Mesh/CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ add_executable(${TARGET}
44
MeshTestHelpers.hpp
55
QuadMeshTest.cpp
66
CubeMeshTest.cpp
7+
SimpleCubeMeshTest.cpp
78
SphereMeshTest.cpp
89
IcosahedronMeshTest.cpp
910
UberMeshTest.cpp
1011
)
1112

1213
target_link_libraries(${TARGET}
1314
PRIVATE
14-
MethaneGraphicsMesh
15-
MethaneBuildOptions
16-
MethaneMathPrecompiledHeaders
17-
MethaneTestsCatchHelpers
18-
$<$<BOOL:${METHANE_TRACY_PROFILING_ENABLED}>:TracyClient>
19-
Catch2WithMain
15+
MethaneGraphicsMesh
16+
MethaneBuildOptions
17+
MethaneMathPrecompiledHeaders
18+
MethaneTestsCatchHelpers
19+
$<$<BOOL:${METHANE_TRACY_PROFILING_ENABLED}>:TracyClient>
20+
Catch2WithMain
2021
)
2122

2223
if(METHANE_PRECOMPILED_HEADERS_ENABLED)
@@ -25,7 +26,7 @@ endif()
2526

2627
set_target_properties(${TARGET}
2728
PROPERTIES
28-
FOLDER Tests
29+
FOLDER Tests
2930
)
3031

3132
install(TARGETS ${TARGET}

Tests/Graphics/Mesh/CubeMeshTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ TEST_CASE("Colored Cube Mesh Generator", "[mesh]")
6262

6363
SECTION("Mesh Data")
6464
{
65-
const std::vector<MeshVertex> mesh_vertices = {
65+
const std::vector<MeshVertex> reference_vertices = {
6666
{ // 0
6767
.position = {-3, -2, 1},
6868
.normal = {0, 0, 1},
@@ -208,7 +208,7 @@ TEST_CASE("Colored Cube Mesh Generator", "[mesh]")
208208
.texcoord = {1, 1}
209209
}
210210
};
211-
CHECK(mesh.GetVertices() == mesh_vertices);
211+
CheckMeshVerticesApproxEquals(mesh.GetVertices(), reference_vertices);
212212

213213
const Mesh::Indices mesh_indices = {
214214
// Front

Tests/Graphics/Mesh/IcosahedronMeshTest.cpp

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Icosahedron mesh generator unit tests
3030
#include "MeshTestHelpers.hpp"
3131

3232
#include <catch2/catch_test_macros.hpp>
33+
#include <catch2/catch_approx.hpp>
3334
#include <fmt/format.h>
3435
#include <string>
3536

@@ -59,66 +60,66 @@ TEST_CASE("Icosahedron Mesh Generator", "[mesh]")
5960

6061
SECTION("Mesh Data")
6162
{
62-
const std::vector<MeshVertex> mesh_vertices = {
63+
const std::vector<MeshVertex> reference_vertices = {
6364
{ // 0
64-
.position = {-3, 3.4364917, 0},
65-
.normal = {-0.65764374, 0.7533291, 0},
66-
.texcoord = {1, 0.7715532}
65+
.position = {-3.F, 3.436F, 0.F},
66+
.normal = {-0.658F, 0.753F, 0.F},
67+
.texcoord = {1.F, 0.771F}
6768
},
6869
{ // 1
69-
.position = {3, 3.4364917, 0},
70-
.normal = {0.65764374, 0.7533291, 0},
71-
.texcoord = {0.5, 0.7715532}
70+
.position = {3.F, 3.436F, 0.F},
71+
.normal = {0.658F, 0.753F, 0.F},
72+
.texcoord = {0.5F, 0.771F}
7273
},
7374
{ // 2
74-
.position = {-3, -3.4364917, 0},
75-
.normal = {-0.65764374, -0.7533291, 0},
76-
.texcoord = {1, 0.22844677}
75+
.position = {-3.F, -3.436F, 0.F},
76+
.normal = {-0.658F, -0.753F, 0.F},
77+
.texcoord = {1.F, 0.228F}
7778
},
7879
{ // 3
79-
.position = {3, -3.4364917, 0},
80-
.normal = {0.65764374, -0.7533291, 0},
81-
.texcoord = {0.5, 0.22844677}
80+
.position = {3.F, -3.436F, 0.F},
81+
.normal = {0.658F, -0.753F, 0.F},
82+
.texcoord = {0.5F, 0.228F}
8283
},
8384
{ // 4
84-
.position = {0, -3, 3.4364917},
85-
.normal = {0, -0.65764374, 0.7533291},
86-
.texcoord = {0.75, 0.27155325}
85+
.position = {0.F, -3.F, 3.436F},
86+
.normal = {0.F, -0.658F, 0.753F},
87+
.texcoord = {0.75F, 0.271F}
8788
},
8889
{ // 5
89-
.position = {0, 3, 3.4364917},
90-
.normal = {0, 0.65764374, 0.7533291},
91-
.texcoord = {0.75, 0.7284468}
90+
.position = {0.F, 3.F, 3.436F},
91+
.normal = {0.F, 0.658F, 0.753F},
92+
.texcoord = {0.75F, 0.728F}
9293
},
9394
{ // 6
94-
.position = {0, -3, -3.4364917},
95-
.normal = {0, -0.65764374, -0.7533291},
96-
.texcoord = {0.25, 0.27155325}
95+
.position = {0.F, -3.F, -3.436F},
96+
.normal = {0.F, -0.658F, -0.753F},
97+
.texcoord = {0.25F, 0.271F}
9798
},
9899
{ // 7
99-
.position = {0, 3, -3.4364917},
100-
.normal = {0, 0.65764374, -0.7533291},
101-
.texcoord = {0.25, 0.7284468}
100+
.position = {0.F, 3.F, -3.436F},
101+
.normal = {0.F, 0.658F, -0.753F},
102+
.texcoord = {0.25F, 0.728F}
102103
},
103104
{ // 8
104-
.position = {3.4364917, 0, -3},
105-
.normal = {0.7533291, 0, -0.65764374},
106-
.texcoord = {0.3857766, 0.5}
105+
.position = {3.436F, 0.F, -3.F},
106+
.normal = {0.753F, 0.F, -0.658F},
107+
.texcoord = {0.386F, 0.5F}
107108
}, {
108-
.position = {3.4364917, 0, 3},
109-
.normal = {0.7533291, 0, 0.65764374},
110-
.texcoord = {0.61422336, 0.5}
109+
.position = {3.436F, 0.F, 3.F},
110+
.normal = {0.753F, 0.F, 0.658F},
111+
.texcoord = {0.614F, 0.5F}
111112
}, {
112-
.position = {-3.4364917, 0, -3},
113-
.normal = {-0.7533291, 0, -0.65764374},
114-
.texcoord = {0.11422336, 0.5}
113+
.position = {-3.436F, 0.F, -3.F},
114+
.normal = {-0.753F, 0.F, -0.658F},
115+
.texcoord = {0.1142F, 0.5F}
115116
}, {
116-
.position = {-3.4364917, 0, 3},
117-
.normal = {-0.7533291, 0, 0.65764374},
118-
.texcoord = {0.88577664, 0.5}
117+
.position = {-3.436F, 0.F, 3.F},
118+
.normal = {-0.753F, 0.F, 0.658F},
119+
.texcoord = {0.886F, 0.5F}
119120
}
120121
};
121-
CHECK(mesh.GetVertices() == mesh_vertices);
122+
CheckMeshVerticesApproxEquals(mesh.GetVertices(), reference_vertices);
122123

123124
const Mesh::Indices mesh_indices = {
124125
5, 0, 11,

0 commit comments

Comments
 (0)