17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 05:09:20 +02:00

perf(track): pieces of gauge lines whose bounding boxes do not meet are skipped before they are intersected; self-test railtime logs how much of the time goes to finding the crossings

This commit is contained in:
maj00r
2026-10-13 18:54:11 +02:00
parent c0b50cc3d2
commit 38b2f4108a
2 changed files with 22 additions and 3 deletions

View File

@@ -354,11 +354,20 @@ void editor_mode::selftest_step()
{ {
if (track == nullptr || track->m_editorremoved || (track->iCategoryFlag & 15) != 1) if (track == nullptr || track->m_editorremoved || (track->iCategoryFlag & 15) != 1)
continue; continue;
track->plan_rails(true); track->rail_crossings(false);
++tracks; ++tracks;
} }
auto const elapsed{std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - started).count()}; auto const crossed{std::chrono::steady_clock::now()};
WriteLog(format("SELFTEST railtime: the rails of %d tracks laid out in %.1f ms", tracks, elapsed)); for (auto *track : simulation::Paths.sequence())
{
if (track == nullptr || track->m_editorremoved || (track->iCategoryFlag & 15) != 1)
continue;
track->plan_rails(true);
}
auto const finished{std::chrono::steady_clock::now()};
auto const crossings{std::chrono::duration<double, std::milli>(crossed - started).count()};
auto const elapsed{std::chrono::duration<double, std::milli>(finished - started).count()};
WriteLog(format("SELFTEST railtime: the rails of %d tracks laid out in %.1f ms, of which their crossings %.1f ms", tracks, elapsed, crossings));
} }
else if (command == "crossings") else if (command == "crossings")
{ {

View File

@@ -439,9 +439,19 @@ std::vector<TTrack::rail_crossing> TTrack::rail_crossings( bool const Joined ) {
for( std::size_t i = 1; i < line.points.size(); ++i ) { for( std::size_t i = 1; i < line.points.size(); ++i ) {
auto const a0 { plan( line.points[ i - 1 ] ) }; auto const a0 { plan( line.points[ i - 1 ] ) };
auto const a { plan( line.points[ i ] ) - a0 }; auto const a { plan( line.points[ i ] ) - a0 };
auto const alow { glm::min( a0, a0 + a ) - 0.02 * glm::length( a ) - 1e-6 };
auto const ahigh { glm::max( a0, a0 + a ) + 0.02 * glm::length( a ) + 1e-6 };
if( alow.x > theirs.high.x + 1.0 || theirs.low.x - 1.0 > ahigh.x || alow.y > theirs.high.y + 1.0 || theirs.low.y - 1.0 > ahigh.y ) {
continue;
}
for( std::size_t j = 1; j < theirs.points.size(); ++j ) { for( std::size_t j = 1; j < theirs.points.size(); ++j ) {
auto const b0 { plan( theirs.points[ j - 1 ] ) }; auto const b0 { plan( theirs.points[ j - 1 ] ) };
auto const b { plan( theirs.points[ j ] ) - b0 }; auto const b { plan( theirs.points[ j ] ) - b0 };
auto const reach { 0.02 * glm::length( b ) };
if( alow.x > std::max( b0.x, b0.x + b.x ) + reach || std::min( b0.x, b0.x + b.x ) - reach > ahigh.x
|| alow.y > std::max( b0.y, b0.y + b.y ) + reach || std::min( b0.y, b0.y + b.y ) - reach > ahigh.y ) {
continue;
}
auto const denominator { cross( a, b ) }; auto const denominator { cross( a, b ) };
if( std::abs( denominator ) < 1e-12 ) { if( std::abs( denominator ) < 1e-12 ) {
continue; continue;