18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 10:05: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
+3 -1
View File
@@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/Globals.h"
#include "utilities/Logs.h"
#include <algorithm>
#include <cmath>
#include <format>
#include <string>
@@ -116,7 +117,8 @@ void physics::Vehicle::buffer_stop_contact(double const dt)
auto would{bufferstop::outcome::none};
auto vehiclecrush{0.0};
input.dt = monitor_step;
for (auto time = 0.0; time < monitor_time; time += monitor_step)
auto const steps{static_cast<int>(std::ceil(monitor_time / monitor_step - 1e-9))};
for (auto index{0}; index < steps; ++index)
{
auto const step{bufferstop::contact(installation.stop, state, input)};
would = bufferstop::worse(would, step.result);