mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-02 10:29:13 +01:00
refactor(sonar): make narrowing conversions explicit (cpp:S5276)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -72,8 +72,8 @@ float cMoon::getIntensity() {
|
||||
void cMoon::setLocation( float const Longitude, float const Latitude ) {
|
||||
|
||||
// convert fraction from geographical base of 6o minutes
|
||||
m_observer.longitude = (int)Longitude + (Longitude - (int)Longitude) * 100.0 / 60.0;
|
||||
m_observer.latitude = (int)Latitude + (Latitude - (int)Latitude) * 100.0 / 60.0 ;
|
||||
m_observer.longitude = (int)Longitude + (Longitude - static_cast<float>((int)Longitude)) * 100.0 / 60.0;
|
||||
m_observer.latitude = (int)Latitude + (Latitude - static_cast<float>((int)Latitude)) * 100.0 / 60.0 ;
|
||||
}
|
||||
|
||||
// sets current time, overriding one acquired from the system clock
|
||||
@@ -101,9 +101,9 @@ void cMoon::move() {
|
||||
|
||||
SYSTEMTIME localtime = simulation::Time.data(); // time for the calculation
|
||||
|
||||
if( m_observer.hour >= 0 ) { localtime.wHour = m_observer.hour; }
|
||||
if( m_observer.minute >= 0 ) { localtime.wMinute = m_observer.minute; }
|
||||
if( m_observer.second >= 0 ) { localtime.wSecond = m_observer.second; }
|
||||
if( m_observer.hour >= 0 ) { localtime.wHour = static_cast<uint16_t>(m_observer.hour); }
|
||||
if( m_observer.minute >= 0 ) { localtime.wMinute = static_cast<uint16_t>(m_observer.minute); }
|
||||
if( m_observer.second >= 0 ) { localtime.wSecond = static_cast<uint16_t>(m_observer.second); }
|
||||
|
||||
double localut =
|
||||
localtime.wHour
|
||||
@@ -297,7 +297,7 @@ cMoon::phase() {
|
||||
m_phase = 50;
|
||||
else {
|
||||
// calculate moon's age in days from new moon
|
||||
float ip = normalize( ( simulation::Time.julian_day() - 2451550.1f ) / 29.530588853f );
|
||||
float ip = normalize( ( static_cast<float>(simulation::Time.julian_day()) - 2451550.1f ) / 29.530588853f );
|
||||
m_phase = ip * 29.53f;
|
||||
}
|
||||
}
|
||||
@@ -306,7 +306,7 @@ cMoon::phase() {
|
||||
float
|
||||
cMoon::normalize( const float Value ) const {
|
||||
|
||||
float value = Value - floor( Value );
|
||||
float value = static_cast<float>(Value - floor( Value ));
|
||||
if( value < 0.f ) { ++value; }
|
||||
|
||||
return value;
|
||||
|
||||
@@ -70,13 +70,13 @@ void CSkyDome::Generate() {
|
||||
|
||||
for( int i = 0; i <= latitudes; ++i ) {
|
||||
|
||||
float const latitude = M_PI * ( -0.5f + (float)i / latitudes / 2 ); // half-sphere only
|
||||
float const latitude = static_cast<float>(M_PI * ( -0.5f + (float)i / static_cast<float>(latitudes) / 2 )); // half-sphere only
|
||||
float const z = std::sin( latitude );
|
||||
float const zr = std::cos( latitude );
|
||||
|
||||
for( int j = 0; j <= longitudes; ++j ) {
|
||||
|
||||
float const longitude = 2.0 * M_PI * (float)j / longitudes;
|
||||
float const longitude = static_cast<float>(2.0 * M_PI * (float)j / longitudes);
|
||||
float const x = std::cos( longitude );
|
||||
float const y = std::sin( longitude );
|
||||
/*
|
||||
@@ -168,8 +168,8 @@ float CSkyDome::GetZenith( float Zenithmatrix[ 3 ][ 4 ], const float Theta, cons
|
||||
|
||||
float CSkyDome::PerezFunctionO1( float Perezcoeffs[ 5 ], const float Thetasun, const float Zenithval ) {
|
||||
|
||||
const float val = ( 1.0f + Perezcoeffs[ 0 ] * std::exp( Perezcoeffs[ 1 ] ) ) *
|
||||
( 1.0f + Perezcoeffs[ 2 ] * std::exp( Perezcoeffs[ 3 ] * Thetasun ) + Perezcoeffs[ 4 ] * std::pow( std::cos( Thetasun ), 2 ) );
|
||||
const float val = static_cast<float>(( 1.0f + Perezcoeffs[ 0 ] * std::exp( Perezcoeffs[ 1 ] ) ) *
|
||||
( 1.0f + Perezcoeffs[ 2 ] * std::exp( Perezcoeffs[ 3 ] * Thetasun ) + Perezcoeffs[ 4 ] * std::pow( std::cos( Thetasun ), 2 ) ));
|
||||
|
||||
return Zenithval / val;
|
||||
}
|
||||
@@ -187,7 +187,7 @@ void CSkyDome::RebuildColors() {
|
||||
auto gammacorrection = glm::mix( glm::vec3( 1.0f ), glm::vec3( 0.45f ), twilightfactor );
|
||||
|
||||
// get zenith luminance
|
||||
float const chi = ( 4.0f / 9.0f - m_turbidity / 120.0f ) * ( M_PI - 2.0f * m_thetasun );
|
||||
float const chi = static_cast<float>(( 4.0f / 9.0f - m_turbidity / 120.0f ) * ( M_PI - 2.0f * m_thetasun ));
|
||||
float zenithluminance = ( 4.0453f * m_turbidity - 4.9710f ) * std::tan( chi ) - 0.2155f * m_turbidity + 2.4192f;
|
||||
|
||||
// get x / y zenith
|
||||
@@ -238,7 +238,7 @@ void CSkyDome::RebuildColors() {
|
||||
// = 1.0f / cosf( arccos( vertex.y ) );
|
||||
// = 1.0f / vertex.y;
|
||||
float const icostheta = 1.0f / vertex.y;
|
||||
float const cosgamma2 = std::pow( std::cos( gamma ), 2 );
|
||||
float const cosgamma2 = static_cast<float>(std::pow( std::cos( gamma ), 2 ));
|
||||
|
||||
// Compute x,y values
|
||||
float const x = PerezFunctionO2( perezx, icostheta, gamma, cosgamma2, zenithx );
|
||||
@@ -274,7 +274,7 @@ void CSkyDome::RebuildColors() {
|
||||
|
||||
// override the hue, based on sun height above the horizon. crude way to deal with model shortcomings
|
||||
// correction begins when the sun is higher than 10 degrees above the horizon, and fully in effect at 10+15 degrees
|
||||
float const degreesabovehorizon = 90.0f - m_thetasun * ( 180.0f / M_PI );
|
||||
float const degreesabovehorizon = static_cast<float>(90.0f - m_thetasun * ( 180.0f / M_PI ));
|
||||
auto const sunbasedphase = std::clamp( 1.0f / 15.0f * ( degreesabovehorizon - 10.0f ), 0.0f, 1.0f );
|
||||
// correction is applied in linear manner from the bottom, becomes fully in effect for vertices with y = 0.50
|
||||
auto const heightbasedphase = std::clamp( vertex.y * 2.0f, 0.0f, 1.0f );
|
||||
|
||||
@@ -76,8 +76,8 @@ float cSun::getIntensity() {
|
||||
void cSun::setLocation( float const Longitude, float const Latitude ) {
|
||||
|
||||
// convert fraction from geographical base of 6o minutes
|
||||
m_observer.longitude = (int)Longitude + (Longitude - (int)Longitude) * 100.0 / 60.0;
|
||||
m_observer.latitude = (int)Latitude + (Latitude - (int)Latitude) * 100.0 / 60.0 ;
|
||||
m_observer.longitude = (int)Longitude + (Longitude - static_cast<float>((int)Longitude)) * 100.0 / 60.0;
|
||||
m_observer.latitude = (int)Latitude + (Latitude - static_cast<float>((int)Latitude)) * 100.0 / 60.0 ;
|
||||
}
|
||||
|
||||
// sets current time, overriding one acquired from the system clock
|
||||
@@ -105,9 +105,9 @@ void cSun::move() {
|
||||
|
||||
SYSTEMTIME localtime = simulation::Time.data(); // time for the calculation
|
||||
|
||||
if( m_observer.hour >= 0 ) { localtime.wHour = m_observer.hour; }
|
||||
if( m_observer.minute >= 0 ) { localtime.wMinute = m_observer.minute; }
|
||||
if( m_observer.second >= 0 ) { localtime.wSecond = m_observer.second; }
|
||||
if( m_observer.hour >= 0 ) { localtime.wHour = static_cast<uint16_t>(m_observer.hour); }
|
||||
if( m_observer.minute >= 0 ) { localtime.wMinute = static_cast<uint16_t>(m_observer.minute); }
|
||||
if( m_observer.second >= 0 ) { localtime.wSecond = static_cast<uint16_t>(m_observer.second); }
|
||||
|
||||
double localut =
|
||||
localtime.wHour
|
||||
|
||||
Reference in New Issue
Block a user