mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 02:49:19 +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:
@@ -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<double, std::milli>(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<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")
|
||||
{
|
||||
|
||||
@@ -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 ) {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user