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

fix: coupler force of vehicles facing each other taken back along the other vehicle's axis

CForce runs along the axis of its own vehicle, so the force the other vehicle takes back on its coupler of the pair
is turned around once more when the vehicles face each other (-CF * DirPatch()), as that vehicle computes it itself.

Tests: the coupler forces of the pair facing each other and facing the same way.
This commit is contained in:
jerrrrycho
2026-10-19 01:09:35 +02:00
parent 00805cfe77
commit 52aa9b16cf
2 changed files with 28 additions and 11 deletions

View File

@@ -427,16 +427,32 @@ TEST_CASE("couplers: automatic couplers of different control systems couple with
TEST_CASE("couplers: the coupler force of vehicles facing each other lands on the couplers holding them") {
// the force a vehicle takes from its coupler, the other one takes back on its own coupler of the pair, whichever
// way the vehicles face; it used to land on the far end of the other vehicle when they faced each other
// way the vehicles face; it used to land on the far end of the other vehicle when they faced each other.
// CForce runs along the axis of its own vehicle, so the two forces of the pair are opposite along the track: of
// opposite signs for vehicles facing the same way, of the same sign for vehicles facing each other
auto first{automatic_wagon(5.0, "first")};
auto second{automatic_wagon(0.0, "second")};
test::pair pair{first, end::front, second, end::front, 1.0};
pair.run(5.0);
REQUIRE(pair.coupled());
pair.step();
REQUIRE(second->Couplers[end::front].CForce != 0.0);
CHECK(first->Couplers[end::front].CForce == doctest::Approx(-second->Couplers[end::front].CForce));
CHECK(first->Couplers[end::rear].CForce == 0.0); // nothing there
CHECK(second->Couplers[end::rear].CForce == 0.0);
SUBCASE("facing each other") {
test::pair pair{first, end::front, second, end::front, 1.0};
pair.run(5.0);
REQUIRE(pair.coupled());
pair.step();
REQUIRE(second->Couplers[end::front].CForce != 0.0);
CHECK(first->Couplers[end::front].CForce == doctest::Approx(second->Couplers[end::front].CForce));
CHECK(first->Couplers[end::rear].CForce == 0.0); // nothing there
CHECK(second->Couplers[end::rear].CForce == 0.0);
}
SUBCASE("facing the same way") {
test::pair pair{first, end::front, second, end::rear, 1.0};
pair.run(5.0);
REQUIRE(pair.coupled());
pair.step();
REQUIRE(second->Couplers[end::rear].CForce != 0.0);
CHECK(first->Couplers[end::front].CForce == doctest::Approx(-second->Couplers[end::rear].CForce));
CHECK(first->Couplers[end::rear].CForce == 0.0);
CHECK(second->Couplers[end::front].CForce == 0.0);
}
}