18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 21:45:16 +01:00

test(track): count the steps along a buckle in integers

SonarCloud S2193: no float loop counters.
This commit is contained in:
jerrrrycho
2026-11-15 18:57:08 +01:00
parent b182e560e1
commit f2d9926e66
2 changed files with 9 additions and 4 deletions

View File

@@ -180,8 +180,9 @@ TEST_CASE("the buckle has its amplitude in the middle, side lobes the other way
CHECK(track_buckle::bend(shape, 60.0) == doctest::Approx(-peak));
// none larger anywhere, and the curvature with no jumps
auto previous{track_buckle::bend(shape, 35.0)};
for (auto at = 35.0; at <= 85.0; at += 0.01)
for (auto step = 0; step <= 5000; ++step)
{
auto const at{35.0 + 0.01 * step};
auto const bend{track_buckle::bend(shape, at)};
CHECK(std::abs(bend) <= peak * 1.0001);
CHECK(std::abs(bend - previous) < 0.01 * peak);
@@ -230,8 +231,8 @@ TEST_CASE("a bogie feels the curvature of the buckle averaged over its wheelbase
CHECK(std::abs(across) < 0.5 * peak);
// the most the body feels, at any place, is less than a bogie does
auto most{0.0};
for (auto at = 20.0; at <= 80.0; at += 0.05)
most = std::max(most, std::abs(track_buckle::body_bend(shape, at, 17.0, 2.5)));
for (auto step = 0; step <= 1200; ++step)
most = std::max(most, std::abs(track_buckle::body_bend(shape, 20.0 + 0.05 * step, 17.0, 2.5)));
CHECK(most < 0.95 * peak);
CHECK(most > 0.3 * peak);
}

View File

@@ -51,8 +51,12 @@ derailment::outcome ride(track_buckle::shape const &Shape, double const Radius,
derailment::monitor monitor;
auto const velocity{Speed / 3.6};
auto const reach{track_buckle::reach(Shape) + Stock.pivots};
for (auto at = Shape.centre - reach - 5.0; at <= Shape.centre + reach + 5.0; at += velocity * Step)
auto const start{Shape.centre - reach - 5.0};
auto const advance{velocity * Step};
auto const steps{static_cast<int>(std::floor((2.0 * (reach + 5.0)) / advance))};
for (auto step = 0; step <= steps; ++step)
{
auto const at{start + step * advance};
derailment::track_state track;
track.radius = Radius;
auto const bend{track_buckle::body_bend(Shape, at, Stock.pivots, Stock.base)};