mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
fix(physics): trackcheck tells a curve without a speed limit apart from the defects
A track without a speed limit of its own was checked at a default 125 km/h and counted as overturning or a tight curve too fast at the default speed: in Tomaszewo 154 such lines, all of them curves with no limit, the tram tracks of the town (29 to 31 m) among them. A curve without a speed limit is no defect: the drivers go by the signals and the timetable there. It now gets a note of its own, "no speed limit set (not a defect): the curve takes at most X km/h, the overturning speed of EU07", only where that is under the top speed of the EU07, and the summary counts these curves apart from the suspicious tracks, with the slowest speed among them. The tight curve too fast needs a speed limit too. Tram tracks have no category of their own (a tram is a vehicle of the trains' category, on their tracks), so they are checked alike.
This commit is contained in:
@@ -52,20 +52,35 @@ TEST_CASE("trackcheck: the speed limit of a curve") {
|
||||
SUBCASE("over the overturning speed of the EU07") {
|
||||
auto const found{tc::check(curve(300.0, critical + 5.0))};
|
||||
CHECK(has(found, tc::kind::overturning));
|
||||
CHECK_FALSE(has(found, tc::kind::overturning_default));
|
||||
CHECK_FALSE(has(found, tc::kind::unlimited_curve));
|
||||
CHECK(found.defective());
|
||||
CHECK(found.text.find("over the overturning speed of EU07") != std::string::npos);
|
||||
CHECK(found.text.find("speed limit 113 km/h") != std::string::npos);
|
||||
}
|
||||
SUBCASE("the cant raises it") {
|
||||
CHECK(tc::check(curve(300.0, critical + 5.0, 100.0)).empty());
|
||||
}
|
||||
SUBCASE("without a speed limit of its own the default one goes, counted apart") {
|
||||
SUBCASE("without a speed limit of its own it's no defect, the speed it takes is told") {
|
||||
auto const found{tc::check(curve(300.0, -1.0))};
|
||||
CHECK(has(found, tc::kind::overturning_default));
|
||||
CHECK(has(found, tc::kind::unlimited_curve));
|
||||
CHECK_FALSE(has(found, tc::kind::overturning));
|
||||
CHECK(found.text.find("default speed 125 km/h") != std::string::npos);
|
||||
CHECK_FALSE(found.defective());
|
||||
CHECK_FALSE(tc::is_defect(tc::kind::unlimited_curve));
|
||||
CHECK(found.unlimited_speed == doctest::Approx(critical));
|
||||
CHECK(found.text.starts_with("no speed limit set (not a defect): the curve takes at most "));
|
||||
CHECK(found.text.find(" km/h, the overturning speed of EU07") != std::string::npos);
|
||||
CHECK(found.text.find("speed limit none") != std::string::npos);
|
||||
}
|
||||
SUBCASE("nor anything when it takes them at the top speed of the EU07") {
|
||||
CHECK(tc::check(curve(600.0, -1.0)).empty());
|
||||
}
|
||||
SUBCASE("a tram loop of 30 m without a speed limit is no tight curve too fast") {
|
||||
// the tram tracks of Tomaszewo (tramwaj106...): no category of their own, no speed limit
|
||||
auto const found{tc::check(curve(30.0, -1.0))};
|
||||
CHECK(found.kinds == std::vector{tc::kind::unlimited_curve});
|
||||
CHECK(found.unlimited_speed == doctest::Approx(overturning(30.0)));
|
||||
CHECK(found.unlimited_speed < 40.0);
|
||||
}
|
||||
SUBCASE("a closed track (speed 0) is not checked") {
|
||||
CHECK(tc::check(curve(100.0, 0.0)).empty());
|
||||
}
|
||||
@@ -135,23 +150,34 @@ TEST_CASE("trackcheck: the scan of a scenery") {
|
||||
tracks.push_back(curve(0.0, 100.0));
|
||||
tracks.back().name = "fine";
|
||||
tracks.back().damage = 2;
|
||||
tracks.push_back(curve(30.0, -1.0));
|
||||
tracks.back().name = "tram_1";
|
||||
tracks.push_back(curve(150.0, -1.0));
|
||||
tracks.back().name = "siding_1";
|
||||
|
||||
std::vector<std::string> log;
|
||||
auto const summary{tc::scan(tracks, [&](std::string const &Line) { log.push_back(Line); })};
|
||||
CHECK(summary.tracks == 4);
|
||||
CHECK(summary.tracks == 6);
|
||||
// the curves without a speed limit are told apart from the defects
|
||||
CHECK(summary.suspicious == 2);
|
||||
CHECK(summary.unlimited == 2);
|
||||
CHECK(summary.slowest == doctest::Approx(overturning(30.0)));
|
||||
CHECK(summary.count(tc::kind::overturning) == 1);
|
||||
CHECK(summary.count(tc::kind::cant_on_straight) == 1);
|
||||
CHECK(summary.count(tc::kind::tight_curve) == 0);
|
||||
CHECK(summary.count(tc::kind::unlimited_curve) == 2);
|
||||
// the damage flags are counted, not told track by track
|
||||
CHECK(summary.damage.at(31) == 2);
|
||||
CHECK(summary.damage.at(2) == 1);
|
||||
REQUIRE(log.size() == 4);
|
||||
REQUIRE(log.size() == 7);
|
||||
CHECK(log[0].starts_with("trackcheck: fast: speed limit 140 km/h over the overturning speed of EU07"));
|
||||
CHECK(log[1].starts_with("trackcheck: leaning: cant 50 / 50 mm on a straight track"));
|
||||
CHECK(log[1].ends_with("damage 31)"));
|
||||
CHECK(log[2].starts_with("trackcheck: 4 rail tracks checked, 2 suspicious: overturning 1; flange climbing 0;"));
|
||||
CHECK(log[3] == "trackcheck: damage flags: 2 on 1; 31 on 2");
|
||||
CHECK(log[2].starts_with("trackcheck: tram_1: no speed limit set (not a defect): the curve takes at most "));
|
||||
CHECK(log[3].starts_with("trackcheck: siding_1: no speed limit set (not a defect)"));
|
||||
CHECK(log[4] == "trackcheck: 6 rail tracks checked, 2 suspicious: overturning 1; flange climbing 0; cant on a straight 1; cant too high 0; tight curve too fast 0; uneven out of range 0");
|
||||
CHECK(log[5].starts_with("trackcheck: curves without a speed limit: 2 taking the reference vehicles under 125 km/h (not a defect), the slowest at "));
|
||||
CHECK(log[6] == "trackcheck: damage flags: 2 on 1; 31 on 2");
|
||||
for (auto const &line : log) {
|
||||
CHECK(line.starts_with("trackcheck: "));
|
||||
}
|
||||
|
||||
@@ -65,6 +65,64 @@ std::string uneven_excess(track_uneven::attribute const &Uneven, settings const
|
||||
return result;
|
||||
}
|
||||
|
||||
// what the check of a track found so far
|
||||
struct collector {
|
||||
findings &result;
|
||||
void add(kind const Kind, std::string const &Text) const {
|
||||
if (std::ranges::find(result.kinds, Kind) == result.kinds.end()) {
|
||||
result.kinds.push_back(Kind);
|
||||
}
|
||||
append(result.text, Text);
|
||||
}
|
||||
};
|
||||
|
||||
derailment::track_state curve_of(track const &Track) {
|
||||
// with the cant both ends have at the least
|
||||
auto const cant{std::min(std::abs(Track.cant[0]), std::abs(Track.cant[1]))};
|
||||
derailment::track_state result;
|
||||
result.radius = Track.radius;
|
||||
result.cant = cant_angle(cant, Track.gauge);
|
||||
result.gauge = Track.gauge;
|
||||
return result;
|
||||
}
|
||||
|
||||
// a speed limit over the speed a reference vehicle overturns or climbs the rail at in the curve
|
||||
void check_limit(track const &Track, std::vector<reference> const &References, collector const &Found) {
|
||||
auto const curve{curve_of(Track)};
|
||||
for (auto const &reference : References) {
|
||||
auto const overturning{derailment::overturning_speed(curve.radius, curve.cant, reference.vehicle.centre_of_gravity, curve.gauge) * kmh};
|
||||
if (overturning > 0.0 && Track.velocity > overturning) {
|
||||
Found.add(kind::overturning, std::format("speed limit {:.0f} km/h over the overturning speed of {} {:.0f} km/h", Track.velocity, reference.name, overturning));
|
||||
}
|
||||
if (auto const climbing{derailment::climbing_speed(reference.vehicle, curve)}; climbing.has_value() && Track.velocity > *climbing * kmh) {
|
||||
Found.add(kind::climbing, std::format("speed limit {:.0f} km/h over the flange climbing speed of {} {:.0f} km/h", Track.velocity, reference.name, *climbing * kmh));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// a curve without a speed limit: how fast it takes the reference vehicles, when that's under the unlimited velocity
|
||||
void check_unlimited(track const &Track, std::vector<reference> const &References, settings const &Settings, collector const &Found) {
|
||||
auto const curve{curve_of(Track)};
|
||||
auto slowest{Settings.unlimited_velocity};
|
||||
std::string what;
|
||||
for (auto const &reference : References) {
|
||||
auto const overturning{derailment::overturning_speed(curve.radius, curve.cant, reference.vehicle.centre_of_gravity, curve.gauge) * kmh};
|
||||
if (overturning > 0.0 && overturning < slowest) {
|
||||
slowest = overturning;
|
||||
what = std::format("the overturning speed of {}", reference.name);
|
||||
}
|
||||
if (auto const climbing{derailment::climbing_speed(reference.vehicle, curve)}; climbing.has_value() && *climbing * kmh < slowest) {
|
||||
slowest = *climbing * kmh;
|
||||
what = std::format("the flange climbing speed of {}", reference.name);
|
||||
}
|
||||
}
|
||||
if (what.empty()) {
|
||||
return;
|
||||
}
|
||||
Found.result.unlimited_speed = slowest;
|
||||
Found.add(kind::unlimited_curve, std::format("no speed limit set (not a defect): the curve takes at most {:.0f} km/h, {}", slowest, what));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::vector<reference> const &default_references() {
|
||||
@@ -81,10 +139,6 @@ std::string_view name_of(kind const Kind) {
|
||||
return "overturning";
|
||||
case kind::climbing:
|
||||
return "flange climbing";
|
||||
case kind::overturning_default:
|
||||
return "overturning at the default speed";
|
||||
case kind::climbing_default:
|
||||
return "flange climbing at the default speed";
|
||||
case kind::cant_on_straight:
|
||||
return "cant on a straight";
|
||||
case kind::cant_excess:
|
||||
@@ -93,56 +147,48 @@ std::string_view name_of(kind const Kind) {
|
||||
return "tight curve too fast";
|
||||
case kind::uneven:
|
||||
return "uneven out of range";
|
||||
case kind::unlimited_curve:
|
||||
return "curve without a speed limit";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
bool is_defect(kind const Kind) {
|
||||
return Kind != kind::unlimited_curve;
|
||||
}
|
||||
|
||||
bool findings::defective() const {
|
||||
return std::ranges::any_of(kinds, [](kind const Kind) { return is_defect(Kind); });
|
||||
}
|
||||
|
||||
findings check(track const &Track, std::vector<reference> const &References, settings const &Settings) {
|
||||
findings result;
|
||||
auto const found = [&](kind const Kind, std::string const &Text) {
|
||||
if (std::find(result.kinds.begin(), result.kinds.end(), Kind) == result.kinds.end()) {
|
||||
result.kinds.push_back(Kind);
|
||||
}
|
||||
append(result.text, Text);
|
||||
};
|
||||
collector const found{result};
|
||||
auto const curved{Track.radius > 0.0};
|
||||
auto const given{Track.velocity >= 0.0};
|
||||
auto const velocity{given ? Track.velocity : Settings.default_velocity};
|
||||
|
||||
if (Track.plain) {
|
||||
// the speed in the curve, with the cant both ends have at the least
|
||||
if (curved && velocity > 0.0) {
|
||||
auto const cant{std::min(std::abs(Track.cant[0]), std::abs(Track.cant[1]))};
|
||||
derailment::track_state track;
|
||||
track.radius = Track.radius;
|
||||
track.cant = cant_angle(cant, Track.gauge);
|
||||
track.gauge = Track.gauge;
|
||||
for (auto const &reference : References) {
|
||||
auto const overturning{derailment::overturning_speed(track.radius, track.cant, reference.vehicle.centre_of_gravity, track.gauge) * kmh};
|
||||
if (overturning > 0.0 && velocity > overturning) {
|
||||
found(given ? kind::overturning : kind::overturning_default,
|
||||
std::format("{} {:.0f} km/h over the overturning speed of {} {:.0f} km/h", given ? "speed limit" : "default speed", velocity, reference.name, overturning));
|
||||
}
|
||||
if (auto const climbing{derailment::climbing_speed(reference.vehicle, track)}; climbing.has_value() && velocity > *climbing * kmh) {
|
||||
found(given ? kind::climbing : kind::climbing_default,
|
||||
std::format("{} {:.0f} km/h over the flange climbing speed of {} {:.0f} km/h", given ? "speed limit" : "default speed", velocity, reference.name, *climbing * kmh));
|
||||
}
|
||||
}
|
||||
// a closed track (speed 0) isn't run on
|
||||
if (curved && given && Track.velocity > 0.0) {
|
||||
check_limit(Track, References, found);
|
||||
}
|
||||
if (curved && false == given) {
|
||||
check_unlimited(Track, References, Settings, found);
|
||||
}
|
||||
// cant held over the whole of a straight track: a transition has it at one end only
|
||||
if (false == curved && std::abs(Track.cant[0]) > Settings.straight_cant && std::abs(Track.cant[1]) > Settings.straight_cant && Track.cant[0] * Track.cant[1] > 0.0) {
|
||||
found(kind::cant_on_straight, std::format("cant {:.0f} / {:.0f} mm on a straight track", Track.cant[0], Track.cant[1]));
|
||||
found.add(kind::cant_on_straight, std::format("cant {:.0f} / {:.0f} mm on a straight track", Track.cant[0], Track.cant[1]));
|
||||
}
|
||||
if (curved && velocity > Settings.tight_velocity && Track.radius < Settings.tight_radius) {
|
||||
found(kind::tight_curve, std::format("radius {:.0f} m with a {} of {:.0f} km/h", Track.radius, given ? "speed limit" : "default speed", velocity));
|
||||
if (curved && given && Track.velocity > Settings.tight_velocity && Track.radius < Settings.tight_radius) {
|
||||
found.add(kind::tight_curve, std::format("radius {:.0f} m with a speed limit of {:.0f} km/h", Track.radius, Track.velocity));
|
||||
}
|
||||
}
|
||||
if (auto const most{std::max(std::abs(Track.cant[0]), std::abs(Track.cant[1]))}; most > Settings.most_cant) {
|
||||
found(kind::cant_excess, std::format("cant {:.0f} mm over {:.0f} mm", most, Settings.most_cant));
|
||||
found.add(kind::cant_excess, std::format("cant {:.0f} mm over {:.0f} mm", most, Settings.most_cant));
|
||||
}
|
||||
if (auto const excess{uneven_excess(Track.uneven, Settings)}; false == excess.empty()) {
|
||||
found(kind::uneven, std::format("uneven {} mm out of range", excess));
|
||||
found.add(kind::uneven, std::format("uneven {} mm out of range", excess));
|
||||
}
|
||||
if (false == result.empty()) {
|
||||
result.text += std::format(" (radius {:.0f} m, cant {:.0f} / {:.0f} mm, speed limit {}, damage {})", Track.radius, Track.cant[0], Track.cant[1],
|
||||
@@ -162,17 +208,27 @@ summary scan(std::vector<track> const &Tracks, sink const &Log, std::vector<refe
|
||||
if (found.empty()) {
|
||||
continue;
|
||||
}
|
||||
++result.suspicious;
|
||||
if (found.defective()) {
|
||||
++result.suspicious;
|
||||
}
|
||||
if (found.unlimited_speed > 0.0) {
|
||||
++result.unlimited;
|
||||
result.slowest = result.slowest > 0.0 ? std::min(result.slowest, found.unlimited_speed) : found.unlimited_speed;
|
||||
}
|
||||
for (auto const kind : found.kinds) {
|
||||
++result.counts[static_cast<std::size_t>(kind)];
|
||||
}
|
||||
Log(std::format("trackcheck: {}: {}", track.name.empty() ? std::string{"(none)"} : track.name, found.text));
|
||||
}
|
||||
std::string counts;
|
||||
for (std::size_t kind = 0; kind < result.counts.size(); ++kind) {
|
||||
append(counts, std::format("{} {}", name_of(static_cast<track_check::kind>(kind)), result.counts[kind]));
|
||||
for (std::size_t index = 0; index < result.counts.size(); ++index) {
|
||||
if (auto const kind{static_cast<track_check::kind>(index)}; is_defect(kind)) {
|
||||
append(counts, std::format("{} {}", name_of(kind), result.counts[index]));
|
||||
}
|
||||
}
|
||||
Log(std::format("trackcheck: {} rail tracks checked, {} suspicious: {}", result.tracks, result.suspicious, counts));
|
||||
Log(std::format("trackcheck: curves without a speed limit: {} taking the reference vehicles under {:.0f} km/h (not a defect){}", result.unlimited, Settings.unlimited_velocity,
|
||||
result.unlimited > 0 ? std::format(", the slowest at {:.0f} km/h", result.slowest) : std::string{}));
|
||||
std::string damage;
|
||||
for (auto const &[flags, count] : result.damage) {
|
||||
append(damage, std::format("{} on {}", flags, count));
|
||||
|
||||
@@ -23,7 +23,10 @@ http://mozilla.org/MPL/2.0/.
|
||||
// derailment (McZapkie/derailment.h) and the plain rules of the track find suspicious, to the log once the scenery
|
||||
// loaded, so a run can tell a faulty scenery from a faulty simulation. one line for a track with all it found
|
||||
// ("trackcheck: <name>: ..."), and a summary with the count of each kind. the damage flags are only counted: sceneries
|
||||
// set them for the jolts of a worn track (damage 31 on every track of line 107)
|
||||
// set them for the jolts of a worn track (damage 31 on every track of line 107). a curve without a speed limit of its
|
||||
// own is no defect (the drivers go by the signals and the timetable there, the tram loops of a town have none), it is
|
||||
// only told how fast it takes the reference vehicles, apart from the defects. the rail tracks of trams have no category
|
||||
// of their own (a tram is a vehicle of the category of the trains, on a track of theirs), so they are checked alike
|
||||
namespace track_check {
|
||||
|
||||
// a rail track as the check sees it
|
||||
@@ -49,9 +52,9 @@ struct reference {
|
||||
std::vector<reference> const &default_references();
|
||||
|
||||
struct settings {
|
||||
// the speed limit of a track which gives none [km/h]: the top speed of the EU07, the trains the default vehicles
|
||||
// make up run no faster
|
||||
double default_velocity{125.0};
|
||||
// a curve without a speed limit is told of when it takes the reference vehicles slower than this [km/h]: the top
|
||||
// speed of the EU07, the trains the default vehicles make up run no faster
|
||||
double unlimited_velocity{125.0};
|
||||
double most_cant{160.0}; // [mm], 150 the most of the Polish rules (Id-1), and a margin
|
||||
double straight_cant{5.0}; // the cant both ends of a straight track have, past which it's cant without a curve [mm]
|
||||
double tight_radius{40.0}; // a curve tighter than this [m]
|
||||
@@ -63,27 +66,34 @@ struct settings {
|
||||
enum class kind {
|
||||
overturning, // the speed limit is over the speed a reference vehicle overturns at
|
||||
climbing, // or over the one its flange climbs the rail at
|
||||
overturning_default, // the same with the default speed limit, of a track which gives none
|
||||
climbing_default,
|
||||
cant_on_straight, // both ends of a straight track have the same cant
|
||||
cant_excess, // over the most cant
|
||||
tight_curve, // a curve tighter than the tight radius with a speed limit over the tight velocity
|
||||
uneven, // the unevenness out of the plausible range
|
||||
unlimited_curve, // no defect: a curve without a speed limit, which takes the reference vehicles slower than the
|
||||
// unlimited velocity
|
||||
count_
|
||||
};
|
||||
std::string_view name_of(kind Kind);
|
||||
// whether the kind is a defect of the scenery, rather than a note
|
||||
bool is_defect(kind Kind);
|
||||
|
||||
// what the check found on a track
|
||||
struct findings {
|
||||
std::vector<kind> kinds;
|
||||
std::string text; // what the log line tells after the name of the track, empty when nothing
|
||||
double unlimited_speed{0.0}; // the speed a curve without a speed limit takes the reference vehicles at [km/h], 0 when
|
||||
// not told of
|
||||
bool empty() const { return kinds.empty(); }
|
||||
bool defective() const; // has a kind which is a defect
|
||||
};
|
||||
findings check(track const &Track, std::vector<reference> const &References = default_references(), settings const &Settings = {});
|
||||
|
||||
struct summary {
|
||||
int tracks{0}; // checked
|
||||
int suspicious{0}; // with a line of their own
|
||||
int suspicious{0}; // with a defect
|
||||
int unlimited{0}; // curves without a speed limit told of, defects or not
|
||||
double slowest{0.0}; // the lowest speed one of them takes the reference vehicles at [km/h], 0 without any
|
||||
std::array<int, static_cast<std::size_t>(kind::count_)> counts{};
|
||||
std::map<int, int> damage; // the tracks of each value of the damage flags, none for 0
|
||||
int count(kind const Kind) const { return counts[static_cast<std::size_t>(Kind)]; }
|
||||
|
||||
Reference in New Issue
Block a user