mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-08 09:27:54 +01:00
fix(track): what Sonar reports on the unevenness
The blockers are in the EP brake of a vehicle, older than this work: its arrays made with new[] are vectors now, which also removes the deletes. - The caches of the unevenness of a track are no longer mutable: what fills them isn't const any more. - TSegment gets back to RaPositionGet in one piece, with what the path has to do with the others in one struct. - Less nesting in the group of switches and in the fields of the editor, nested conditionals written out, and the attribute is read from a string_view. A test no longer counts in floating point. No change in behaviour.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include "doctest.h"
|
||||
#include "world/TrackUneven.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
@@ -12,19 +14,20 @@ double deviation(std::vector<double> const &Values)
|
||||
auto mean{0.0};
|
||||
for (auto const value : Values)
|
||||
mean += value;
|
||||
mean /= Values.size();
|
||||
auto const count{static_cast<double>(Values.size())};
|
||||
mean /= count;
|
||||
auto sum{0.0};
|
||||
for (auto const value : Values)
|
||||
sum += (value - mean) * (value - mean);
|
||||
return std::sqrt(sum / Values.size());
|
||||
return std::sqrt(sum / count);
|
||||
}
|
||||
|
||||
double peak(std::vector<double> Values)
|
||||
{
|
||||
for (auto &value : Values)
|
||||
value = std::abs(value);
|
||||
std::sort(Values.begin(), Values.end());
|
||||
return Values[static_cast<std::size_t>(0.999 * Values.size())];
|
||||
std::ranges::sort(Values);
|
||||
return Values[Values.size() * 999 / 1000];
|
||||
}
|
||||
|
||||
void add_chord(std::vector<double> &Output, std::vector<double> const &Line, int const Half)
|
||||
@@ -44,14 +47,22 @@ TEST_CASE("uneven track: measures as the Id-14 limits for its value")
|
||||
int const steps{4000};
|
||||
int const base{10}; // 5 m
|
||||
int const lines{36};
|
||||
double vertical{0.0}, horizontal{0.0}, twist{0.0}, wander{0.0}, level{0.0}, j{0.0}, away{0.0};
|
||||
double vertical{0.0};
|
||||
double horizontal{0.0};
|
||||
double twist{0.0};
|
||||
double wander{0.0};
|
||||
double level{0.0};
|
||||
double j{0.0};
|
||||
double away{0.0};
|
||||
for (int line = 0; line < lines; ++line)
|
||||
{
|
||||
auto const heading{glm::pi<double>() * (line + 0.37) / lines};
|
||||
glm::dvec3 const start{7919.0 * std::sin(line * 1.7), 0.0, 6577.0 * std::cos(line * 2.3)};
|
||||
glm::dvec3 const along{std::cos(heading), 0.0, std::sin(heading)};
|
||||
glm::dvec3 const across{-along.z, 0.0, along.x};
|
||||
std::vector<double> up[2], side[2], middle;
|
||||
std::array<std::vector<double>, 2> up;
|
||||
std::array<std::vector<double>, 2> side;
|
||||
std::vector<double> middle;
|
||||
for (int i = 0; i < steps; ++i)
|
||||
{
|
||||
auto const point{start + along * (i * step)};
|
||||
@@ -64,7 +75,11 @@ TEST_CASE("uneven track: measures as the Id-14 limits for its value")
|
||||
}
|
||||
middle.push_back(track_uneven::field(point).y * amplitude);
|
||||
}
|
||||
std::vector<double> verticals, horizontals, twists, gauges, levels;
|
||||
std::vector<double> verticals;
|
||||
std::vector<double> horizontals;
|
||||
std::vector<double> twists;
|
||||
std::vector<double> gauges;
|
||||
std::vector<double> levels;
|
||||
for (int rail = 0; rail < 2; ++rail)
|
||||
{
|
||||
add_chord(verticals, up[rail], base);
|
||||
@@ -269,9 +284,9 @@ TEST_CASE("uneven track: the value along a track meets its neighbours exactly")
|
||||
CHECK(track_uneven::along(18.0, 35.0, 35.0, 0.25, 0.5) == doctest::Approx(35.0).epsilon(0.01));
|
||||
// no jump anywhere
|
||||
auto last{track_uneven::along(18.0, 35.0, 0.0, 0.0, length)};
|
||||
for (auto distance{0.25}; distance <= length; distance += 0.25)
|
||||
for (int step = 1; step <= 2000; ++step)
|
||||
{
|
||||
auto const value{track_uneven::along(18.0, 35.0, 0.0, distance, length)};
|
||||
auto const value{track_uneven::along(18.0, 35.0, 0.0, step * 0.25, length)};
|
||||
REQUIRE(std::abs(value - last) < 0.5);
|
||||
last = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user