18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 12:57:06 +01:00
Files
maszyna/tests/unit/test_switch_curve.cpp
T
maj00r 10f2ac36f9 fix(editor): a switch laid gets the speed of its diverging track, one breaking a hard rule of ST-T1-A6 isn't laid (#454)
* fix(editor): track edits keep the joints, the norms, the records and the saved speed together

- The cant typed in the inspector goes on into the track joined at that end, as the gizmo and the
  joints tool do it; the neighbours go into the same undo step. The joint stepped before.
- A track laid on from a canted joint takes the cant off along the ramp the norms ask for at the
  speed (`alignment::cant_ramp_length`), not at a fixed 1.5 mm a metre whatever the speed and the
  norms: 120 mm at 100 km/h over 120 m, not 80 m.
- Deleting a track of the line under the route tool keeps the laying norms. They went back to the
  defaults, and every later lay, extend and join used those.
- The gauge is a paste group of its own, off by default: pasting how a track rides or sounds no
  longer changes its gauge.
- The speed of a turntable set in the editor is the one saved. The editor changed the speed the
  turntable runs at, while the file keeps the limit it was loaded with.
- Deleting a set of tracks does what Del does with each: a double switch, a slip and a crossover go
  whole, the records of the switches go with them, and the model and events of a turntable too. The
  records stayed behind and on saving were given to another switch, which then showed a wrong type.
- Deleting a switch of a crossover takes the crossover out whole, as the connection tools do: the
  outer track of a crossover on a curve comes down by its lift and the record of the connection
  goes. Alone, the switch left the outer track up for good, and the connection to the next switch
  given its name. A switch bent out of the shape of its record is found by its name.

Tests: a unit test of the norm ramp. The other changes are in the editor's UI, which the unit tests
don't reach.

* test(editor): self-test scripts that fail, a runner, and a case for each fix of the track editing

The editor's self-test scripts only logged: nothing made a run fail. Now:

- `expect` commands check the state and log `SELFTEST PASS` or `SELFTEST FAIL ... got X, expected Y`:
  the cant at a track end, the joint at an end (gap, angle, cant step), the records of a switch and
  the connections naming it, speed, gauge, a track present or removed, the laying norms' gauge,
  heights and lifts against a mark, whether a track is in the line under the route tool, and the
  includes of a turntable. A command no group takes counts as a failure, so a mistyped one can't
  make the checks after it pass.
- At `quit` the result is logged, and a script whose expectations failed ends the editor with exit
  code 2 (a failed start stays 1; the simulator's test mode is unchanged).
- The commit of the inspector's cant field is `track_cant_commit`, which the inspector and the
  `trackcant` command both call; `routegauge` sets the laying norms as the route tool does, and
  `tracksetdelete` deletes a set of tracks by name.
- `tests/editor/run.py` runs each script of `tests/editor/cases` on a copy of the fixture scenery
  in the game folder, with a wall-time limit and a memory cap, reads the exit code and the
  `SELFTEST` lines, and deletes the copy. A `#> reopen` line restarts the editor on the saved
  scenery. See `tests/editor/README.md`.
- One case per fix of the track editing quick fixes (inspector cant, norms after deleting, the
  gauge paste group, turntable speed saved, deleting a set, a set with a double switch, a slip
  and a crossover, deleting a switch of a crossover, a bent switch). All pass; with the fixes
  reverted all fail.

* feat(editor): the track tool panels keep their fields, results and buttons within the panel

- The card of the tool: after a long gesture the action goes under it, at its indent, when what is
  left of the row is narrower than 8 font sizes or the longest word of the action. It was squeezed
  into a sliver and broken in the middle of its words.
- A click on the title row of the card folds it to that row (icon, name, family, key, and a small
  triangle marker) and opens it again. One flag for all the tools, kept with the editor settings
  (`track_card_folded` in eu07_editor.ini), open by default: the card took 250-300 px at the top
  of every tool and repeats the hint bar of the view.
- The grade labels of the vertical profile, on the graph and in the view, write the per mille as
  the panel does (the translated "per mille", the per mille sign in Polish), not "o/oo".
- The track analysis window: the thresholds of the speed check and of the joints keep to their
  widest name and a field of 10 font sizes where the window is wider than that, as docked across
  the bottom (`begin_fields_fitted`). The results are tables with each column as wide as what is in
  it: the speed check with its column names kept at the top as the list scrolls, the joints with
  the kind, the value and the two tracks next to each other. A click on a row shows it as before.
- `same_line_if_fits` puts the next button beside the one before only when it fits in what is left
  of the line, at the start of the next line otherwise. Used where the route design puts buttons
  side by side, for "Forget the design" in the profile panel, which was cut off at the edge, and for
  the buttons of a switch in the inspector.
- The laying options: the speed, the curve radius and the longest path are fields with the name on
  the left in two columns (`begin_fields`/`field_row`), as in the inspector, the route and the
  profile, the chips of the quick values under them. The segmented choices give the short names
  less of the room when a long one doesn't fit in its even share, and go on in a second bar when
  they don't fit side by side: "Through the clicked points" overflowed its third of the bar.

* fix(editor): a switch laid gets the speed of its diverging track, one breaking a hard rule of ST-T1-A6 isn't laid

- Every switch laid writes the speed of its diverging track (`velocity`): the switch tool on a
  straight, into a curve, from a free end and linked, a double switch, the switches of a slip, a
  switch given another template of the catalogue, and a switch moved along the curve it's bent
  into. A switch of the catalogue had no limit before, one copied from a switch of the scenery kept
  that one's, one laid without a track had the laying speed on both its tracks. The limit is for the
  diverging track alone (`velocity -V`); the own limit of the track it goes into stays for both
  where it's the lower. The switch tool says the speed and what gives it.
- The speed is formula 9.9 of PKP PLK ST-T1-A6 the other way round, V = sqrt((I + D) r / 11.8), with
  the normal cant deficiency of the frog of table 9.7 (110 mm a fixed frog, 130 mm a movable nose),
  rounded down to the steps of the speed limits and no more than table 11.2 gives the basic switch.
  For the fixed frogs the formula gives table 11.2 itself (190 40, 300 50, 500 60, 760 80, 1200
  100 km/h); the 2500-1:26.5 with a movable nose stays 130. A switch bent into a curve takes the
  radius of its diverging track from table 11.8 (one-sided r" = (Rr - t^2)/(R + r), two-sided
  (Rr + t^2)/(R - r)) and the cant of the line with its sign: leaning against the diverging track it
  takes speed away, where the speed check counted it as helping. Rz 60E1-190-1:9 bent out of the
  curve R 600 m with 60 mm: 30 km/h, not 40; the 60E1-500-1:12 of the review, out of R 1200 m with
  60 mm: 60 km/h at its fixed frog (54 at I = 100 mm, the 0.65 m/s2 the editor took), not 107.
- A switch breaking a hard rule isn't laid, the tracks left as they were, and the switch tool says
  why, with the value, the limit and the paragraph: the cant changing within it (11.4 pkt 7), a cant
  ramp ending within it or nearer than 6 m (9.6 pkt 16-17; one ending right at an end of the switch
  is let be, as the snapping of the start offers it), a double switch, a slip or a crossing bent
  (11.4 pkt 4), the curvature of its diverging or its main track turning from one side to the other
  (9.7 pkt 12, KZW II). They were warnings shown after the switch was laid, and on a straight the
  cant wasn't looked at at all. The line is looked at 10 m past the ends of the curve or the
  straight too, so the ramp on the straight before a curve counts. The previews show the refusals.
- A switch moved along its straight or the curve it's bent into, a double switch moved along its
  straight, and a switch given another template go through the same checks; one breaking a rule
  stays as it is.
- Warnings still: 1:9.403 and steeper than 1:9 bent (11.4 pkt 4c-d), a rule of the running and the
  main tracks, which the editor doesn't tell from the side ones, as the warning now says; the limits
  of table 11.9 and a cant over 100 mm in a bent switch (table 9.6), as before.

Tests: unit tests of tables 11.8 and 11.9 (the least main radius bends the diverging track to the
least radius the table gives), table 9.7, the speeds of table 11.2 by formula 9.9, the speed of a
bent switch with the cant with its sign (the example of the review), the cant over a switch on a
straight and a double switch bent. Editor cases `q2_1_switch_speed`, `q2_2_switch_refusals` and
`q2_3_switch_move`, with `expect status` (the status of the switch tool) and `expect steps` (the
undo steps), the fixture with a straight taking a cant on and a compound curve without cant. All
pass; with the changes of the editor reverted all three fail.

* test(editor): a mistyped track fails the self-test, indented comments are skipped, case 7b checks the switch got bent

- A blank line or an indented `#` comment in a script is no longer a command no group takes.
- `trackcant`, `routegauge` and `tracksetdelete` with a track that isn't there count as a failed expectation.
- `expect shaped <switch> <yes|no>`: 7b checks that the gizmo drag bent the switch out of its record before deleting it.
- The ramp-length loop of test_alignment counts in an integer (Sonar S2193).
2026-11-27 03:57:25 +01:00

398 lines
22 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "editor/editorSwitchCurve.hpp"
#include <algorithm>
#include <cmath>
#include <string>
namespace {
// a line every half metre: a straight, a transition curve from it to the arc of the radius, with a straight cant ramp along it, and
// the arc, each of the lengths given
std::vector<switch_curve::track_point> line(double const Straight, double const Transition, double const Arc, double const Radius, double const Cant) {
std::vector<switch_curve::track_point> points;
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 (int k = 0; k * 0.5 <= Straight + Transition + Arc + 1e-9; ++k) {
auto const s{k * 0.5};
if (s > 0.0)
heading += 0.5 * (curvature(s - 0.5) + curvature(s)) * 0.5;
points.push_back({s, heading, cant(s)});
}
return points;
}
// the tracks of a switch Length long laid into the line from the station: the main one along it, the diverging one turning off it
// to the side by the curvature of the basic switch
std::pair<std::vector<switch_curve::track_point>, std::vector<switch_curve::track_point>> laid(std::vector<switch_curve::track_point> const &Line, double const From, double const Length, double const Radius, int const Side) {
std::vector<switch_curve::track_point> main;
std::vector<switch_curve::track_point> branch;
auto const first{std::lower_bound(Line.begin(), Line.end(), From, [](auto const &Point, double const Value) { return Point.station < Value; })};
for (auto point{first}; point != Line.end() && point->station <= From + Length + 1e-9; ++point) {
auto const s{point->station - From};
main.push_back({s, point->heading - first->heading, 0.0});
branch.push_back({s, point->heading - first->heading + Side * s / Radius, 0.0});
}
return {main, branch};
}
bool says(std::vector<std::string> const &Lines, char const *Text) {
return std::any_of(Lines.begin(), Lines.end(), [&](std::string const &Line) { return Line.find(Text) != std::string::npos; });
}
} // namespace
TEST_CASE("switch on a curve: the curvatures of its tracks on a transition curve, read the way the line turns") {
auto const track{line(100.0, 120.0, 200.0, 1000.0, 60.0)};
auto const [main, branch] {laid(track, 150.0, 30.0, 500.0, -1)};
auto const report{switch_curve::check(main, branch, track, 150.0, 180.0, 500.0, 12.0)};
CHECK(report.curved);
CHECK(report.transition);
CHECK(report.main_start == doctest::Approx(51.0 / 120.0 / 1000.0).epsilon(0.02));
CHECK(report.main_end == doctest::Approx(79.0 / 120.0 / 1000.0).epsilon(0.02));
// turning off to the outside of the curve: against it all along, the case KZW I
CHECK(report.branch_start < 0.0);
CHECK(report.branch_end < 0.0);
CHECK(false == says(report.refusals, "KZW II"));
// laid on the ramp, the cant changing under it: not laid so (11.4 pkt 7)
CHECK(report.cant_start == doctest::Approx(25.0).epsilon(0.02));
CHECK(report.cant_end == doctest::Approx(40.0).epsilon(0.02));
CHECK(says(report.refusals, "The cant changes within the switch"));
CHECK(false == says(report.warnings, "The cant changes within the switch"));
}
TEST_CASE("switch on a curve: the diverging track turning from one side to the other is the case KZW II") {
// a transition growing past the curvature of the basic switch along the switch
auto const track{line(100.0, 60.0, 100.0, 300.0, 0.0)};
auto const [main, branch] {laid(track, 125.0, 30.0, 500.0, -1)};
auto const report{switch_curve::check(main, branch, track, 125.0, 155.0, 500.0, 12.0)};
CHECK(report.branch_start < 0.0);
CHECK(report.branch_end > 0.0);
// refused, with the radii it turns with either way
CHECK(says(report.refusals, "KZW II"));
CHECK(says(report.refusals, "(9.7 pkt 12)"));
CHECK(false == says(report.warnings, "KZW II"));
// the main track, on the transition curve alone, turns one way all along
CHECK(false == says(report.refusals, "main track"));
}
TEST_CASE("switch on a curve: the ends of a cant ramp at the ends of the switch or 6 m off it") {
auto const track{line(100.0, 120.0, 200.0, 1000.0, 60.0)};
auto const ramps{switch_curve::ramp_ends(track)};
REQUIRE(ramps.size() == 2);
CHECK(ramps[0] == doctest::Approx(100.0).epsilon(0.01));
CHECK(ramps[1] == doctest::Approx(220.0).epsilon(0.01));
auto const at = [&](double const From) {
auto const [main, branch] {laid(track, From, 30.0, 500.0, 1)};
return switch_curve::check(main, branch, track, From, From + 30.0, 500.0, 12.0);
};
// within it or nearer than 6 m: not laid so
CHECK(says(at(210.0).refusals, "within the switch"));
CHECK(says(at(222.0).refusals, "6 m at least"));
CHECK(says(at(222.0).refusals, "2.0 m off the switch"));
CHECK(false == says(at(220.0).refusals, "within the switch"));
CHECK(says(at(220.0).notes, "at an end of the switch"));
CHECK(at(230.0).refusals.empty());
CHECK(false == says(at(230.0).warnings, "cant ramp"));
// the start pressed near those places drawn to them
std::string what;
CHECK(switch_curve::snapped_start(ramps, 218.5, 30.0, 1, 3.0, &what) == doctest::Approx(220.0));
CHECK(what.find("starts at an end") != std::string::npos);
CHECK(switch_curve::snapped_start(ramps, 228.0, 30.0, 1, 3.0, &what) == doctest::Approx(226.0));
CHECK(what.find("6 m off") != std::string::npos);
CHECK(switch_curve::snapped_start(ramps, 72.0, 30.0, 1, 3.0, &what) == doctest::Approx(70.0));
CHECK(what.find("ends at an end") != std::string::npos);
CHECK(switch_curve::snapped_start(ramps, 160.0, 30.0, 1, 3.0, &what) == doctest::Approx(160.0));
CHECK(what.empty());
}
TEST_CASE("switch on a curve: one with a straight frog bent up to the frog, both tracks straight over it") {
auto const track{line(0.0, 1.0, 400.0, 1500.0, 0.0)};
for (auto const side : {1, -1}) {
CAPTURE(side);
auto [main, branch] {laid(track, 150.0, 27.0, 190.0, side)};
// the last 6 m of both straight, the diverging one with no curve of its own there either: the frog of the switch
auto const frog{21.0};
auto const straighten = [&](std::vector<switch_curve::track_point> &Track) {
auto const at{std::find_if(Track.begin(), Track.end(), [&](auto const &Point) { return Point.station >= frog; })};
for (auto point{at}; point != Track.end(); ++point)
point->heading = at->heading;
};
straighten(main);
straighten(branch);
auto const report{switch_curve::check(main, branch, track, 150.0, 177.0, 190.0, 9.0, 27.0 - frog)};
CHECK(report.curved);
// the curvature of the bent part only: no transition curve under it, the diverging track turning one way all along
CHECK_FALSE(report.transition);
CHECK(false == says(report.refusals, "KZW II"));
CHECK(says(report.warnings, "Bent up to the frog"));
}
}
TEST_CASE("switch on a curve: none of 1:9.403 nor steeper than 1:9 bent in the running and the main tracks, 1:9 itself is") {
auto const track{line(0.0, 1.0, 400.0, 1500.0, 0.0)};
auto const [main, branch] {laid(track, 150.0, 33.0, 300.0, 1)};
auto const banned = [&](double const Ratio) {
CAPTURE(Ratio);
auto const report{switch_curve::check(main, branch, track, 150.0, 183.0, 300.0, Ratio)};
REQUIRE(report.curved);
// the editor tells no main track from a side one: a warning, which says so, not a refusal
CHECK(report.refusals.empty());
return says(report.warnings, "(11.4 pkt 4)") && says(report.warnings, "only warns");
};
// 1:9 of the catalogue and as read off the angle of the tracks
CHECK_FALSE(banned(9.0));
CHECK_FALSE(banned(8.998));
CHECK_FALSE(banned(9.002));
CHECK(banned(9.403));
CHECK(banned(9.41));
CHECK_FALSE(banned(9.51));
CHECK_FALSE(banned(10.0));
CHECK_FALSE(banned(12.0));
CHECK(banned(7.5));
CHECK(banned(6.6));
CHECK(banned(4.8));
}
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 (int k = 0; k * 0.5 <= Length + 1e-9; ++k)
points.push_back({k * 0.5, Heading + Curvature * (k * 0.5), 0.0});
return points;
}
// a slip of 1:9 with the slip curves of R 190 m bent onto the line from the station on: the tracks through it with the curvature of the
// line, the slip curves with theirs plus the one of the line, one turning as the line does, the other against it
switch_curve::slip_report bent_slip(std::vector<switch_curve::track_point> const &Line, double const From, double const Curvature) {
auto const angle{std::atan(1.0 / 9.0)};
auto const half{16.6};
auto const tracks{std::vector{arc(2.0 * half, 0.0, Curvature), arc(2.0 * half, angle, Curvature * std::cos(angle))}};
auto const curves{std::vector{arc(190.0 * angle, 0.0, 1.0 / 190.0 + Curvature), arc(190.0 * angle, angle, -1.0 / 190.0 + Curvature)}};
return switch_curve::check_slip(tracks, curves, Line, From, From + 2.0 * half);
}
} // namespace
TEST_CASE("slip bent into a curve: in a side track only, its slip curve bent the way of the curve no sharper than a side track takes") {
auto const sharp{bent_slip(line(0.0, 0.0, 400.0, 800.0, 0.0), 150.0, 1.0 / 800.0)};
CHECK(sharp.curved);
// none bent, the editor telling no main track from a side one
CHECK(says(sharp.refusals, "R 800 m: no double switch, slip nor crossing is bent (11.4 pkt 4)"));
CHECK(sharp.first == doctest::Approx(1.0 / 800.0).epsilon(0.02));
CHECK(sharp.second == doctest::Approx(std::cos(std::atan(1.0 / 9.0)) / 800.0).epsilon(0.02));
REQUIRE(sharp.curves.size() == 2);
// 1/190 + 1/800: R 153.5 m, 1/190 - 1/800: R 249.2 m
CHECK(1.0 / sharp.curves[0] == doctest::Approx(153.5).epsilon(0.01));
CHECK(1.0 / sharp.curves[1] == doctest::Approx(249.2).epsilon(0.01));
CHECK(says(sharp.warnings, "R 154 m, below the least 180 m"));
CHECK(false == says(sharp.warnings, "R 249 m"));
CHECK(false == says(sharp.warnings, "9.7 pkt 12"));
// R 4000 m: the slip curve of 1/190 + 1/4000, R 181.4 m, still within the side tracks
auto const gentle{bent_slip(line(0.0, 0.0, 400.0, 4000.0, 0.0), 150.0, 1.0 / 4000.0)};
CHECK(gentle.curved);
CHECK(says(gentle.refusals, "(11.4 pkt 4)"));
CHECK(false == says(gentle.warnings, "table 9.2"));
CHECK(gentle.notes.empty());
// one on a straight is no bent one
auto const straight{bent_slip(line(400.0, 0.0, 0.0, 1000.0, 0.0), 150.0, 0.0)};
CHECK_FALSE(straight.curved);
CHECK(straight.warnings.empty());
CHECK(straight.refusals.empty());
}
TEST_CASE("slip bent into a curve: the cant of the side track, a track through it turning from one side to the other") {
// the cant the same over it, none recommended in a side track though
auto const canted{bent_slip(line(0.0, 0.0, 400.0, 1000.0, 30.0), 150.0, 1.0 / 1000.0)};
CHECK(canted.cant_start == doctest::Approx(30.0));
CHECK(canted.cant_end == doctest::Approx(30.0));
CHECK(false == says(canted.refusals, "The cant changes"));
CHECK(says(canted.notes, "9.3 pkt 5"));
// a reverse curve under it
auto const curve{line(0.0, 0.0, 400.0, 1000.0, 0.0)};
auto first{arc(33.2, 0.0, 1.0 / 1000.0)};
for (auto &point : first)
if (point.station > 16.6)
point.heading = 16.6 / 1000.0 - (point.station - 16.6) / 1000.0;
auto const angle{std::atan(1.0 / 9.0)};
auto const report{switch_curve::check_slip({first, arc(33.2, angle, 1.0 / 1000.0)}, {arc(21.0, 0.0, 1.0 / 190.0)}, curve, 150.0, 183.2)};
CHECK(says(report.refusals, "9.7 pkt 12"));
}
TEST_CASE("switch exit: a curve right behind a straight frog, its sudden changes of the cant deficiency apart or together") {
double const sw{1.0 / 190.0};
// R 190 on behind a frog straight for 6.09 m, at 40 km/h: apart, 99 mm at the end, within the 130 mm of table 9.15
auto const same{switch_curve::check_exit(sw, 6.092, {{40.0, sw, sw}}, 40.0)};
CHECK(same.apart == doctest::Approx(6.092));
CHECK(same.element == doctest::Approx(6.0));
CHECK(same.change == doctest::Approx(99.4).epsilon(0.01));
CHECK(same.warnings.empty());
// the other way behind a frog straight of 1.66 m only: together, 199 mm, over the 130 mm
auto const reverse{switch_curve::check_exit(sw, 1.662, {{40.0, -sw, -sw}}, 40.0)};
CHECK(reverse.apart == doctest::Approx(1.662));
CHECK(reverse.change == doctest::Approx(198.8).epsilon(0.01));
REQUIRE(reverse.warnings.size() == 1);
CHECK(says(reverse.warnings, "tables 9.15, 9.16"));
// the same way behind it: together the curvature hardly changes
CHECK(switch_curve::check_exit(sw, 1.662, {{40.0, sw, sw}}, 40.0).warnings.empty());
// a straight of 5 m laid on first: 6.66 m apart, the curve the other way alone, 99 mm
auto const later{switch_curve::check_exit(sw, 1.662, {{5.0, 0.0, 0.0}, {40.0, -sw, -sw}}, 40.0)};
CHECK(later.apart == doctest::Approx(6.662));
CHECK(later.warnings.empty());
// a sharp curve of R 100 alone: 189 mm
CHECK(says(switch_curve::check_exit(sw, 6.092, {{30.0, 0.01, 0.01}}, 40.0).warnings, "table 9.15"));
// a transition out of the frog straight: no sudden change behind it
CHECK(switch_curve::check_exit(sw, 1.662, {{20.0, 0.0, -sw}, {20.0, -sw, -sw}}, 40.0).warnings.empty());
// the curve of a switch with a curved frog going on: nothing of the switch to judge
auto const on{switch_curve::check_exit(1.0 / 300.0, 0.0, {{30.0, 1.0 / 300.0, 1.0 / 300.0}}, 50.0)};
CHECK(on.apart < 0.0);
CHECK(on.warnings.empty());
}
TEST_CASE("switch on a curve: a double switch isn't bent, nor is a slip or a crossing (11.4 pkt 4)") {
auto const track{line(0.0, 1.0, 400.0, 1500.0, 0.0)};
auto const [main, branch] {laid(track, 150.0, 30.0, 190.0, 1)};
auto const bent{switch_curve::check(main, branch, track, 150.0, 180.0, 190.0, 9.0, 0.0, true)};
REQUIRE(bent.curved);
CHECK(says(bent.refusals, "Bent into R 1500 m: no double switch, slip nor crossing is bent (11.4 pkt 4)"));
// a single one of the same shape is
CHECK(switch_curve::check(main, branch, track, 150.0, 180.0, 190.0, 9.0).refusals.empty());
// and a double one on a straight
auto const straight{line(400.0, 0.0, 0.0, 1000.0, 0.0)};
auto const [smain, sbranch] {laid(straight, 150.0, 30.0, 190.0, 1)};
auto const on_straight{switch_curve::check(smain, sbranch, straight, 150.0, 180.0, 190.0, 9.0, 0.0, true)};
CHECK_FALSE(on_straight.curved);
CHECK(on_straight.refusals.empty());
}
TEST_CASE("switch on a straight: the cant of the line over it, no ramp within it nor nearer than 6 m (11.4 pkt 7, 9.6 pkt 16)") {
// a straight of 100 m, a ramp of 60 m up to 60 mm, then 100 m of 60 mm
std::vector<switch_curve::track_point> straight;
for (int k = 0; k * 0.5 <= 260.0 + 1e-9; ++k) {
auto const s{k * 0.5};
straight.push_back({s, 0.0, s <= 100.0 ? 0.0 : s <= 160.0 ? (s - 100.0) : 60.0});
}
auto const at = [&](double const From) { return switch_curve::check_line(straight, From, From + 33.2); };
CHECK(at(20.0).refusals.empty());
CHECK(at(60.0).refusals.empty());
// 1.8 m off the start of the ramp
CHECK(says(at(65.0).refusals, "1.8 m off the switch, 6 m at least (9.6 pkt 16)"));
// on it: the cant changing under it, the start of the ramp within it
auto const on{at(90.0)};
CHECK(says(on.refusals, "The cant changes within the switch, 0 to 23 mm: it's to stay the same over it (11.4 pkt 7)"));
CHECK(says(on.refusals, "10.0 m from its start"));
// ending right where the ramp starts, and of the cant all along
CHECK(at(100.0 - 33.2).refusals.empty());
CHECK(says(at(100.0 - 33.2).notes, "at an end of the switch"));
CHECK(at(180.0).refusals.empty());
CHECK(at(180.0).cant_start == doctest::Approx(60.0));
}
TEST_CASE("table 11.8: the diverging track of a switch bent one-sided and two-sided, the tangent t correcting the sum of the curvatures") {
// Rz 60E1-500-1:12: t = 500 tan(atan(1/12) / 2) = 20.797 m, as a of the catalogue
// a) two-sided, the main track bent to R 1200 against the diverging one: r" = (R r + t^2) / (R - r)
CHECK(switch_curve::bent_radius(-1200.0, 500.0, 12.0) == doctest::Approx((1200.0 * 500.0 + 20.797 * 20.797) / 700.0).epsilon(1e-5));
CHECK(switch_curve::bent_radius(-1200.0, 500.0, 12.0) == doctest::Approx(857.76).epsilon(1e-5));
// b) one-sided, the main track bent to R 1200 with it: r" = (R r - t^2) / (R + r)
CHECK(switch_curve::bent_radius(1200.0, 500.0, 12.0) == doctest::Approx(352.69).epsilon(1e-5));
// near the plain sums of the curvatures, 1 / (1/500 -+ 1/1200)
CHECK(switch_curve::bent_radius(-1200.0, 500.0, 12.0) == doctest::Approx(857.14).epsilon(1e-3));
CHECK(switch_curve::bent_radius(1200.0, 500.0, 12.0) == doctest::Approx(352.94).epsilon(1e-3));
// b) bent from the diverging track: the main track sharper than it takes it past straight, r" = (R r + t^2) / (r - R), the other way
CHECK(switch_curve::bent_radius(-400.0, 500.0, 12.0) == doctest::Approx(-2004.33).epsilon(1e-5));
// the main track as sharp as the diverging curve against it: the diverging track straight; not bent: the basic switch
CHECK(switch_curve::bent_radius(-500.0, 500.0, 12.0) == 0.0);
CHECK(switch_curve::bent_radius(0.0, 500.0, 12.0) == 500.0);
}
TEST_CASE("table 11.9: the least radii of the switches bent one-sided, the diverging track of the least main radius by table 11.8") {
struct row {
double radius;
double ratio;
double branch; // the limiting curvature, 1/km
double least_branch; // m
double least_main; // m
double branch_exception;
double least_branch_exception;
double least_main_exception;
};
// the values in the brackets for 300 and 500, allowed by way of exception
row const rows[]{{300.0, 9.0, 4.000, 250.0, 1505.522, 4.673, 214.0, 749.722},
{500.0, 12.0, 4.000, 250.0, 501.730, 4.673, 214.0, 375.638},
{760.0, 14.0, 3.333, 300.0, 497.250, 3.333, 300.0, 497.250},
{1200.0, 18.5, 2.169, 461.0, 750.001, 2.169, 461.0, 750.001},
{2500.0, 26.5, 1.063, 941.0, 1510.0, 1.063, 941.0, 1510.0}};
for (auto const &entry : rows) {
CAPTURE(entry.radius);
auto const limit{switch_curve::bent_limit_of(entry.radius)};
REQUIRE(limit.has_value());
CHECK(limit->branch * 1000.0 == doctest::Approx(entry.branch));
CHECK(limit->main == doctest::Approx(entry.least_main));
CHECK(limit->branch_exception * 1000.0 == doctest::Approx(entry.branch_exception));
CHECK(limit->main_exception == doctest::Approx(entry.least_main_exception));
// the least main radius bends the diverging track one-sided to the least radius the table gives it
CHECK(switch_curve::bent_radius(entry.least_main, entry.radius, entry.ratio) == doctest::Approx(entry.least_branch).epsilon(0.001));
CHECK(switch_curve::bent_radius(entry.least_main_exception, entry.radius, entry.ratio) == doctest::Approx(entry.least_branch_exception).epsilon(0.001));
}
CHECK_FALSE(switch_curve::bent_limit_of(190.0).has_value());
}
TEST_CASE("table 9.7: the cant deficiency over a switch, fixed frog and movable nose") {
auto const fixed{switch_curve::switch_deficiency(false)};
CHECK(fixed.recommended == 90.0);
CHECK(fixed.normal == 110.0);
CHECK(fixed.limit == 110.0);
auto const movable{switch_curve::switch_deficiency(true)};
CHECK(movable.recommended == 100.0);
CHECK(movable.normal == 130.0);
CHECK(movable.limit == 130.0);
}
TEST_CASE("formula 9.9 and table 9.7: the speeds of table 11.2 on the diverging tracks of the basic switches with a fixed frog") {
// V = sqrt(I R / 11.8) at the normal 110 mm, rounded down to 10 km/h: 190 40, 300 (1:9 and 1:9.403) 50, 500 60, 760 80, 1200 100
auto const table = [](double const Radius) { return std::floor(switch_curve::curve_speed(Radius, 0.0, switch_curve::switch_deficiency(false).normal) / 10.0) * 10.0; };
CHECK(table(190.0) == 40.0);
CHECK(table(300.0) == 50.0);
CHECK(table(500.0) == 60.0);
CHECK(table(760.0) == 80.0);
CHECK(table(1200.0) == 100.0);
// the 2500-1:26.5 with a movable nose would take 166 km/h; table 11.2 and Id-4 give it 130, which the editor keeps
CHECK(switch_curve::curve_speed(2500.0, 0.0, switch_curve::switch_deficiency(true).normal) == doctest::Approx(166.0).epsilon(0.001));
// a straight track takes any speed, a cant against the turn as large as the deficiency none
CHECK(std::isinf(switch_curve::curve_speed(0.0, 0.0, 110.0)));
CHECK(switch_curve::curve_speed(500.0, -110.0, 110.0) == 0.0);
CHECK(switch_curve::curve_speed(500.0, -150.0, 110.0) == 0.0);
}
TEST_CASE("formula 9.9: the speed on the diverging track of a bent switch, the cant with its sign, the frog by table 9.7") {
// the example of the review: Rz 60E1-500-1:12 bent outward into R 1200 m with 60 mm of cant, two-sided, r" = 857.8 m. The cant
// leans against the diverging track: with I up to 100 mm, the 0.65 m/s2 the editor took for the switch branches, about 54 km/h,
// where the cant taken without its sign gave 107
auto const radius{switch_curve::bent_radius(-1200.0, 500.0, 12.0)};
CHECK(switch_curve::curve_speed(radius, -60.0, 100.0) == doctest::Approx(53.9).epsilon(0.002));
CHECK(switch_curve::curve_speed(radius, 60.0, 100.0) == doctest::Approx(107.8).epsilon(0.002));
// by its frog, table 9.7: fixed, 90 recommended and 110 normal; movable nose, 100 and 130
auto const fixed{switch_curve::switch_deficiency(false)};
auto const movable{switch_curve::switch_deficiency(true)};
CHECK(switch_curve::curve_speed(radius, -60.0, fixed.recommended) == doctest::Approx(46.7).epsilon(0.002));
CHECK(switch_curve::curve_speed(radius, -60.0, fixed.normal) == doctest::Approx(60.3).epsilon(0.002));
CHECK(switch_curve::curve_speed(radius, -60.0, movable.recommended) == doctest::Approx(53.9).epsilon(0.002));
CHECK(switch_curve::curve_speed(radius, -60.0, movable.normal) == doctest::Approx(71.3).epsilon(0.002));
// bent inward, one-sided into R 1200: r" = 352.7 m, the cant leaning into its turn, 71 km/h at 110 mm
CHECK(switch_curve::curve_speed(switch_curve::bent_radius(1200.0, 500.0, 12.0), 60.0, fixed.normal) == doctest::Approx(71.3).epsilon(0.002));
// Rz 60E1-190-1:9 in the curve R 600 m with 60 mm of the self-test scenery: outward 278.3 m and 34.3 km/h, inward 144.2 m and 45.6 km/h
CHECK(switch_curve::bent_radius(-600.0, 190.0, 9.0) == doctest::Approx(278.3).epsilon(0.001));
CHECK(switch_curve::curve_speed(switch_curve::bent_radius(-600.0, 190.0, 9.0), -60.0, fixed.normal) == doctest::Approx(34.3).epsilon(0.002));
CHECK(switch_curve::bent_radius(600.0, 190.0, 9.0) == doctest::Approx(144.2).epsilon(0.001));
CHECK(switch_curve::curve_speed(switch_curve::bent_radius(600.0, 190.0, 9.0), 60.0, fixed.normal) == doctest::Approx(45.6).epsilon(0.002));
}