diff --git a/application/editormodeselftest.cpp b/application/editormodeselftest.cpp index f97426d1..a7bc68fb 100644 --- a/application/editormodeselftest.cpp +++ b/application/editormodeselftest.cpp @@ -354,11 +354,20 @@ void editor_mode::selftest_step() { if (track == nullptr || track->m_editorremoved || (track->iCategoryFlag & 15) != 1) continue; - track->plan_rails(true); + track->rail_crossings(false); ++tracks; } - auto const elapsed{std::chrono::duration(std::chrono::steady_clock::now() - started).count()}; - WriteLog(format("SELFTEST railtime: the rails of %d tracks laid out in %.1f ms", tracks, elapsed)); + auto const crossed{std::chrono::steady_clock::now()}; + 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(crossed - started).count()}; + auto const elapsed{std::chrono::duration(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") { diff --git a/world/TrackRails.cpp b/world/TrackRails.cpp index d78398e6..e4b2dbc0 100644 --- a/world/TrackRails.cpp +++ b/world/TrackRails.cpp @@ -439,9 +439,19 @@ std::vector TTrack::rail_crossings( bool const Joined ) { for( std::size_t i = 1; i < line.points.size(); ++i ) { auto const a0 { plan( line.points[ i - 1 ] ) }; 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 ) { auto const b0 { plan( theirs.points[ j - 1 ] ) }; 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 ) }; if( std::abs( denominator ) < 1e-12 ) { continue;