17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-01 13:44:49 +01:00

fix(editor): the heights from point to point broke the grade only at the bends of straights which stay bends, a curve traced or bends clicked close along a curve going at one grade from one of its ends to the other, attached there; and two tracks laid no longer meet at two heights where a point was clicked within 5 m of their joint, each end of a piece not cut there taking the height of its own stretch, not of the one the middle of the piece lies on (steps of 0.6 m on a steep grade in abc). Unit tests of the heights from point to point

This commit is contained in:
maj00r
2026-10-24 22:28:43 +02:00
parent 4602f727bb
commit 133ba9cb45
6 changed files with 70 additions and 4 deletions

View File

@@ -17,6 +17,9 @@ add_executable(${UNIT_TESTS_NAME}
editor_stubs.cpp
# the geometry of the lines the track editor designs, standing on its own
"${CMAKE_SOURCE_DIR}/editor/editorAlignment.cpp"
# and the heights of the tracks laid
"${CMAKE_SOURCE_DIR}/editor/editorGroundFollow.cpp"
"${CMAKE_SOURCE_DIR}/editor/editorProfile.cpp"
${UNIT_TEST_CASES})
# the core library brings the game's build settings along

View File

@@ -0,0 +1,42 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorGroundFollow.hpp"
#include <cmath>
#include <limits>
namespace {
segment_data straight(double const From, double const To) {
segment_data piece;
piece.points[segment_data::point::start] = {From, 0.0, 0.0};
piece.points[segment_data::point::end] = {To, 0.0, 0.0};
return piece;
}
} // namespace
TEST_CASE("heights: from point to point the tracks meet at one height where a point is clicked just past a joint") {
// three tracks of 40 m, the grade breaking 3 m past the first joint and 2 m short of the second one, steeply
std::vector<segment_data> pieces{straight(0.0, 40.0), straight(40.0, 80.0), straight(80.0, 120.0)};
auto const unknown{std::numeric_limits<double>::quiet_NaN()};
ground_follow::follow_points(pieces, {{43.0, -5.0, 0.0}, {78.0, 3.0, 0.0}}, {0.0, unknown, 0.0, unknown});
REQUIRE(pieces.size() >= 3);
for (std::size_t i = 0; i + 1 < pieces.size(); ++i)
CHECK(pieces[i].points[segment_data::point::end].y == doctest::Approx(pieces[i + 1].points[segment_data::point::start].y).epsilon(1e-9));
CHECK(pieces.front().points[segment_data::point::start].y == doctest::Approx(0.0));
CHECK(pieces.back().points[segment_data::point::end].y == doctest::Approx(0.0));
}
TEST_CASE("heights: with no point between the ends the grade is even from one end to the other") {
std::vector<segment_data> pieces{straight(0.0, 50.0), straight(50.0, 100.0)};
auto const unknown{std::numeric_limits<double>::quiet_NaN()};
ground_follow::follow_points(pieces, {}, {10.0, unknown, 12.0, unknown});
REQUIRE(pieces.size() == 2);
CHECK(pieces[0].points[segment_data::point::end].y == doctest::Approx(11.0));
CHECK(pieces[1].points[segment_data::point::start].y == doctest::Approx(11.0));
}