17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-04 19:59:25 +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:
jerrrrycho
2026-10-10 15:16:28 +02:00
parent 80464d0bc1
commit 8c23c1fe2b
53 changed files with 468 additions and 468 deletions

View File

@@ -120,7 +120,7 @@ class float4
};
float inline Length() const
{
return sqrt(x * x + y * y + z * z + w * w);
return static_cast<float>(sqrt(x * x + y * y + z * z + w * w));
};
};
inline float4 operator*(const float4 &q1, const float4 &q2)
@@ -194,8 +194,8 @@ inline float4 Slerp(const float4 &q0, const float4 &q1, float t)
auto const sinOmega = std::sqrt(1.0f - cosOmega * cosOmega); // sinus z jedynki tryg.
auto const omega = std::atan2(sinOmega, cosOmega); // wyznaczenie kąta
auto const oneOverSinOmega = 1.0f / sinOmega; // odwrotność sinusa, bo sinus w mianowniku
k0 = sin((1.0f - t) * omega) * oneOverSinOmega;
k1 = sin(t * omega) * oneOverSinOmega;
k0 = static_cast<float>(sin((1.0f - t) * omega) * oneOverSinOmega);
k1 = static_cast<float>(sin(t * omega) * oneOverSinOmega);
}
return float4(q0.x * k0 + new_q1.x * k1, q0.y * k0 + new_q1.y * k1, q0.z * k0 + new_q1.z * k1,
q0.w * k0 + new_q1.w * k1);

View File

@@ -33,14 +33,14 @@ std::string filename_date() {
clock_gettime(CLOCK_REALTIME, &ts);
std::tm const tm = local_tm(ts.tv_sec);
std::tm const *tms = &tm;
st.wYear = tms->tm_year;
st.wMonth = tms->tm_mon;
st.wDayOfWeek = tms->tm_wday;
st.wDay = tms->tm_mday;
st.wHour = tms->tm_hour;
st.wMinute = tms->tm_min;
st.wSecond = tms->tm_sec;
st.wMilliseconds = ts.tv_nsec / 1000000;
st.wYear = static_cast<uint16_t>(tms->tm_year);
st.wMonth = static_cast<uint16_t>(tms->tm_mon);
st.wDayOfWeek = static_cast<uint16_t>(tms->tm_wday);
st.wDay = static_cast<uint16_t>(tms->tm_mday);
st.wHour = static_cast<uint16_t>(tms->tm_hour);
st.wMinute = static_cast<uint16_t>(tms->tm_min);
st.wSecond = static_cast<uint16_t>(tms->tm_sec);
st.wMilliseconds = static_cast<uint16_t>(ts.tv_nsec / 1000000);
#elif _WIN32
::GetLocalTime( &st );
#endif

View File

@@ -35,7 +35,7 @@ public:
std::chrono::duration<float, std::milli>
stop() {
m_last = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::steady_clock::now() - m_start );
m_accumulator = 0.95f * m_accumulator + m_last.count() / 1000.f;
m_accumulator = 0.95f * m_accumulator + static_cast<float>(m_last.count()) / 1000.f;
return m_last; }
float
average() const {

View File

@@ -59,10 +59,10 @@ RGBtoHSV( glm::vec3 const &RGB ) {
else
hsv.x = 4.f + ( RGB.r - RGB.g ) / delta; // between magenta & cyan
hsv.x *= 60.0; // degrees
hsv.x *= 60.0f; // degrees
if( hsv.x < 0.0 )
hsv.x += 360.0;
hsv.x += 360.0f;
return hsv;
}
@@ -81,9 +81,9 @@ HSVtoRGB( glm::vec3 const &HSV ) {
}
float hh = HSV.x;
if( hh >= 360.0 ) hh = 0.0;
hh /= 60.0;
hh /= 60.0f;
int const i = (int)hh;
float const ff = hh - i;
float const ff = hh - static_cast<float>(i);
float const p = HSV.z * ( 1.f - HSV.y );
float const q = HSV.z * ( 1.f - HSV.y * ff );
float const t = HSV.z * ( 1.f - HSV.y * (1.f - ff) );

View File

@@ -6,12 +6,12 @@ headtrack::headtrack() = default;
void headtrack::find_joy() {
for (size_t i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; i++) {
if (!glfwJoystickPresent(i))
if (!glfwJoystickPresent(static_cast<int>(i)))
continue;
std::string name(glfwGetJoystickName(i));
std::string name(glfwGetJoystickName(static_cast<int>(i)));
if (name == Global.headtrack_conf.joy) {
joy_id = i;
joy_id = static_cast<int>(i);
return;
}
}

View File

@@ -146,15 +146,15 @@ void motiontelemetry::update()
}
float buffer[12] = { 0 };
buffer[0] = Timer::GetTime();
buffer[1] = velocity;
buffer[2] = local_acc.y;
buffer[3] = local_acc.z;
buffer[4] = local_acc.x;
buffer[5] = glm::degrees(rot.x);
buffer[6] = glm::degrees(rot.z);
buffer[7] = glm::degrees(rot.y);
buffer[8] = yaw_vel;
buffer[0] = static_cast<float>(Timer::GetTime());
buffer[1] = static_cast<float>(velocity);
buffer[2] = static_cast<float>(local_acc.y);
buffer[3] = static_cast<float>(local_acc.z);
buffer[4] = static_cast<float>(local_acc.x);
buffer[5] = static_cast<float>(glm::degrees(rot.x));
buffer[6] = static_cast<float>(glm::degrees(rot.z));
buffer[7] = static_cast<float>(glm::degrees(rot.y));
buffer[8] = static_cast<float>(yaw_vel);
buffer[9] = 1.0f;
if (send(sock, (char*)buffer, sizeof(buffer), 0) == -1)

View File

@@ -275,7 +275,7 @@ void uart_input::poll()
/* handle baud change */
if(status->active_baud_index != status->selected_baud_index) {
status->baud = std::stoul(uart_baudrates_list[status->selected_baud_index]);
status->baud = static_cast<int>(std::stoul(uart_baudrates_list[status->selected_baud_index]));
status->active_baud_index = status->selected_baud_index;
status->reset_stats();
status->is_connected = false;
@@ -534,7 +534,7 @@ void uart_input::poll()
auto const trainstate = t->get_state();
SYSTEMTIME time = simulation::Time.data();
uint16_t tacho = Global.iPause ? 0 : trainstate.velocity * conf.tachoscale;
uint16_t tacho = Global.iPause ? 0 : static_cast<uint16_t>(trainstate.velocity * conf.tachoscale);
uint16_t tank_press = (uint16_t)std::min(conf.tankuart, trainstate.reservoir_pressure * 0.1f / conf.tankmax * conf.tankuart);
uint16_t pipe_press = (uint16_t)std::min(conf.pipeuart, trainstate.pipe_pressure * 0.1f / conf.pipemax * conf.pipeuart);
uint16_t brake_press = (uint16_t)std::min(conf.brakeuart, trainstate.brake_pressure * 0.1f / conf.brakemax * conf.brakeuart);
@@ -543,7 +543,7 @@ void uart_input::poll()
uint16_t current1 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[0] / conf.currentmax * conf.currentuart);
uint16_t current2 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[1] / conf.currentmax * conf.currentuart);
uint16_t current3 = (uint16_t)std::min(conf.currentuart, trainstate.hv_current[2] / conf.currentmax * conf.currentuart);
uint32_t odometer = trainstate.distance * 10000.0;
uint32_t odometer = static_cast<uint32_t>(trainstate.distance * 10000.0);
uint16_t lv_voltage = (uint16_t)std::min( conf.lvuart, trainstate.lv_voltage / conf.lvmax * conf.lvuart );
if( trainstate.cab > 0 ) {
// NOTE: moving from a cab to engine room doesn't change cab indicator

View File

@@ -100,7 +100,7 @@ inline double LocalRandom(double b)
inline double BorlandTime()
{
auto timesinceepoch = std::time(nullptr);
return timesinceepoch / (24.0 * 60 * 60);
return static_cast<double>(timesinceepoch) / (24.0 * 60 * 60);
/*
// std alternative
auto timesinceepoch = std::chrono::system_clock::now().time_since_epoch();
@@ -315,7 +315,7 @@ template <typename T> T clamp_power_of_two(T Value, T const Min = T(1), T const
template <typename Type_> Type_ quantize(Type_ const Value, Type_ const Step)
{
return Step * std::round(Value / Step);
return static_cast<unsigned int>(Step * std::round(Value / Step));
}
template <typename T> T min_speed(T const Left, T const Right)