Highlight tunnel connections in green when selected

This commit is contained in:
2026-07-21 21:16:21 +02:00
parent a75222f111
commit a8a6a04f1e
6 changed files with 220 additions and 12 deletions

View File

@@ -169,3 +169,80 @@ TEST_CASE("A candidate beyond the max distance is not matched")
REQUIRE(result.resolvedType == BuildingType::TunnelEntry);
REQUIRE(!result.partnerTile.has_value());
}
// ---------------------------------------------------------------------------
// findTunnelPartner: the matching end of an existing selected tunnel
// (REQ-BLD-TUNNEL-SELECT-HIGHLIGHT)
// ---------------------------------------------------------------------------
TEST_CASE("findTunnelPartner: a selected entry finds its exit ahead")
{
TunnelMap tunnels;
tunnels[{2, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East};
tunnels[{6, 5}] = TunnelTileInfo{BuildingType::TunnelExit, Rotation::East};
const std::optional<QPoint> partner = findTunnelPartner(
makeLookup(tunnels), QPoint(2, 5), BuildingType::TunnelEntry, Rotation::East, 10);
REQUIRE(partner.has_value());
REQUIRE(*partner == QPoint(6, 5));
}
TEST_CASE("findTunnelPartner: a selected exit finds its entry behind")
{
TunnelMap tunnels;
tunnels[{2, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East};
tunnels[{6, 5}] = TunnelTileInfo{BuildingType::TunnelExit, Rotation::East};
const std::optional<QPoint> partner = findTunnelPartner(
makeLookup(tunnels), QPoint(6, 5), BuildingType::TunnelExit, Rotation::East, 10);
REQUIRE(partner.has_value());
REQUIRE(*partner == QPoint(2, 5));
}
TEST_CASE("findTunnelPartner: an unpaired tunnel has no partner")
{
TunnelMap tunnels;
tunnels[{2, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East};
REQUIRE(!findTunnelPartner(makeLookup(tunnels), QPoint(2, 5),
BuildingType::TunnelEntry, Rotation::East, 10).has_value());
}
TEST_CASE("findTunnelPartner: a same-direction tunnel between blocks the pairing")
{
TunnelMap tunnels;
tunnels[{2, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East}; // selected
tunnels[{4, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East}; // blocker
tunnels[{6, 5}] = TunnelTileInfo{BuildingType::TunnelExit, Rotation::East};
// The scan from the selected entry stops at the same-direction entry, which is not
// an exit, so the exit beyond it is not paired.
REQUIRE(!findTunnelPartner(makeLookup(tunnels), QPoint(2, 5),
BuildingType::TunnelEntry, Rotation::East, 10).has_value());
}
TEST_CASE("findTunnelPartner: a differently-facing tunnel is skipped")
{
TunnelMap tunnels;
tunnels[{2, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East};
tunnels[{4, 5}] = TunnelTileInfo{BuildingType::TunnelExit, Rotation::North}; // skipped
tunnels[{6, 5}] = TunnelTileInfo{BuildingType::TunnelExit, Rotation::East}; // match
const std::optional<QPoint> partner = findTunnelPartner(
makeLookup(tunnels), QPoint(2, 5), BuildingType::TunnelEntry, Rotation::East, 10);
REQUIRE(partner.has_value());
REQUIRE(*partner == QPoint(6, 5));
}
TEST_CASE("findTunnelPartner: a partner beyond the max distance is not matched")
{
TunnelMap tunnels;
tunnels[{2, 5}] = TunnelTileInfo{BuildingType::TunnelEntry, Rotation::East};
tunnels[{6, 5}] = TunnelTileInfo{BuildingType::TunnelExit, Rotation::East}; // distance 4
REQUIRE(!findTunnelPartner(makeLookup(tunnels), QPoint(2, 5),
BuildingType::TunnelEntry, Rotation::East, 3).has_value());
}