mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 09:27:10 +01:00
ca1f2239df
E5 (editor-tracks-domain.md §4 "Rozjazd", §7): every type of the catalogue is a turnout the model lays, its tracks lines it owns and its legs nodes, kept whole or refused like the ordinary switches E2b laid. E2b refused the rest with "stage E5". - Secant blades (S42): the diverging track runs along the main one for the pre-blade stretch and turns off it by the angle of the blades at their tips, the rest of 1:n on its arc; a turn inside the track, the node at the start keeping the heading of the main track. The generator ends a piece there with the heading of the element before it (unchanged where a line runs on in its heading). - Double switches (Rpd, Rpj, Rps): the main track cut at the start of the second switch, its node holding the main track, the main track of the second switch (main2) and its diverging track, to the other side or the same one, as switch_design::build() lays it. Written as the switch tool writes them: the first switch, a plain track of a metre before the second one (the simulation joins a switch to plain tracks only), the second switch. - Symmetric switches (Rls): both tracks turning off by half of the angle, to both sides, laid at a free end of a line, which they end (the line beyond it would have to turn at the node); not moved along the line. - Slips (Rkp, Rkpd) and diamond crossings (Skrz): the main track a part of the line, the crossing track across its middle at the angle of the slip between two nodes of its own, the slip curves from the start to the end of the crossing track and, of a double slip, from its start to the end of the main track; slip_of() lays the curves with the blades of the ordinary switch of the rail, radius and angle (no data of the slips' own blades was found), passing the crossing as near as the rails of the simulator's profile let them. The three with the blades outside of the diamond whose curves then reach past the half length of Id-4 (49E1 190-1:6,6, 300-1:9, 500-1:9, by up to 0.3 m) are laid as long as their curves. Written as the switch tool writes them: a switch at each leg a slip curve leaves, the tracks crossing and the middles of the slip curves plain tracks, the joints inside it the same numbers on both sides. - The rules: a double switch, a slip, a crossing (11.4 pkt 4 a, b) and a symmetric switch (no rule of table 11.8 for it) lie on straights only; an invariant, refused with the reason before anything is laid. The norms judge the tracks crossing at a slip or a crossing as crossings (no cant, tab. 9.6), its slip curves as diverging tracks. - The ends of the tracks of a turnout which carry no line through their node (the starts of the diverging tracks, the ends of the slip curves) are branch_end(); a node holds such an end beside a track of the same turnout on its side. settle() lays all the tracks a turnout lays itself (lay_tracks()), the nodes of its own where they end; lifting, moving, changing (to another kind too) and removing a turnout take all of them along. - The project file: the turnout record gets "second <node> <main2> <diverging2> <node>" and "crossing <line> <node> <node> slip <line>" where the turnout has them (diverging 0 0 for a crossing); version 1, unreleased, read as before without them. The generated section keeps each track a turnout is made of. - TSI INF 4.2.3.4(1), 150 m at least, judges the plain line, not the curves of switches (4.2.5): its hard row leaves out the tracks of the turnouts, so the industrial S42 switches of R 70 and 140 m are laid. Tests: U: every type of the catalogue laid (41 ordinary, 3 symmetric, 15 double, 18 slips, 20 crossings) on a straight to both sides along the line and against it, its legs where the catalogue puts them (the main track a + b, 1:n at the ends, the second switch at the stagger, the crossing track at the angle of the slip, half its length from the crossing), moved and taken out, the line one again, each a step to undo; the turn of the secant blades of S42-190-1:7 at the end of the pre-blade stretch; a double switch, two slips and a crossing refused in a curve, a secant S42 bent in a side track, a symmetric switch refused at the end of a curve. The three fitted to the tangents of S42-140-1:6,6 16/12 measured are refused by the norms (tab. 9.14) where the transition one is. P: 200 random edits with every type along arcs and transitions, seeds 5150, 2718 and 1618: the invariants after each, a refusal changing nothing, undone back to the start exactly. G: every type made into the tracks of the simulator and read back by TTrack::Load, the ends of the paths at the legs or at each other to the bit, the velocity and the frog; a double switch, a double slip and a crossing written to the project file and read back, their tracks laid again the same to the bit. The E2b case of the types refused now checks that they're laid. Unit tests 1077 -> 1086.
211 lines
9.0 KiB
C++
211 lines
9.0 KiB
C++
#pragma once
|
|
|
|
// the lines of the track geometry the tests of editor/layout edit and make tracks of: a line of three curves between free ends, the
|
|
// norms of a line of 80 km/h of mixed traffic, and the invariants of the lines and the nodes checked on their own, apart from the
|
|
// checks of the model
|
|
|
|
#include "doctest.h"
|
|
#include "editor/editorGeometry.hpp"
|
|
#include "editor/editorSwitchCurve.hpp"
|
|
#include "editor/layout/layoutCommands.hpp"
|
|
#include "editor/layout/layoutTurnout.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace test::layout_fixture {
|
|
|
|
inline norms::line_class line_class() {
|
|
norms::line_class result;
|
|
result.vmax = 80.0;
|
|
result.kind = norms::traffic::mixed;
|
|
result.track = norms::track_kind::main;
|
|
return result;
|
|
}
|
|
|
|
// a vertex with the cant and the transitions the norms prefer for the radius
|
|
inline layout::vertex curve(glm::dvec2 const &Point, double const Radius) {
|
|
auto const preferred{layout::preferred_curve(norms::profile_id::plk, line_class(), Radius)};
|
|
layout::vertex result;
|
|
result.point = Point;
|
|
result.radius = Radius;
|
|
result.cant = preferred.cant;
|
|
result.transition_in = result.transition_out = preferred.transition;
|
|
return result;
|
|
}
|
|
|
|
// three curves, R 800, 600 and 900, with straights between them, a break of the grade line with a vertical curve
|
|
inline layout::create_line three_curves(layout::transition_shape const Shape = layout::transition_shape::clothoid, glm::dvec3 const &Offset = glm::dvec3{0.0}) {
|
|
layout::create_line result;
|
|
result.start = glm::dvec3{0.0, 100.0, 0.0} + Offset;
|
|
result.end = glm::dvec3{2200.0, 104.0, 600.0} + Offset;
|
|
glm::dvec2 const shift{Offset.x, Offset.z};
|
|
result.vertices = {curve(glm::dvec2{600.0, 0.0} + shift, 800.0), curve(glm::dvec2{1100.0, 300.0} + shift, 600.0), curve(glm::dvec2{1600.0, 300.0} + shift, 900.0)};
|
|
result.grades = {{1000.0, 103.0 + Offset.y, 10000.0}};
|
|
result.transition = Shape;
|
|
result.ramp = Shape == layout::transition_shape::bloss ? layout::ramp_shape::bloss : layout::ramp_shape::linear;
|
|
result.category = line_class();
|
|
return result;
|
|
}
|
|
|
|
inline std::string reasons_of(layout::outcome const &Outcome) {
|
|
std::string result;
|
|
for (auto const &reason : Outcome.reasons) {
|
|
result += reason + "; ";
|
|
}
|
|
return result;
|
|
}
|
|
|
|
inline std::string reasons_of(layout::verdict const &Verdict) {
|
|
std::string result;
|
|
for (auto const &reason : Verdict.refusals()) {
|
|
result += reason + "; ";
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// the invariants, checked here on their own: each line laid and running on from element to element, the cant running on, the ends at
|
|
// their nodes and running on through them, the topology of the ends (two at a node, three at the start of a turnout: its two tracks on one
|
|
// side of it); the turnouts whole, their main tracks as long as their types, their tracks from their start, their velocity by the speed rule;
|
|
// and the model's own check, the norms along the chains and the rules of the turnouts with it (check_invariants; check_structure leaves it out)
|
|
inline void check_structure(layout::network const &Network) {
|
|
for (auto const &[id, line] : Network.lines()) {
|
|
CAPTURE(layout::number(id));
|
|
auto const &solved{line.solved};
|
|
REQUIRE(solved.valid());
|
|
auto const *start{Network.find(line.start)};
|
|
auto const *end{Network.find(line.end)};
|
|
REQUIRE(start != nullptr);
|
|
REQUIRE(end != nullptr);
|
|
CHECK(line.start != line.end);
|
|
// the line begins at its node, to the bit, and ends there within the sum of the rounding along it
|
|
CHECK(solved.elements.front().origin == geometry::plan_of(start->position));
|
|
auto const &last{solved.elements.back()};
|
|
CHECK(glm::distance(last.position(last.length), geometry::plan_of(end->position)) < 1e-6);
|
|
CHECK(solved.start.position == start->position);
|
|
CHECK(solved.end.position == end->position);
|
|
for (std::size_t i = 1; i < solved.elements.size(); ++i) {
|
|
auto const &a{solved.elements[i - 1]};
|
|
auto const &b{solved.elements[i]};
|
|
CHECK(glm::distance(a.position(a.length), b.origin) < 1e-6);
|
|
// a track a turnout lays may turn where its secant blades meet the stock rails, by less than 2 degrees
|
|
auto const kink{std::abs(geometry::signed_angle(a.tangent(a.length), b.direction))};
|
|
CHECK((kink < 1e-9 || (layout::laid_by_turnout(Network, id) && kink < 0.035)));
|
|
CHECK(a.end_chainage() == doctest::Approx(b.chainage).epsilon(1e-12));
|
|
}
|
|
for (std::size_t i = 1; i < solved.cant.size(); ++i) {
|
|
CHECK(std::abs(solved.cant[i - 1].end - solved.cant[i].start) <= 0.5);
|
|
CHECK(solved.cant[i - 1].to == doctest::Approx(solved.cant[i].from).epsilon(1e-12));
|
|
}
|
|
CHECK(std::abs(solved.grade(0.0) - solved.start.grade) < 1e-12);
|
|
}
|
|
for (auto const &[id, node] : Network.nodes()) {
|
|
CAPTURE(layout::number(id));
|
|
REQUIRE_FALSE(node.ends.empty());
|
|
std::vector<layout::end_ref> through;
|
|
for (auto const &end : node.ends) {
|
|
if (layout::branch_end(Network, end)) {
|
|
// a branch of a turnout beside a track of it carrying the line through the node, on its side
|
|
auto const *switched{layout::owner_of(Network, end.line)};
|
|
REQUIRE(switched != nullptr);
|
|
CHECK(std::ranges::any_of(node.ends, [&](layout::end_ref const &Each) {
|
|
auto const *owner{layout::owner_of(Network, Each.line)};
|
|
return owner != nullptr && owner->id == switched->id && false == layout::branch_end(Network, Each) && Each.side() == end.side();
|
|
}));
|
|
}
|
|
else {
|
|
through.push_back(end);
|
|
}
|
|
}
|
|
REQUIRE(through.size() <= 2);
|
|
if (through.size() == 2) {
|
|
CHECK(through[0].side() != through[1].side());
|
|
}
|
|
for (auto const &end : node.ends) {
|
|
auto const *line{Network.find(end.line)};
|
|
REQUIRE(line != nullptr);
|
|
CHECK(line->node_at(end.end) == id);
|
|
auto const &values{end.end == layout::line_end::start ? line->solved.start : line->solved.end};
|
|
auto const sense{static_cast<double>(end.sense)};
|
|
CHECK(values.position == node.position);
|
|
CHECK(std::abs(geometry::signed_angle(node.heading, values.heading * sense)) <= 1e-9);
|
|
CHECK(std::abs(values.cant * sense - node.cant) <= 0.5);
|
|
CHECK(std::abs(values.grade * sense - node.grade) <= 0.002);
|
|
}
|
|
}
|
|
for (auto const &[id, turnout] : Network.turnouts()) {
|
|
CAPTURE(layout::number(id));
|
|
CAPTURE(turnout.type);
|
|
auto const type{layout::turnout_type_of(turnout.type)};
|
|
REQUIRE(type.has_value());
|
|
using layout::turnout_kind;
|
|
auto const kind{type->kind};
|
|
CHECK(layout::kind_of(turnout) == kind);
|
|
for (auto const track : layout::tracks_of(turnout)) {
|
|
auto const *line{Network.find(track)};
|
|
REQUIRE(line != nullptr);
|
|
CHECK(line->turnout == id);
|
|
}
|
|
auto const *main{Network.find(turnout.main)};
|
|
auto const between = [&](layout::line_id const Track, layout::node_id const From, layout::node_id const To, int const Direction) {
|
|
auto const *line{Network.find(Track)};
|
|
REQUIRE(line != nullptr);
|
|
CHECK((Direction > 0 ? line->start : line->end) == From);
|
|
CHECK((Direction > 0 ? line->end : line->start) == To);
|
|
CHECK(line->solved.start.position == Network.find(line->start)->position);
|
|
CHECK(line->solved.end.position == Network.find(line->end)->position);
|
|
};
|
|
switch (kind) {
|
|
case turnout_kind::twofold:
|
|
between(turnout.main, turnout.start, turnout.second, turnout.direction);
|
|
between(turnout.main2, turnout.second, turnout.main_end, turnout.direction);
|
|
between(turnout.diverging, turnout.start, turnout.diverging_end, 1);
|
|
between(turnout.diverging2, turnout.second, turnout.diverging2_end, 1);
|
|
CHECK(main->solved.length == doctest::Approx(type->stagger).epsilon(1e-9));
|
|
CHECK(Network.find(turnout.main2)->solved.length == doctest::Approx(type->length - type->stagger).epsilon(1e-9));
|
|
break;
|
|
case turnout_kind::symmetric:
|
|
between(turnout.main, turnout.start, turnout.main_end, 1);
|
|
between(turnout.diverging, turnout.start, turnout.diverging_end, 1);
|
|
break;
|
|
case turnout_kind::slip:
|
|
case turnout_kind::crossing:
|
|
between(turnout.main, turnout.start, turnout.main_end, turnout.direction);
|
|
between(turnout.crossing, turnout.cross_start, turnout.cross_end, 1);
|
|
if (kind == turnout_kind::slip) {
|
|
between(turnout.diverging, turnout.start, turnout.cross_end, 1);
|
|
}
|
|
if (turnout.diverging2 != layout::line_id::none) {
|
|
between(turnout.diverging2, turnout.cross_start, turnout.main_end, 1);
|
|
}
|
|
CHECK(main->solved.length == doctest::Approx(type->length).epsilon(1e-9));
|
|
break;
|
|
default:
|
|
between(turnout.main, turnout.start, turnout.main_end, turnout.direction);
|
|
between(turnout.diverging, turnout.start, turnout.diverging_end, 1);
|
|
CHECK(main->solved.length == doctest::Approx(type->length).epsilon(1e-9));
|
|
break;
|
|
}
|
|
CHECK(turnout.speed_diverging > 0.0);
|
|
CHECK(turnout.speed_main > 0.0);
|
|
if (kind == turnout_kind::crossing) {
|
|
CHECK(turnout.velocity == turnout.speed_main);
|
|
}
|
|
else {
|
|
CHECK(turnout.velocity == switch_curve::written_velocity(turnout.speed_main, turnout.speed_diverging));
|
|
}
|
|
}
|
|
}
|
|
|
|
inline void check_invariants(layout::network const &Network) {
|
|
check_structure(Network);
|
|
auto const verdict{layout::check_all(Network)};
|
|
auto const reasons{reasons_of(verdict)};
|
|
CAPTURE(reasons);
|
|
CHECK(verdict.fine());
|
|
}
|
|
|
|
} // namespace test::layout_fixture
|