[core] Fix google-readability-casting errors

As reported by clang-tidy-8.
This commit is contained in:
Thiago Marcos P. Santos
2020-03-20 12:38:09 +02:00
parent 5fa7ff3b63
commit 65f4df5190
8 changed files with 34 additions and 24 deletions

View File

@@ -286,7 +286,7 @@ size_t HTTPRequest::writeCallback(void *const contents, const size_t size, const
impl->data = std::make_shared<std::string>();
}
impl->data->append((char *)contents, size * nmemb);
impl->data->append(static_cast<char *>(contents), size * nmemb);
return size * nmemb;
}

View File

@@ -56,8 +56,8 @@ static void term(j_decompress_ptr) {}
static void attach_stream(j_decompress_ptr cinfo, std::istream* in) {
if (cinfo->src == nullptr) {
cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(jpeg_stream_wrapper));
cinfo->src = static_cast<struct jpeg_source_mgr*>((*cinfo->mem->alloc_small)(
reinterpret_cast<j_common_ptr>(cinfo), JPOOL_PERMANENT, sizeof(jpeg_stream_wrapper)));
}
auto * src = reinterpret_cast<jpeg_stream_wrapper*> (cinfo->src);
src->manager.init_source = init_source;
@@ -122,7 +122,7 @@ PremultipliedImage decodeJPEG(const uint8_t* data, size_t size) {
PremultipliedImage image({ static_cast<uint32_t>(width), static_cast<uint32_t>(height) });
uint8_t* dst = image.data.get();
JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, rowStride, 1);
JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)(reinterpret_cast<j_common_ptr>(&cinfo), JPOOL_IMAGE, rowStride, 1);
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, buffer, 1);

View File

@@ -59,7 +59,7 @@ std::string encodePNG(const PremultipliedImage& pre) {
for (uint32_t y = 0; y < src.size.height; y++) {
// Every scanline needs to be prefixed with one byte that indicates the filter type.
idat.append(1, 0); // filter type 0
idat.append((const char*)(src.data.get() + y * stride), stride);
idat.append(reinterpret_cast<const char*>(src.data.get() + y * stride), stride);
}
idat = util::compress(idat);

View File

@@ -24,19 +24,23 @@ GeometryCollection clipLines(const GeometryCollection &lines,
continue;
} else if (p0.x < x1) {
p0 = {x1,
static_cast<int16_t>(std::round(p0.y + (p1.y - p0.y) * ((float)(x1 - p0.x) / (p1.x - p0.x))))};
static_cast<int16_t>(
std::round(p0.y + (p1.y - p0.y) * (static_cast<float>(x1 - p0.x) / (p1.x - p0.x))))};
} else if (p1.x < x1) {
p1 = {x1,
static_cast<int16_t>(std::round(p0.y + (p1.y - p0.y) * ((float)(x1 - p0.x) / (p1.x - p0.x))))};
static_cast<int16_t>(
std::round(p0.y + (p1.y - p0.y) * (static_cast<float>(x1 - p0.x) / (p1.x - p0.x))))};
}
if (p0.y < y1 && p1.y < y1) {
continue;
} else if (p0.y < y1) {
p0 = {static_cast<int16_t>(std::round(p0.x + (p1.x - p0.x) * ((float)(y1 - p0.y) / (p1.y - p0.y)))),
p0 = {static_cast<int16_t>(
std::round(p0.x + (p1.x - p0.x) * (static_cast<float>(y1 - p0.y) / (p1.y - p0.y)))),
y1};
} else if (p1.y < y1) {
p1 = {static_cast<int16_t>(std::round(p0.x + (p1.x - p0.x) * ((float)(y1 - p0.y) / (p1.y - p0.y)))),
p1 = {static_cast<int16_t>(
std::round(p0.x + (p1.x - p0.x) * (static_cast<float>(y1 - p0.y) / (p1.y - p0.y)))),
y1};
}
@@ -44,19 +48,23 @@ GeometryCollection clipLines(const GeometryCollection &lines,
continue;
} else if (p0.x >= x2) {
p0 = {x2,
static_cast<int16_t>(std::round(p0.y + (p1.y - p0.y) * ((float)(x2 - p0.x) / (p1.x - p0.x))))};
static_cast<int16_t>(
std::round(p0.y + (p1.y - p0.y) * (static_cast<float>(x2 - p0.x) / (p1.x - p0.x))))};
} else if (p1.x >= x2) {
p1 = {x2,
static_cast<int16_t>(std::round(p0.y + (p1.y - p0.y) * ((float)(x2 - p0.x) / (p1.x - p0.x))))};
static_cast<int16_t>(
std::round(p0.y + (p1.y - p0.y) * (static_cast<float>(x2 - p0.x) / (p1.x - p0.x))))};
}
if (p0.y >= y2 && p1.y >= y2) {
continue;
} else if (p0.y >= y2) {
p0 = {static_cast<int16_t>(std::round(p0.x + (p1.x - p0.x) * ((float)(y2 - p0.y) / (p1.y - p0.y)))),
p0 = {static_cast<int16_t>(
std::round(p0.x + (p1.x - p0.x) * (static_cast<float>(y2 - p0.y) / (p1.y - p0.y)))),
y2};
} else if (p1.y >= y2) {
p1 = {static_cast<int16_t>(std::round(p0.x + (p1.x - p0.x) * ((float)(y2 - p0.y) / (p1.y - p0.y)))),
p1 = {static_cast<int16_t>(
std::round(p0.x + (p1.x - p0.x) * (static_cast<float>(y2 - p0.y) / (p1.y - p0.y)))),
y2};
}

View File

@@ -36,7 +36,7 @@ RenderHillshadeLayer::~RenderHillshadeLayer() = default;
const std::array<float, 2> RenderHillshadeLayer::getLatRange(const UnwrappedTileID& id) {
const LatLng latlng0 = LatLng(id);
const LatLng latlng1 = LatLng(UnwrappedTileID(id.canonical.z, id.canonical.x, id.canonical.y + 1));
return {{ (float)latlng0.latitude(), (float)latlng1.latitude() }};
return {{static_cast<float>(latlng0.latitude()), static_cast<float>(latlng1.latitude())}};
}
const std::array<float, 2> RenderHillshadeLayer::getLight(const PaintParameters& parameters) {

View File

@@ -145,7 +145,8 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
// tiles are used from the cache, but not created.
optional<util::TileRange> tileRange = {};
if (bounds) {
tileRange = util::TileRange::fromLatLngBounds(*bounds, zoomRange.min, std::min(tileZoom, (int32_t)zoomRange.max));
tileRange = util::TileRange::fromLatLngBounds(
*bounds, zoomRange.min, std::min(tileZoom, static_cast<int32_t>(zoomRange.max)));
}
auto createTileFn = [&](const OverscaledTileID& tileID) -> Tile* {
if (tileRange && !tileRange->contains(tileID.canonical)) {
@@ -196,10 +197,9 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
if (type != SourceType::Annotations) {
size_t conservativeCacheSize =
std::max((float)parameters.transformState.getSize().width / tileSize, 1.0f) *
std::max((float)parameters.transformState.getSize().height / tileSize, 1.0f) *
(parameters.transformState.getMaxZoom() - parameters.transformState.getMinZoom() + 1) *
0.5;
std::max(static_cast<float>(parameters.transformState.getSize().width) / tileSize, 1.0f) *
std::max(static_cast<float>(parameters.transformState.getSize().height) / tileSize, 1.0f) *
(parameters.transformState.getMaxZoom() - parameters.transformState.getMinZoom() + 1) * 0.5;
cache.setSize(conservativeCacheSize);
}

View File

@@ -254,7 +254,7 @@ optional<mbgl::Value> serializeLegacyFilter(const Convertible& values) {
result.emplace_back(NullValue());
}
}
return (mbgl::Value)result;
return mbgl::Value(result);
}
return toValue(values);
}

View File

@@ -113,11 +113,13 @@ void build_bounds_map(PointList& points, uint32_t maxTile, BoundsMap& et, bool c
if (to_max.points.size() >= 2) {
// Projections may result in values beyond the bounds, clamp to max tile coordinates
const auto y = static_cast<uint32_t>(std::floor(clamp(to_max.points.front().y, 0.0, (double)maxTile)));
const auto y =
static_cast<uint32_t>(std::floor(clamp(to_max.points.front().y, 0.0, static_cast<double>(maxTile))));
et[y].push_back(to_max);
}
if (to_min.points.size() >= 2) {
const auto y = static_cast<uint32_t>(std::floor(clamp(to_min.points.front().y, 0.0, (double)maxTile)));
const auto y =
static_cast<uint32_t>(std::floor(clamp(to_min.points.front().y, 0.0, static_cast<double>(maxTile))));
et[y].push_back(to_min);
}
}
@@ -218,7 +220,7 @@ struct BuildBoundsMap {
bnd.points.insert(bnd.points.end(), 2, point);
bnd.winding = false;
BoundsMap et;
const auto y = static_cast<uint32_t>(std::floor(clamp(point.y, 0.0, (double)(1 << zoom))));
const auto y = static_cast<uint32_t>(std::floor(clamp(point.y, 0.0, static_cast<double>(1 << zoom))));
et[y].push_back(bnd);
return et;
}
@@ -233,7 +235,7 @@ struct BuildBoundsMap {
}
bnd.points.insert(bnd.points.end(), 2, point);
bnd.winding = false;
const auto y = static_cast<uint32_t>(std::floor(clamp(point.y, 0.0, (double)(1 << zoom))));
const auto y = static_cast<uint32_t>(std::floor(clamp(point.y, 0.0, static_cast<double>(1 << zoom))));
et[y].push_back(bnd);
}
return et;