mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 22:07:55 +01:00
38f90387c4
The second half of E1: what the tracks of a scenery are against a profile of the norms, listed. Nothing of the tracks is changed. - editor/editorNormsReport: a line of paths sampled a metre apart, two samples at each joint, into what the norms read a line from: the plan, the curvature signed by the turn, the cant on the base of 1500 mm (as the simulator takes the rolls) signed by the side it leans to as the line runs, the grade, the speed of each path (a switch's for its diverging track alone too), and what the path is a part of (a switch, its diverging track, a curved switch, a movable frog, a crossing). The line described, checked, and each finding set back on its path with a point of it; its message, "cant ramp 3.00 mm/m, PLK allows at most 2.50 mm/m (tab. 9.12)", "break of the grade with no vertical curve, PLK asks for a radius of at least 2500 m (tab. 10.2)", through STR_C; the text of the report: the class, the elements, the cant, the grade line and the findings of each line. - The Norms tab of the track window, under More beside Speed and Joints, no key; its window is ###trackanalysis, as theirs. The line through the selected path (run_route, as the speed check walks it) or the whole scenery: the lines through the plain tracks, then each path of a switch none of them ran along, checked with the line it lies in and its own findings kept, a place two lines run through listed once. The profile (PLK by default) and the class of the line folded under a line saying it: the line speed for the tracks with none of their own (on by default: the speed of each track), the slow trains (tab. 8.1 by default), the traffic, main track or siding, the load, at a platform. The results in the table of the speed check and the joints, the worst first, coloured by the tier, the values above the recommended ones on a tick; a click on a row shows the place, the hard limits and the warnings are marked in the view. The icon is drawn into its own cell of editor_icons.png only (the generator has it): the sheet drawn again with this Pillow differs in other cells. - Self-test: normsreport <file> [scope] [plk|tsi|en|ch] [km/h] writes the report to the file; expect findings <tier> <least> <most>; the case e1_norms_report checks the curves k0..k3 of the fixture at 60 km/h against PLK and the whole scenery against the TSI. - Golden: data/norms/line.scn, a line of 14 tracks written by make_line.py there (curves with and without transitions, cant on and off a curve and along a straight, reverse curves 10 m apart, short straights, a grade with breaks), and its report against the four profiles in data/norms/line_report.txt; EU07_UNIT_TESTS_UPDATE_GOLDEN=1 writes it anew. A test lays a canted corner with the alignment of the editor and finds the samples leaning into it, both turns and run both ways, I = Deq - D. alignment::limits stays as the laying tools use it. Where its values differ from PLK P0: - unbalanced 0.6 m/s2 is I 92 mm on the 1500 mm base; P0 110 mm (P1 130) on the running lines, 80 on the sidings; - ramp_factor 10, a ramp of 1:(10 V), 1 mm/m at 100 km/h and 2.5 mm/m at 40 km/h, has no counterpart: P0 1.6 mm/m at any speed; - jerk 0.3 m/s3 is dI/dt 46 mm/s; P0 55 mm/s; - vertical_factor 0.4 V^2 and vertical_min 2000 m; P0 max(0.77 V^2, 5000 m) (P1 max(0.35 V^2, 5000), P2 max(0.25 V^2, 2000)); - arc_min 20 m and arc_min_factor 0.4 V; P0 max(0.35 V, 30 m) up to 120 km/h, 0.40 V up to 200 km/h, also for the straights, where tangent_min_time is 0; - the same: cant_max 150 mm (P0 = P1 = P2 on ballast), cant_rate 35 mm/s (P0 of tab. 9.13), the base of 1500 mm.
211 lines
7.5 KiB
C++
211 lines
7.5 KiB
C++
// the report of the norms on the tracks laid (editor/editorNormsReport.cpp): tracks read from the text of a scenery with no scene, the
|
|
// way test_track_text.cpp reads them, chained into a line, sampled, described as elements and checked. The line of data/norms/line.scn
|
|
// (written by make_line.py there) against each profile gives the report kept in data/norms/line_report.txt; with
|
|
// EU07_UNIT_TESTS_UPDATE_GOLDEN=1 the report is written there instead, to be looked through as the change it is
|
|
|
|
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
#include "track_text.h"
|
|
#include "editor/editorAlignment.hpp"
|
|
#include "editor/editorGeometry.hpp"
|
|
#include "editor/editorNormsReport.hpp"
|
|
|
|
#include <cmath>
|
|
#include <cstdlib>
|
|
#include <fstream>
|
|
#include <memory>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
|
|
using test::read_track;
|
|
using test::track_reading;
|
|
|
|
std::string const kData{EU07_UNIT_TESTS_DATA "/norms/"};
|
|
|
|
std::vector<std::unique_ptr<TTrack>> read_tracks(std::string const &File) {
|
|
std::ifstream in{File};
|
|
REQUIRE(in.good());
|
|
std::vector<std::unique_ptr<TTrack>> result;
|
|
std::string line;
|
|
while (std::getline(in, line)) {
|
|
// a checkout may end the lines with CR LF
|
|
std::erase(line, '\r');
|
|
if (line.rfind("node", 0) == 0) {
|
|
result.push_back(read_track(line));
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// the tracks one after another, from the first one: each next the one an end of which is where the line has come to
|
|
std::vector<norms_report::span> chained(std::vector<std::unique_ptr<TTrack>> const &Tracks) {
|
|
std::vector<norms_report::span> result;
|
|
if (Tracks.empty()) {
|
|
return result;
|
|
}
|
|
std::vector<bool> taken(Tracks.size(), false);
|
|
result.push_back({Tracks.front().get(), 0, true});
|
|
taken.front() = true;
|
|
auto reached{Tracks.front()->m_paths[0].points[segment_data::point::end]};
|
|
for (bool found{true}; found;) {
|
|
found = false;
|
|
for (std::size_t i = 0; i < Tracks.size() && false == found; ++i) {
|
|
if (taken[i]) {
|
|
continue;
|
|
}
|
|
auto const &path{Tracks[i]->m_paths[0]};
|
|
auto const at_start{geometry::plan_distance(path.points[segment_data::point::start], reached) < geometry::same_point};
|
|
auto const at_end{geometry::plan_distance(path.points[segment_data::point::end], reached) < geometry::same_point};
|
|
if (false == at_start && false == at_end) {
|
|
continue;
|
|
}
|
|
result.push_back({Tracks[i].get(), 0, at_start});
|
|
reached = path.points[at_start ? segment_data::point::end : segment_data::point::start];
|
|
taken[i] = true;
|
|
found = true;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
std::string normalized(std::string Text) {
|
|
std::erase(Text, '\r');
|
|
return Text;
|
|
}
|
|
|
|
std::string file_text(std::string const &File) {
|
|
std::ifstream in{File, std::ios::binary};
|
|
std::ostringstream text;
|
|
text << in.rdbuf();
|
|
return normalized(text.str());
|
|
}
|
|
|
|
// the track text of a path laid by the editor, for it to be read as the scenery loader reads it
|
|
std::string entry(std::string const &Name, segment_data const &Path) {
|
|
std::ostringstream text;
|
|
text.precision(10);
|
|
auto const length{geometry::bezier{Path}.plan_length()};
|
|
text << "node -1 0 " << Name << " track normal " << length << " 1.435 0.15 25 20 0 flat vis rail_screw_used1 4 tpbps-new2 0.2 0.5 1.1";
|
|
auto const &points{Path.points};
|
|
for (auto const index : {segment_data::point::start, segment_data::point::control1, segment_data::point::control2, segment_data::point::end}) {
|
|
text << ' ' << points[index].x << ' ' << points[index].y << ' ' << points[index].z;
|
|
if (index == segment_data::point::start) {
|
|
text << ' ' << Path.rolls[0];
|
|
} else if (index == segment_data::point::end) {
|
|
text << ' ' << Path.rolls[1];
|
|
}
|
|
}
|
|
text << " 0 endtrack";
|
|
return text.str();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("norms report: the cant of a curve laid by the editor leans into it, both ways and run both ways, as the samples sign it") {
|
|
track_reading const reading;
|
|
for (auto const side : {1.0, -1.0}) {
|
|
CAPTURE(side);
|
|
// a corner of R 400 m with transitions of 60 m and a cant of 80 mm, as in test_cant.cpp
|
|
alignment::design design;
|
|
design.start = {0.0, 0.0, 0.0};
|
|
design.end = {1000.0 * side, 0.0, 1000.0};
|
|
design.start_direction = {0.0, 1.0};
|
|
design.end_direction = {side, 0.0};
|
|
alignment::vertex vertex;
|
|
vertex.position = {0.0, 1000.0};
|
|
vertex.radius = 400.0;
|
|
vertex.transition_in = 60.0;
|
|
vertex.transition_out = 60.0;
|
|
vertex.cant = 80.0;
|
|
design.vertices.push_back(vertex);
|
|
auto const line{alignment::compute(design)};
|
|
REQUIRE(line.valid);
|
|
std::vector<std::unique_ptr<TTrack>> tracks;
|
|
int count{0};
|
|
for (auto const &path : alignment::pieces(line, design, alignment::minimum_pieces(line, design))) {
|
|
tracks.push_back(read_track(entry("corner" + std::to_string(++count), path)));
|
|
}
|
|
auto spans{chained(tracks)};
|
|
REQUIRE(spans.size() == tracks.size());
|
|
for (auto const backward : {false, true}) {
|
|
CAPTURE(backward);
|
|
if (backward) {
|
|
std::ranges::reverse(spans);
|
|
for (auto &span : spans) {
|
|
span.forward = !span.forward;
|
|
}
|
|
}
|
|
auto const sampled{norms_report::sample(spans, 1.0, false)};
|
|
int curved{0};
|
|
for (auto const &sample : sampled.samples) {
|
|
if (std::abs(sample.curvature) > 1.0 / 450.0) {
|
|
++curved;
|
|
CHECK(sample.curvature * sample.cant > 0.0);
|
|
CHECK(std::abs(sample.cant) > 70.0);
|
|
CHECK(std::abs(sample.cant) < 80.5);
|
|
}
|
|
}
|
|
CHECK(curved > 50);
|
|
// so at 80 km/h the arc falls short by 11.8 V^2 / R - 80 mm, not by more
|
|
norms_report::options options;
|
|
options.line.vmax = 80.0;
|
|
options.track_speeds = false;
|
|
auto const checked{norms_report::check(spans, options)};
|
|
for (auto const &found : checked.entries) {
|
|
if (found.finding.what == norms::parameter::cant_deficiency && found.kind == norms::element_kind::arc) {
|
|
CHECK(found.finding.value == doctest::Approx(11.8 * 80 * 80 / 400.0 - 80.0).epsilon(0.02));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_CASE("norms report: the golden report of the line of data/norms/line.scn against each profile") {
|
|
track_reading const reading;
|
|
auto const tracks{read_tracks(kData + "line.scn")};
|
|
REQUIRE(tracks.size() == 14);
|
|
auto const spans{chained(tracks)};
|
|
REQUIRE(spans.size() == tracks.size());
|
|
std::string report;
|
|
for (auto const profile : {norms::profile_id::plk, norms::profile_id::tsi, norms::profile_id::en13803, norms::profile_id::ch}) {
|
|
norms_report::options options;
|
|
options.profile = profile;
|
|
options.line.vmax = 100.0;
|
|
options.line.kind = norms::traffic::mixed;
|
|
options.line.track = norms::track_kind::main;
|
|
options.line.load = 5.0;
|
|
auto const checked{norms_report::check(spans, options)};
|
|
report += norms_report::header(options) + norms_report::text(checked, profile == norms::profile_id::plk) + "\n";
|
|
// every finding lies on a track of the line, at a point of it
|
|
for (auto const &found : checked.entries) {
|
|
CHECK(found.track != nullptr);
|
|
}
|
|
}
|
|
auto const golden{kData + "line_report.txt"};
|
|
if (auto const *update{std::getenv("EU07_UNIT_TESTS_UPDATE_GOLDEN")}; update != nullptr && std::string{update} == "1") {
|
|
std::ofstream{golden, std::ios::binary} << report;
|
|
MESSAGE("written " << golden);
|
|
return;
|
|
}
|
|
auto const expected{file_text(golden)};
|
|
// line by line, for the first difference to be shown by itself
|
|
std::istringstream got{report};
|
|
std::istringstream kept{expected};
|
|
std::string got_line;
|
|
std::string kept_line;
|
|
int number{0};
|
|
while (true) {
|
|
auto const more_got{static_cast<bool>(std::getline(got, got_line))};
|
|
auto const more_kept{static_cast<bool>(std::getline(kept, kept_line))};
|
|
++number;
|
|
if (false == more_got && false == more_kept) {
|
|
break;
|
|
}
|
|
CAPTURE(number);
|
|
REQUIRE(got_line == kept_line);
|
|
}
|
|
}
|