18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 11:15:23 +01:00

fix: SonarQube findings of the buffer stops

- The notice of a finished hit is taken out of the contact with std::exchange before it goes to the scenery, so
  what the scenery does with it can't reach the one held in the contact.
- The loops count whole steps (an int, the number of steps taken with ceil) instead of adding a floating step.
- The local final of bufferstop::contact() is ending (final is a contextual keyword).

Unit tests 1294/1294.
This commit is contained in:
jerrrrycho
2026-12-02 17:04:29 +01:00
parent 9ecbd110da
commit 885c28c1ef
4 changed files with 22 additions and 15 deletions
+6 -3
View File
@@ -60,7 +60,8 @@ run_result run(bs::definition const &Stop, bs::contact_input Input, double const
Input.closing = Speed;
Input.penetration = -0.01;
auto touched{false};
for (auto time = 0.0; time < 120.0; time += Input.dt) {
auto const steps{static_cast<int>(std::ceil(120.0 / Input.dt))};
for (auto index{0}; index < steps; ++index) {
auto const step{bs::contact(Stop, result.stop, Input)};
result.worst = bs::worse(result.worst, step.result);
result.peak = std::max(result.peak, step.force);
@@ -87,7 +88,8 @@ run_result run(bs::definition const &Stop, bs::contact_input Input, double const
// the lowest speed [km/h], in steps of a quarter, the vehicle rides up the stop at
std::optional<double> ride_up_speed(bs::definition const &Stop, bs::contact_input const &Input) {
for (auto speed = 4.0; speed <= 20.0; speed += 0.25) {
for (auto quarter{16}; quarter <= 80; ++quarter) {
auto const speed{0.25 * quarter};
if (run(Stop, Input, speed * kmh).climbed) {
return speed;
}
@@ -153,7 +155,8 @@ TEST_CASE("bufferstop: the brake elements of a sliding stop hold less the longer
// over the 8 m of its run-out the 1848 kJ of the calculation of Rawie 10 EB
auto work{0.0};
constexpr double step{0.001};
for (auto slid = 0.5 * step; slid < 8.0; slid += step) {
for (auto index{0}; index < 8000; ++index) {
auto const slid{(index + 0.5) * step};
work += bs::friction_force(stop, slid) * step;
}
CHECK(work == doctest::Approx(1848.0e3).epsilon(0.001));