mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-11 00:35:16 +01:00
fix: the bugs and vulnerabilities SonarCloud reports on PR #216
This commit is contained in:
@@ -673,7 +673,8 @@ knots::line check_blocks( TTrack const &Track, int const Path, int const Side, s
|
||||
if( false == others.empty() || false == Crossing.empty() ) {
|
||||
auto const ours { make_gauge_line( segment, Side * halfwidth, 0.0 ) };
|
||||
for( auto const &check : Checks ) {
|
||||
for( auto s { check.from }; s <= check.to; s += 0.1 ) {
|
||||
auto s { check.from };
|
||||
while( s <= check.to ) {
|
||||
glm::dvec3 point, tangent;
|
||||
ours.at( s, point, tangent );
|
||||
auto const inward { plan( ours.normal( s, Side ) ) };
|
||||
@@ -681,6 +682,7 @@ knots::line check_blocks( TTrack const &Track, int const Path, int const Side, s
|
||||
|| ( check.acute && blocked_by( Crossing, plan( point ), inward, Clearance ) ) ) {
|
||||
blocks.emplace_back( s - 0.3, s + 0.3 );
|
||||
}
|
||||
s += 0.1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1039,12 +1041,16 @@ track_rails::switch_blade const &TTrack::blade( int const Path ) const {
|
||||
result.drop = ( half > 0 ? std::max( 0.0, size.crest - bladetop ) : 0.0 );
|
||||
auto const lowered { reach( blade_lowered + blade_gap ) };
|
||||
auto const cutto { std::min( result.heel, foot >= 0.0 ? foot + blade_spacing : result.heel ) };
|
||||
for( auto distance { result.tip }; distance < cutto + 0.5 * blade_spacing; distance += blade_spacing ) {
|
||||
auto const at { std::min( distance, cutto ) };
|
||||
auto const width { level( at ) - blade_gap };
|
||||
result.extents.emplace_back( at, width );
|
||||
if( result.drop > 0.0 && ( lowered < 0.0 || at <= lowered + blade_spacing ) ) {
|
||||
result.drops.emplace_back( at, result.drop * std::clamp( 1.0 - width / blade_lowered, 0.0, 1.0 ) );
|
||||
{
|
||||
auto distance { result.tip };
|
||||
while( distance < cutto + 0.5 * blade_spacing ) {
|
||||
auto const at { std::min( distance, cutto ) };
|
||||
auto const width { level( at ) - blade_gap };
|
||||
result.extents.emplace_back( at, width );
|
||||
if( result.drop > 0.0 && ( lowered < 0.0 || at <= lowered + blade_spacing ) ) {
|
||||
result.drops.emplace_back( at, result.drop * std::clamp( 1.0 - width / blade_lowered, 0.0, 1.0 ) );
|
||||
}
|
||||
distance += blade_spacing;
|
||||
}
|
||||
}
|
||||
auto const steps { std::max( 1, static_cast<int>( std::ceil( ( result.heel - result.tip ) / blade_spacing ) ) ) };
|
||||
|
||||
@@ -957,7 +957,7 @@ void roadpoint_node::update_crossing(double const Deltatime)
|
||||
auto const closed{control > 0.0 || (control == 0.0 && m_hold > 0.0)};
|
||||
if (closed != m_closed)
|
||||
{
|
||||
WriteLog("Level crossing \"" + m_name + "\" " + (closed ? "closed" : "opened") + (control != 0.0 ? " by memory cell \"" + m_memcell->name() + "\"" : " by the trains") + ", stops: " +
|
||||
WriteLog("Level crossing \"" + m_name + "\" " + (closed ? "closed" : "opened") + (control != 0.0 && m_memcell != nullptr ? " by memory cell \"" + m_memcell->name() + "\"" : " by the trains") + ", stops: " +
|
||||
std::to_string(m_stops.size()));
|
||||
close(closed);
|
||||
}
|
||||
|
||||
@@ -807,11 +807,19 @@ bool TSegment::RenderLoftSpan( gfx::vertex_array &Output, glm::dvec3 const &Orig
|
||||
|
||||
std::vector<double> stations { Span.from, Span.to };
|
||||
auto const step { std::max( fStep, 0.2 ) };
|
||||
for( auto distance { std::ceil( Span.from / step ) * step }; distance < Span.to; distance += step ) {
|
||||
stations.push_back( distance );
|
||||
{
|
||||
auto distance { std::ceil( Span.from / step ) * step };
|
||||
while( distance < Span.to ) {
|
||||
stations.push_back( distance );
|
||||
distance += step;
|
||||
}
|
||||
}
|
||||
for( auto distance { std::ceil( Span.from / 0.5 ) * 0.5 }; distance < std::min( Span.to, m_dense ); distance += 0.5 ) {
|
||||
stations.push_back( distance );
|
||||
{
|
||||
auto distance { std::ceil( Span.from / 0.5 ) * 0.5 };
|
||||
while( distance < std::min( Span.to, m_dense ) ) {
|
||||
stations.push_back( distance );
|
||||
distance += 0.5;
|
||||
}
|
||||
}
|
||||
for( auto const *line : { &Span.offsets, &Span.extents, &Span.inner, &Span.drops, &Span.rises, &Span.lows } ) {
|
||||
for( auto const &knot : *line ) {
|
||||
|
||||
@@ -1404,7 +1404,8 @@ private:
|
||||
// f(drop) = odległość osi blachy od liny - długość kolumny; szukane miejsce zerowe w -1,0 .. 2,5 m
|
||||
auto f = [&]( double Drop ) { auto const p { solve( Drop, station, stay ) }; return p.ok ? length( p.pivot - messenger ) - column : 1e9; };
|
||||
double previous { -1.0 }, fprevious { f( previous ) };
|
||||
for( double drop = -1.0 + 0.02; drop <= 2.5; drop += 0.02 ) {
|
||||
double drop { -1.0 + 0.02 };
|
||||
while( drop <= 2.5 ) {
|
||||
auto const fnow { f( drop ) };
|
||||
if( fprevious < 1e8 && fnow < 1e8 && ( fprevious <= 0.0 ) != ( fnow <= 0.0 ) ) {
|
||||
double low { previous }, high { drop }, flow { fprevious };
|
||||
@@ -1420,6 +1421,7 @@ private:
|
||||
if( p.ok && hanging.z < 0.0 && score < bestscore ) { bestscore = score; best = p; bestdrop = low; beststation = station; besthole = static_cast<int>( hole ); }
|
||||
}
|
||||
previous = drop; fprevious = fnow;
|
||||
drop += 0.02;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2136,7 +2136,8 @@ catenary_scene_update( std::size_t const Index, catenary::suspension const &Data
|
||||
mark_changed( suspension.file );
|
||||
if( false == before.empty() && before != Data.umbrella ) {
|
||||
drop_parts( suspension );
|
||||
for( auto const index : umbrella_members( before ) ) { reassemble( index ); break; }
|
||||
// parasol składa jego pierwsze podwieszenie
|
||||
if( auto const members { umbrella_members( before ) }; false == members.empty() ) { reassemble( members.front() ); }
|
||||
}
|
||||
reassemble( Index );
|
||||
follow_chains( Index );
|
||||
@@ -2153,7 +2154,8 @@ catenary_scene_remove( std::size_t const Index ) {
|
||||
suspension.removed = true;
|
||||
mark_changed( suspension.file );
|
||||
if( false == umbrella.empty() ) {
|
||||
for( auto const index : umbrella_members( umbrella ) ) { reassemble( index ); break; }
|
||||
// parasol składa jego pierwsze podwieszenie
|
||||
if( auto const members { umbrella_members( umbrella ) }; false == members.empty() ) { reassemble( members.front() ); }
|
||||
}
|
||||
// z łańcuchów wypada; łańcuch z jednym podwieszeniem przestaje istnieć
|
||||
if( false == suspension.data.name.empty() ) {
|
||||
|
||||
@@ -246,7 +246,10 @@ span_result solve_span( network_type const &Type, span_input const &Input, doubl
|
||||
{
|
||||
auto nodes { messenger.nodes() };
|
||||
auto const step { std::max( 0.1, Samplestep ) };
|
||||
for( double x = step; x < length; x += step ) { nodes.push_back( x ); }
|
||||
{
|
||||
double x { step };
|
||||
while( x < length ) { nodes.push_back( x ); x += step; }
|
||||
}
|
||||
std::sort( nodes.begin(), nodes.end() );
|
||||
nodes.erase( std::unique( nodes.begin(), nodes.end(), []( double L, double R ) { return std::abs( L - R ) < 1e-6; } ), nodes.end() );
|
||||
for( auto const x : nodes ) {
|
||||
|
||||
@@ -90,8 +90,11 @@ y_at( TTraction const &Traction, int const End ) {
|
||||
auto const neighbourend { Traction.iNext[ End ] };
|
||||
if( neighbour->hvNext[ neighbourend ] != &Traction ) { return false; }
|
||||
if( std::abs( y_length( *neighbour ) - ylength ) > 0.01 ) { return false; }
|
||||
auto const &type { definition( Traction )->type };
|
||||
auto const &neighbourtype { definition( *neighbour )->type };
|
||||
auto const *own { definition( Traction ) };
|
||||
auto const *neighbourdefinition { definition( *neighbour ) };
|
||||
if( own == nullptr || neighbourdefinition == nullptr ) { return false; }
|
||||
auto const &type { own->type };
|
||||
auto const &neighbourtype { neighbourdefinition->type };
|
||||
if( type.y_tension != neighbourtype.y_tension
|
||||
|| type.y_mass != neighbourtype.y_mass
|
||||
|| type.messenger_count != neighbourtype.messenger_count ) {
|
||||
|
||||
Reference in New Issue
Block a user