17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-08 18:50:34 +01:00

fix: the bugs and vulnerabilities SonarCloud reports on PR #216

This commit is contained in:
2026-11-07 22:11:08 +01:00
parent 8e85def98f
commit 7667e5b2ec
65 changed files with 910 additions and 121 deletions

View File

@@ -62,8 +62,12 @@ std::vector<glm::dvec2> traced(alignment::result const &Line, double const Spaci
return glm::dvec2{station.position.x, station.position.z} + glm::normalize(across) * Shift;
};
int count{0};
for (auto chainage{std::max(0.0, from - 30.0)}; chainage <= to; chainage += Spacing, ++count)
auto chainage{std::max(0.0, from - 30.0)};
while (chainage <= to) {
points.push_back(along(chainage, Noise * (count % 3 == 0 ? 1.0 : count % 3 == 1 ? -0.6 : 0.2)));
chainage += Spacing;
++count;
}
points.push_back(along(to + 30.0, Noise * 0.5));
points.push_back(along(to + 60.0, -Noise * 0.5));
return points;
@@ -750,7 +754,7 @@ TEST_CASE("alignment: a curve laid into a curved free end ends at it with its cu
}
TEST_CASE("alignment: the pieces of a compound curve are never of no length, whatever its arcs and transitions") {
std::mt19937 random{20261025};
std::mt19937 random{20261025}; // NOSONAR: deterministic test input, not security-relevant
auto const uniform = [&](double const Low, double const High) { return std::uniform_real_distribution<double>(Low, High)(random); };
auto const pick = [&](int const Count) { return std::uniform_int_distribution<int>(0, Count - 1)(random); };
int bad{0}, valid{0};

View File

@@ -15,10 +15,12 @@ std::vector<switch_curve::track_point> line(double const Straight, double const
double heading{0.0};
auto const curvature = [&](double const S) { return S <= Straight ? 0.0 : S <= Straight + Transition ? (S - Straight) / Transition / Radius : 1.0 / Radius; };
auto const cant = [&](double const S) { return S <= Straight ? 0.0 : S <= Straight + Transition ? Cant * (S - Straight) / Transition : Cant; };
for (double s{0.0}; s <= Straight + Transition + Arc + 1e-9; s += 0.5) {
double s{0.0};
while (s <= Straight + Transition + Arc + 1e-9) {
if (s > 0.0)
heading += 0.5 * (curvature(s - 0.5) + curvature(s)) * 0.5;
points.push_back({s, heading, cant(s)});
s += 0.5;
}
return points;
}
@@ -151,8 +153,11 @@ namespace {
// a track of one curvature from its start, heading as given there, a point every half metre
std::vector<switch_curve::track_point> arc(double const Length, double const Heading, double const Curvature) {
std::vector<switch_curve::track_point> points;
for (double s{0.0}; s <= Length + 1e-9; s += 0.5)
double s{0.0};
while (s <= Length + 1e-9) {
points.push_back({s, Heading + Curvature * s, 0.0});
s += 0.5;
}
return points;
}