Commit acb38d4d authored by Volker Krause's avatar Volker Krause
Browse files

Don't expand leading/trailing coaches to the full platform section

This produces almost equal-sized coaches when interpolating based on the
SBB data.
parent 7014b1ce
......@@ -68,6 +68,7 @@ private Q_SLOTS:
const auto idx = model.index(i, 0);
const auto sec = idx.data(VehicleLayoutQueryModel::VehicleSectionRole).value<VehicleSection>();
QVERIFY(sec.hasPlatformPosition());
QCOMPARE(sec.name(), inVec.sections()[i].name());
}
}
};
......
......@@ -95,6 +95,7 @@ template<typename Iter>
void VehicleLayoutQueryModelPrivate::interpolatePlatformPositionsFromSectionName(Iter begin, Iter end)
{
auto rangeBegin = begin, rangeEnd = begin;
float minLength = 1.0;
while (rangeBegin != end) {
while (rangeEnd != end && (*rangeBegin).platformSectionName() == (*rangeEnd).platformSectionName()) {
++rangeEnd;
......@@ -108,7 +109,13 @@ void VehicleLayoutQueryModelPrivate::interpolatePlatformPositionsFromSectionName
return;
}
const auto l = ((*platformIt).end() - (*platformIt).begin()) / std::distance(rangeBegin, rangeEnd);
auto l = ((*platformIt).end() - (*platformIt).begin()) / std::distance(rangeBegin, rangeEnd);
minLength = std::min(minLength, l);
if (rangeEnd == end) { // trailing coaches, don't scale them to the full section
l = minLength;
}
auto pos = (*platformIt).begin();
for (auto it = rangeBegin; it != rangeEnd; ++it) {
(*it).setPlatformPositionBegin(pos);
......@@ -118,6 +125,17 @@ void VehicleLayoutQueryModelPrivate::interpolatePlatformPositionsFromSectionName
rangeBegin = rangeEnd;
}
// fix-up leading coaches to not fill up the entire platform section
rangeEnd = std::find_if(begin, end, [&begin](const auto &p) {
return p.platformSectionName() != (*begin).platformSectionName();
});
auto pos = (*std::prev(rangeEnd)).platformPositionEnd() - std::distance(begin, rangeEnd) * minLength;
for (auto it = begin; it != rangeEnd; ++it) {
(*it).setPlatformPositionBegin(pos);
(*it).setPlatformPositionEnd(pos + minLength);
pos += minLength;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment