Avoid implicit casts and make code more portable (#716)
This commit is contained in:
@@ -76,11 +76,11 @@ struct MemoryProbe {
|
||||
float tolerance;
|
||||
|
||||
static std::tuple<bool, float> checkPeak(const MemoryProbe& expected, const MemoryProbe& actual) {
|
||||
return checkValue(expected.peak, actual.peak, actual.tolerance);
|
||||
return checkValue(static_cast<float>(expected.peak), static_cast<float>(actual.peak), actual.tolerance);
|
||||
}
|
||||
|
||||
static std::tuple<bool, float> checkAllocations(const MemoryProbe& expected, const MemoryProbe& actual) {
|
||||
return checkValue(expected.allocations, actual.allocations, actual.tolerance);
|
||||
return checkValue(static_cast<float>(expected.allocations), static_cast<float>(actual.allocations), actual.tolerance);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ void writeJSON(rapidjson::PrettyWriter<rapidjson::StringBuffer>& writer, const m
|
||||
[&writer](bool b) { writer.Bool(b); },
|
||||
[&writer](uint64_t u) { writer.Uint64(u); },
|
||||
[&writer](int64_t i) { writer.Int64(i); },
|
||||
[&writer](double d) { d == std::floor(d) ? writer.Int64(d) : writer.Double(d); },
|
||||
[&writer](double d) { d == std::floor(d) ? writer.Int64(static_cast<int64_t>(d)) : writer.Double(d); },
|
||||
[&writer](const std::string& s) { writer.String(s); },
|
||||
[&writer](const std::vector<mbgl::Value>& arr) {
|
||||
writer.StartArray();
|
||||
@@ -929,7 +929,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
|
||||
std::string path = std::string(operationArray[2].GetString(), operationArray[2].GetStringLength());
|
||||
assert(!path.empty());
|
||||
|
||||
float tolerance = operationArray[3].GetDouble();
|
||||
float tolerance = static_cast<float>(operationArray[3].GetDouble());
|
||||
mbgl::filesystem::path filePath(path);
|
||||
|
||||
bool compressed = false;
|
||||
@@ -1189,7 +1189,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
|
||||
}
|
||||
|
||||
std::string mark = operationArray[1].GetString();
|
||||
int duration = operationArray[2].GetFloat();
|
||||
int duration = static_cast<int>(operationArray[2].GetFloat());
|
||||
mbgl::LatLng startPos, endPos;
|
||||
double startZoom, endZoom;
|
||||
|
||||
@@ -1235,7 +1235,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) {
|
||||
samples.push_back(frameTime);
|
||||
}
|
||||
|
||||
float averageFps = totalTime > 0.0 ? frames / totalTime : 0.0;
|
||||
float averageFps = totalTime > 0.0f ? frames / totalTime : 0.0f;
|
||||
float minFrameTime = 0.0;
|
||||
|
||||
// Use 1% of the longest frames to compute the minimum fps
|
||||
|
||||
@@ -257,13 +257,14 @@ void TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage,
|
||||
|
||||
expectedImage = mbgl::decodeImage(*maybeExpectedImage);
|
||||
|
||||
pixels = // implicitly converting from uint64_t
|
||||
pixels = static_cast<double>(
|
||||
mapbox::pixelmatch(actualImage.data.get(),
|
||||
expectedImage.data.get(),
|
||||
expectedImage.size.width,
|
||||
expectedImage.size.height,
|
||||
imageDiff.data.get(),
|
||||
0.1285); // Defined in GL JS
|
||||
0.1285) // Defined in GL JS
|
||||
);
|
||||
|
||||
metadata.diff = mbgl::encodePNG(imageDiff);
|
||||
|
||||
@@ -349,7 +350,7 @@ void TestRunner::checkProbingResults(TestMetadata& resultMetadata) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto result = checkValue(expected.second.size, actual->second.size, actual->second.tolerance);
|
||||
auto result = checkValue(static_cast<float>(expected.second.size), static_cast<float>(actual->second.size), actual->second.tolerance);
|
||||
if (!std::get<bool>(result)) {
|
||||
std::stringstream ss;
|
||||
ss << "File size does not match at probe \"" << expected.first << "\" for file \""
|
||||
@@ -663,7 +664,7 @@ LatLng getTileCenterCoordinates(const UnwrappedTileID& tileId) {
|
||||
}
|
||||
|
||||
uint32_t getTileScreenPixelSize(float pixelRatio) {
|
||||
return util::tileSize_D * pixelRatio;
|
||||
return static_cast<uint32_t>(util::tileSize_D * pixelRatio);
|
||||
}
|
||||
|
||||
uint32_t getImageTileOffset(const std::set<uint32_t>& dims, uint32_t dim, float pixelRatio) {
|
||||
@@ -757,7 +758,7 @@ void TestRunner::run(TestMetadata& metadata) {
|
||||
if (metadata.mapMode == MapMode::Tile) {
|
||||
assert(camera.zoom);
|
||||
assert(camera.center);
|
||||
auto tileIds = util::tileCover(map.latLngBoundsForCamera(camera), *camera.zoom);
|
||||
auto tileIds = util::tileCover(map.latLngBoundsForCamera(camera), static_cast<uint8_t>(*camera.zoom));
|
||||
assert(!tileIds.empty());
|
||||
std::set<uint32_t> xDims;
|
||||
std::set<uint32_t> yDims;
|
||||
|
||||
Reference in New Issue
Block a user