C++ warning fixes

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk
2025-08-01 13:33:12 +02:00
committed by Konstantin Pastbin
parent a28d5d15ce
commit 2aaf37e9ee
15 changed files with 35 additions and 34 deletions

View File

@@ -240,9 +240,9 @@ FreetypeError constexpr g_FT_Errors[] =
auto const & currPos = glyphPos[i];
auto const & metrics = m_fontFace->glyph->metrics;
auto const xOffset = (currPos.x_offset + static_cast<int32_t>(metrics.horiBearingX)) >> 6;
auto const xOffset = static_cast<int32_t>((currPos.x_offset + metrics.horiBearingX) >> 6);
// The original Drape code expects a bottom, not a top offset in its calculations.
auto const yOffset = (currPos.y_offset + static_cast<int32_t>(metrics.horiBearingY) - metrics.height) >> 6;
auto const yOffset = static_cast<int32_t>((currPos.y_offset + metrics.horiBearingY - metrics.height) >> 6);
int32_t const xAdvance = currPos.x_advance >> 6;
// yAdvance is always zero for horizontal text layouts.

View File

@@ -25,8 +25,8 @@ size_t GetScriptExtensions(char32_t codepoint, TScriptsArray & scripts)
{
// Fill scripts with the script extensions.
UErrorCode icu_error = U_ZERO_ERROR;
size_t const count =
uscript_getScriptExtensions(static_cast<UChar32>(codepoint), scripts.data(), scripts.max_size(), &icu_error);
size_t const count = uscript_getScriptExtensions(static_cast<UChar32>(codepoint), scripts.data(),
static_cast<int32_t>(scripts.max_size()), &icu_error);
if (U_FAILURE(icu_error))
{
LOG(LWARNING, ("uscript_getScriptExtensions failed with error", icu_error));

View File

@@ -52,7 +52,8 @@ public:
{
m_indexBuffer = GLFunctions::glGenBuffer();
GLFunctions::glBindBuffer(m_indexBuffer, gl_const::GLElementArrayBuffer);
GLFunctions::glBufferData(gl_const::GLElementArrayBuffer, m_mesh->m_indices.size() * sizeof(uint16_t),
GLFunctions::glBufferData(gl_const::GLElementArrayBuffer,
static_cast<uint32_t>(m_mesh->m_indices.size() * sizeof(uint16_t)),
m_mesh->m_indices.data(), gl_const::GLStaticDraw);
}
@@ -113,7 +114,8 @@ public:
CHECK(!m_mesh->m_indices.empty(), ());
CHECK(m_indexBuffer, ("Index buffer was not created"));
GLFunctions::glBindBuffer(m_indexBuffer, gl_const::GLElementArrayBuffer);
GLFunctions::glBufferData(gl_const::GLElementArrayBuffer, m_mesh->m_indices.size() * sizeof(uint16_t),
GLFunctions::glBufferData(gl_const::GLElementArrayBuffer,
static_cast<uint32_t>(m_mesh->m_indices.size() * sizeof(uint16_t)),
m_mesh->m_indices.data(), gl_const::GLStaticDraw);
GLFunctions::glBindBuffer(0, gl_const::GLElementArrayBuffer);
}

View File

@@ -259,8 +259,7 @@ void MetalBaseContext::Clear(uint32_t clearBits, uint32_t storeBits)
void MetalBaseContext::SetViewport(uint32_t x, uint32_t y, uint32_t w, uint32_t h)
{
id<MTLRenderCommandEncoder> encoder = GetCommandEncoder();
[encoder setViewport:{static_cast<double>(x), static_cast<double>(y), static_cast<double>(w), static_cast<double>(h),
0.0, 1.0}];
[encoder setViewport:MTLViewport(x, y, w, h, 0.0, 1.0)];
[encoder setScissorRect:{x, y, w, h}];
}
@@ -269,12 +268,16 @@ void MetalBaseContext::SetScissor(uint32_t x, uint32_t y, uint32_t w, uint32_t h
id<MTLRenderCommandEncoder> encoder = GetCommandEncoder();
if (m_renderPassDescriptor.colorAttachments[0].texture != nil)
{
uint32_t const rpWidth = m_renderPassDescriptor.colorAttachments[0].texture.width;
uint32_t const rpHeight = m_renderPassDescriptor.colorAttachments[0].texture.height;
if (x < 0) x = 0;
if (y < 0) y = 0;
if (x + w > rpWidth) w = rpWidth - x;
if (y + h > rpHeight) h = rpHeight - y;
auto const rpWidth = static_cast<uint32_t>(m_renderPassDescriptor.colorAttachments[0].texture.width);
auto const rpHeight = static_cast<uint32_t>(m_renderPassDescriptor.colorAttachments[0].texture.height);
if (x < 0)
x = 0;
if (y < 0)
y = 0;
if (x + w > rpWidth)
w = rpWidth - x;
if (y + h > rpHeight)
h = rpHeight - y;
[encoder setScissorRect:{x, y, w, h}];
}

View File

@@ -110,7 +110,7 @@ public:
void UpdateIndexBuffer(ref_ptr<dp::GraphicsContext> context) override
{
CHECK(!m_mesh->m_indices.empty(), ());
auto const sizeInBytes = m_mesh->m_indices.size() * sizeof(uint16_t);
auto const sizeInBytes = static_cast<uint32_t>(m_mesh->m_indices.size() * sizeof(uint16_t));
CHECK(m_indexBuffer.m_buffer != VK_NULL_HANDLE, ());
UpdateBufferInternal(context, m_indexBuffer.m_buffer, VK_ACCESS_INDEX_READ_BIT, m_mesh->m_indices.data(),
@@ -169,7 +169,8 @@ private:
buffers.emplace_back(m_geometryBuffers[i].m_buffer);
offsets.emplace_back(0);
}
vkCmdBindVertexBuffers(commandBuffer, 0, m_geometryBuffers.size(), buffers.data(), offsets.data());
vkCmdBindVertexBuffers(commandBuffer, 0, static_cast<uint32_t>(m_geometryBuffers.size()), buffers.data(),
offsets.data());
}
void UpdateBufferInternal(ref_ptr<dp::GraphicsContext> context, VkBuffer buffer, VkAccessFlagBits bufferAccessMask,

View File

@@ -72,7 +72,7 @@ RulerHelper::RulerHelper()
void RulerHelper::Update(ScreenBase const & screen)
{
m2::PointD pivot = screen.PixelRect().Center();
int const minPxWidth = std::lround(kMinPixelWidth * df::VisualParams::Instance().GetVisualScale());
long const minPxWidth = std::lround(kMinPixelWidth * df::VisualParams::Instance().GetVisualScale());
m2::PointD pt1 = screen.PtoG(pivot);
m2::PointD pt0 = screen.PtoG(pivot - m2::PointD(minPxWidth, 0));

View File

@@ -306,7 +306,7 @@ bool TrafficRenderer::CanBeRenderedAsLine(RoadClass const & roadClass, int zoomL
if (it == lineDrawerEnd)
return false;
width = std::max(1l, std::lround(TrafficRenderer::GetPixelWidthInternal(roadClass, zoomLevel)));
width = std::max(1, static_cast<int>(std::lround(TrafficRenderer::GetPixelWidthInternal(roadClass, zoomLevel))));
return width <= dp::SupportManager::Instance().GetMaxLineWidth();
}
} // namespace df

View File

@@ -180,7 +180,7 @@ int GetTileScaleBase(m2::RectD const & r)
{
double const sz = std::max(r.SizeX(), r.SizeY());
ASSERT_GREATER(sz, 0., ("Rect should not be a point:", r));
return std::max(1l, std::lround(std::log2(mercator::Bounds::kRangeX / sz)));
return std::max(1, static_cast<int>(std::lround(std::log2(mercator::Bounds::kRangeX / sz))));
}
double GetTileScaleBase(double drawScale)

View File

@@ -158,7 +158,7 @@ int LatToInt(double lat, int maxValue)
// 000111111222222...LLLLLMMMM
double const x = (lat + 90.0) / 180.0 * maxValue;
return x < 0 ? 0 : (x > maxValue ? maxValue : std::lround(x));
return x < 0 ? 0 : (x > maxValue ? maxValue : static_cast<int>(std::lround(x)));
}
// Make lon in [-180, 180)

View File

@@ -230,12 +230,12 @@ void ScreenBase::SetAngle(double angle)
int ScreenBase::GetWidth() const
{
return std::lround(m_PixelRect.SizeX());
return static_cast<int>(std::lround(m_PixelRect.SizeX()));
}
int ScreenBase::GetHeight() const
{
return std::lround(m_PixelRect.SizeY());
return static_cast<int>(std::lround(m_PixelRect.SizeY()));
}
ScreenBase::MatrixT ScreenBase::CalcTransform(m2::PointD const & oldPt1, m2::PointD const & oldPt2,

View File

@@ -33,12 +33,12 @@ double GetScaleLevelD(m2::RectD const & r)
int GetScaleLevel(double ratio)
{
return std::lround(GetScaleLevelD(ratio));
return static_cast<int>(std::lround(GetScaleLevelD(ratio)));
}
int GetScaleLevel(m2::RectD const & r)
{
return std::lround(GetScaleLevelD(r));
return static_cast<int>(std::lround(GetScaleLevelD(r)));
}
namespace

View File

@@ -198,7 +198,7 @@ double MpsToUnits(double metersPerSecond, Units units)
UNREACHABLE();
}
int FormatSpeed(double metersPerSecond, Units units)
long FormatSpeed(double metersPerSecond, Units units)
{
return std::lround(MpsToUnits(metersPerSecond, units));
}
@@ -214,8 +214,8 @@ std::string FormatOsmLink(double lat, double lon, int zoom)
// Same as (lon + 180) / 360 * 1UL << 32, but without warnings.
double constexpr factor = (1 << 30) / 90.0;
uint32_t const x = std::lround((lon + 180.0) * factor);
uint32_t const y = std::lround((lat + 90.0) * factor * 2.0);
auto const x = static_cast<uint32_t>(std::lround((lon + 180.0) * factor));
auto const y = static_cast<uint32_t>(std::lround((lat + 90.0) * factor * 2.0));
uint64_t const code = bits::BitwiseMerge(y, x);
std::string osmUrl = "https://osm.org/go/";

View File

@@ -70,7 +70,7 @@ double ToSpeedKmPH(double speed, Units units);
double MpsToUnits(double metersPerSecond, Units units);
/// @return Speed value in km/h for Metric and in mph for Imperial.
int FormatSpeed(double metersPerSecond, Units units);
long FormatSpeed(double metersPerSecond, Units units);
/// @return Speed value string (without suffix) in km/h for Metric and in mph for Imperial.
std::string FormatSpeedNumeric(double metersPerSecond, Units units);

View File

@@ -35,7 +35,7 @@ bool EndsInAcronymOrNum(strings::UniString const & myUniStr)
bool allUppercaseNum = true;
strings::UniString lowerStr = strings::MakeLowerCase(myUniStr);
for (int i = myUniStr.size() - 1; i > 0; i--)
for (long i = myUniStr.size() - 1; i > 0; i--)
{
// if we've reached a space, we're done here
if (myUniStr[i] == ' ')

View File

@@ -29,11 +29,6 @@ double constexpr kCategoriesFalseCats = -1.0000000;
double constexpr kDistanceToPivot = -0.48;
double constexpr kWalkingDistanceM = 5000.0;
double constexpr AbsPenaltyPerKm()
{
return -kDistanceToPivot * 1000.0 / RankingInfo::kMaxDistMeters;
}
// These constants are very important and checked in Famous_Cities_Rank test.
double constexpr kRank = 0.23;
double constexpr kPopularity = 0.42;