17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-31 22:49:05 +01:00

fix(editor): the plan warns of the curved track adjoining a curve only where the curvature jumps there: a curve going on from the diverging track of a switch at its radius (R 300 after R 301 in wsd) no longer has it. The side the adjoining track turns to is taken with its radius into the chain and the design, and the curvature the design meets it with, signed by its turn, compared with it, within 5%; a design kept without the side is taken for turning its way. Unit test: R 300 from the very start after R 301 turning the same way gives no warning, turning the other way or starting with a straight does

This commit is contained in:
maj00r
2026-10-25 11:14:49 +01:00
parent bbb3e9e61e
commit 29b9b93353
6 changed files with 85 additions and 6 deletions

View File

@@ -129,6 +129,36 @@ TEST_CASE("alignment: a sharp bend between short straights is laid where clicked
CHECK(line.vertices.front().x == doctest::Approx(120.0));
}
TEST_CASE("alignment: a curve going on at the radius of the curved track before it doesn't change the curvature abruptly") {
auto const adjoining = [](alignment::result const &Line) {
return std::any_of(Line.warnings.begin(), Line.warnings.end(), [](std::string const &Warning) { return Warning.find("adjoining track at the start") != std::string::npos; });
};
// R 300 with no transition from the very start, as a curve after the diverging track of a switch, R 301 there
auto const tangent{300.0 * std::tan(10.0 * pi / 180.0)};
auto design{straights({tangent, 200.0}, {20.0 * pi / 180.0}, 40.0)};
auto &vertex{design.vertices.front()};
vertex.radius = 300.0;
vertex.transition_in = 0.0;
vertex.transition_out = 0.0;
design.start_radius = 301.0;
design.start_turn = 1;
auto const line{alignment::compute(design)};
REQUIRE(line.valid);
REQUIRE_FALSE(line.elements.empty());
CHECK(line.elements.front().kind == alignment::element_kind::arc);
CHECK_FALSE(adjoining(line));
// the track before turning the other way, or the curve starting with a straight: the curvature jumps
design.start_turn = -1;
CHECK(adjoining(alignment::compute(design)));
design.start_turn = 1;
auto later{straights({tangent + 80.0, 200.0}, {20.0 * pi / 180.0}, 40.0)};
later.vertices.front() = vertex;
later.vertices.front().position = {tangent + 80.0, 0.0};
later.start_radius = 301.0;
later.start_turn = 1;
CHECK(adjoining(alignment::compute(later)));
}
TEST_CASE("alignment: two bends share the straight between them") {
auto design{straights({600.0, 250.0, 600.0}, {4.0 * pi / 180.0, -5.0 * pi / 180.0}, 120.0)};
std::vector<char> corners{1, 1};