diff --git a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/TileSelectionState.h b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/TileSelectionState.h index baf801f1b..e2dfcf07b 100644 --- a/Cesium3DTilesSelection/include/Cesium3DTilesSelection/TileSelectionState.h +++ b/Cesium3DTilesSelection/include/Cesium3DTilesSelection/TileSelectionState.h @@ -117,7 +117,7 @@ class TileSelectionState final { * @return `true` if the tile was kicked, and `false` otherwise */ constexpr bool wasKicked(int32_t frameNumber) const noexcept { - Result result = this->getResult(frameNumber); + const Result result = this->getResult(frameNumber); return result == Result::RenderedAndKicked || result == Result::RefinedAndKicked; } @@ -131,7 +131,7 @@ class TileSelectionState final { * @return The {@link TileSelectionState::Result} prior to being kicked. */ constexpr Result getOriginalResult(int32_t frameNumber) const noexcept { - Result result = this->getResult(frameNumber); + const Result result = this->getResult(frameNumber); switch (result) { case Result::RefinedAndKicked: diff --git a/Cesium3DTilesSelection/src/Batched3DModelContent.cpp b/Cesium3DTilesSelection/src/Batched3DModelContent.cpp index 11d2638c1..f281b1975 100644 --- a/Cesium3DTilesSelection/src/Batched3DModelContent.cpp +++ b/Cesium3DTilesSelection/src/Batched3DModelContent.cpp @@ -57,7 +57,7 @@ rapidjson::Document parseFeatureTableJsonData( return document; } - auto rtcIt = document.FindMember("RTC_CENTER"); + const auto rtcIt = document.FindMember("RTC_CENTER"); if (rtcIt != document.MemberEnd() && rtcIt->value.IsArray() && rtcIt->value.Size() == 3 && rtcIt->value[0].IsDouble() && rtcIt->value[1].IsDouble() && rtcIt->value[2].IsDouble()) { @@ -158,18 +158,18 @@ std::unique_ptr Batched3DModelContent::load( "size specified in its header."); } - uint32_t glbStart = headerLength + header.featureTableJsonByteLength + + const uint32_t glbStart = headerLength + header.featureTableJsonByteLength + header.featureTableBinaryByteLength + header.batchTableJsonByteLength + header.batchTableBinaryByteLength; - uint32_t glbEnd = header.byteLength; + const uint32_t glbEnd = header.byteLength; if (glbEnd <= glbStart) { throw std::runtime_error("The B3DM is invalid because the start of the " "glTF model is after the end of the entire B3DM."); } - gsl::span glbData = + const gsl::span glbData = data.subspan(glbStart, glbEnd - glbStart); std::unique_ptr pResult = GltfContent::load(pLogger, url, glbData); @@ -177,21 +177,21 @@ std::unique_ptr Batched3DModelContent::load( if (pResult->model && header.featureTableJsonByteLength > 0) { CesiumGltf::Model& gltf = pResult->model.value(); - gsl::span featureTableJsonData = + const gsl::span featureTableJsonData = data.subspan(headerLength, header.featureTableJsonByteLength); rapidjson::Document featureTable = parseFeatureTableJsonData(pLogger, gltf, featureTableJsonData); - int64_t batchTableStart = headerLength + header.featureTableJsonByteLength + + const int64_t batchTableStart = headerLength + header.featureTableJsonByteLength + header.featureTableBinaryByteLength; - int64_t batchTableLength = + const int64_t batchTableLength = header.batchTableBinaryByteLength + header.batchTableJsonByteLength; if (batchTableLength > 0) { - gsl::span batchTableJsonData = data.subspan( + const gsl::span batchTableJsonData = data.subspan( static_cast(batchTableStart), header.batchTableJsonByteLength); - gsl::span batchTableBinaryData = data.subspan( + const gsl::span batchTableBinaryData = data.subspan( static_cast( batchTableStart + header.batchTableJsonByteLength), header.batchTableBinaryByteLength); diff --git a/Cesium3DTilesSelection/src/BingMapsRasterOverlay.cpp b/Cesium3DTilesSelection/src/BingMapsRasterOverlay.cpp index 2f0f7f40c..ec46c0084 100644 --- a/Cesium3DTilesSelection/src/BingMapsRasterOverlay.cpp +++ b/Cesium3DTilesSelection/src/BingMapsRasterOverlay.cpp @@ -155,7 +155,7 @@ class BingMapsTileProvider final : public QuadtreeRasterOverlayTileProvider { tileID.computeInvertedY(this->getTilingScheme())); } if (key == "subdomain") { - size_t subdomainIndex = + const size_t subdomainIndex = (tileID.level + tileID.x + tileID.y) % this->_subdomains.size(); return this->_subdomains[subdomainIndex]; } @@ -168,13 +168,13 @@ class BingMapsTileProvider final : public QuadtreeRasterOverlayTileProvider { options.rectangle = this->getTilingScheme().tileToRectangle(tileID); std::vector& tileCredits = options.credits; - CesiumGeospatial::GlobeRectangle tileRectangle = + const CesiumGeospatial::GlobeRectangle tileRectangle = CesiumGeospatial::unprojectRectangleSimple( this->getProjection(), options.rectangle); // Cesium levels start at 0, Bing levels start at 1 - unsigned int bingTileLevel = tileID.level + 1; + const unsigned int bingTileLevel = tileID.level + 1; for (const CreditAndCoverageAreas& creditAndCoverageAreas : _credits) { for (CoverageArea coverageArea : creditAndCoverageAreas.coverageAreas) { @@ -195,7 +195,7 @@ class BingMapsTileProvider final : public QuadtreeRasterOverlayTileProvider { static std::string tileXYToQuadKey(uint32_t level, uint32_t x, uint32_t y) { std::string quadkey; for (int32_t i = static_cast(level); i >= 0; --i) { - uint32_t bitmask = static_cast(1 << i); + const uint32_t bitmask = static_cast(1 << i); uint32_t digit = 0; if ((x & bitmask) != 0) { @@ -265,7 +265,7 @@ std::vector collectCredits( const rapidjson::Value* pResource, const std::shared_ptr& pCreditSystem) { std::vector credits; - auto attributionsIt = pResource->FindMember("imageryProviders"); + const auto attributionsIt = pResource->FindMember("imageryProviders"); if (attributionsIt != pResource->MemberEnd() && attributionsIt->value.IsArray()) { @@ -273,19 +273,19 @@ std::vector collectCredits( attributionsIt->value.GetArray()) { std::vector coverageAreas; - auto coverageAreasIt = attribution.FindMember("coverageAreas"); + const auto coverageAreasIt = attribution.FindMember("coverageAreas"); if (coverageAreasIt != attribution.MemberEnd() && coverageAreasIt->value.IsArray()) { for (const rapidjson::Value& area : coverageAreasIt->value.GetArray()) { - auto bboxIt = area.FindMember("bbox"); + const auto bboxIt = area.FindMember("bbox"); if (bboxIt != area.MemberEnd() && bboxIt->value.IsArray() && bboxIt->value.Size() == 4) { - auto zoomMinIt = area.FindMember("zoomMin"); - auto zoomMaxIt = area.FindMember("zoomMax"); - auto bboxArrayIt = bboxIt->value.GetArray(); + const auto zoomMinIt = area.FindMember("zoomMin"); + const auto zoomMaxIt = area.FindMember("zoomMax"); + const auto bboxArrayIt = bboxIt->value.GetArray(); if (zoomMinIt != area.MemberEnd() && zoomMaxIt != area.MemberEnd() && zoomMinIt->value.IsUint() && zoomMaxIt->value.IsUint() && bboxArrayIt[0].IsNumber() && @@ -307,7 +307,7 @@ std::vector collectCredits( } } - auto creditString = attribution.FindMember("attribution"); + const auto creditString = attribution.FindMember("attribution"); if (creditString != attribution.MemberEnd() && creditString->value.IsString()) { credits.push_back( @@ -437,7 +437,7 @@ BingMapsRasterOverlay::createTileProvider( } const std::byte* responseBuffer = pResponse->data().data(); - size_t responseSize = pResponse->data().size(); + const size_t responseSize = pResponse->data().size(); sessionCache[metadataUrl] = std::vector( pResponse->data().begin(), diff --git a/Cesium3DTilesSelection/src/BoundingVolume.cpp b/Cesium3DTilesSelection/src/BoundingVolume.cpp index 86a71330c..e5de7cdf8 100644 --- a/Cesium3DTilesSelection/src/BoundingVolume.cpp +++ b/Cesium3DTilesSelection/src/BoundingVolume.cpp @@ -12,8 +12,8 @@ BoundingVolume transformBoundingVolume( const glm::dmat4x4& transform; BoundingVolume operator()(const OrientedBoundingBox& boundingBox) { - glm::dvec3 center = transform * glm::dvec4(boundingBox.getCenter(), 1.0); - glm::dmat3 halfAxes = glm::dmat3(transform) * boundingBox.getHalfAxes(); + const glm::dvec3 center = transform * glm::dvec4(boundingBox.getCenter(), 1.0); + const glm::dmat3 halfAxes = glm::dmat3(transform) * boundingBox.getHalfAxes(); return OrientedBoundingBox(center, halfAxes); } @@ -23,10 +23,10 @@ BoundingVolume transformBoundingVolume( } BoundingVolume operator()(const BoundingSphere& boundingSphere) { - glm::dvec3 center = + const glm::dvec3 center = transform * glm::dvec4(boundingSphere.getCenter(), 1.0); - double uniformScale = glm::max( + const double uniformScale = glm::max( glm::max( glm::length(glm::dvec3(transform[0])), glm::length(glm::dvec3(transform[1]))), diff --git a/Cesium3DTilesSelection/src/CompositeContent.cpp b/Cesium3DTilesSelection/src/CompositeContent.cpp index b12bfb35c..83e2c1504 100644 --- a/Cesium3DTilesSelection/src/CompositeContent.cpp +++ b/Cesium3DTilesSelection/src/CompositeContent.cpp @@ -121,7 +121,7 @@ CompositeContent::load(const TileContentLoadInput& input) { break; } - gsl::span innerData(data.data() + pos, pInner->byteLength); + const gsl::span innerData(data.data() + pos, pInner->byteLength); std::unique_ptr pInnerLoadResult = TileContentFactory::createContent(derive(input, innerData)); @@ -162,4 +162,4 @@ CompositeContent::load(const TileContentLoadInput& input) { return pResult; } -} // namespace Cesium3DTilesSelection \ No newline at end of file +} // namespace Cesium3DTilesSelection diff --git a/Cesium3DTilesSelection/src/GltfContent.cpp b/Cesium3DTilesSelection/src/GltfContent.cpp index 7a7b03207..3d8e50d6a 100644 --- a/Cesium3DTilesSelection/src/GltfContent.cpp +++ b/Cesium3DTilesSelection/src/GltfContent.cpp @@ -70,16 +70,16 @@ static int generateOverlayTextureCoordinates( std::vector& bufferViews = gltf.bufferViews; std::vector& accessors = gltf.accessors; - int uvBufferId = static_cast(buffers.size()); + const int uvBufferId = static_cast(buffers.size()); CesiumGltf::Buffer& uvBuffer = buffers.emplace_back(); - int uvBufferViewId = static_cast(bufferViews.size()); + const int uvBufferViewId = static_cast(bufferViews.size()); bufferViews.emplace_back(); - int uvAccessorId = static_cast(accessors.size()); + const int uvAccessorId = static_cast(accessors.size()); accessors.emplace_back(); - CesiumGltf::AccessorView positionView(gltf, positionAccessorIndex); + const CesiumGltf::AccessorView positionView(gltf, positionAccessorIndex); if (positionView.status() != CesiumGltf::AccessorViewStatus::Valid) { return -1; } @@ -105,13 +105,13 @@ static int generateOverlayTextureCoordinates( CesiumGltf::AccessorWriter uvWriter(gltf, uvAccessorId); assert(uvWriter.status() == CesiumGltf::AccessorViewStatus::Valid); - double width = rectangle.computeWidth(); - double height = rectangle.computeHeight(); + const double width = rectangle.computeWidth(); + const double height = rectangle.computeHeight(); for (int64_t i = 0; i < positionView.size(); ++i) { // Get the ECEF position - glm::vec3 position = positionView[i]; - glm::dvec3 positionEcef = transform * glm::dvec4(position, 1.0); + const glm::vec3 position = positionView[i]; + const glm::dvec3 positionEcef = transform * glm::dvec4(position, 1.0); // Convert it to cartographic std::optional cartographic = @@ -127,8 +127,8 @@ static int generateOverlayTextureCoordinates( projectPosition(projection, cartographic.value()); double longitude = cartographic.value().longitude; - double latitude = cartographic.value().latitude; - double ellipsoidHeight = cartographic.value().height; + const double latitude = cartographic.value().latitude; + const double ellipsoidHeight = cartographic.value().height; // If the position is near the anti-meridian and the projected position is // outside the expected range, try using the equivalent longitude on the @@ -143,11 +143,11 @@ static int generateOverlayTextureCoordinates( cartographic.value().longitude += cartographic.value().longitude < 0.0 ? CesiumUtility::Math::TWO_PI : -CesiumUtility::Math::TWO_PI; - glm::dvec3 projectedPosition2 = + const glm::dvec3 projectedPosition2 = projectPosition(projection, cartographic.value()); - double distance1 = rectangle.computeSignedDistance(projectedPosition); - double distance2 = rectangle.computeSignedDistance(projectedPosition2); + const double distance1 = rectangle.computeSignedDistance(projectedPosition); + const double distance2 = rectangle.computeSignedDistance(projectedPosition2); if (distance2 < distance1) { projectedPosition = projectedPosition2; @@ -232,13 +232,13 @@ GltfContent::createRasterOverlayTextureCoordinates( return; } - int positionAccessorIndex = positionIt->second; + const int positionAccessorIndex = positionIt->second; if (positionAccessorIndex < 0 || positionAccessorIndex >= static_cast(gltf_.accessors.size())) { return; } - int textureCoordinateAccessorIndex = + const int textureCoordinateAccessorIndex = positionAccessorsToTextureCoordinateAccessor[static_cast( positionAccessorIndex)]; if (textureCoordinateAccessorIndex > 0) { @@ -252,12 +252,12 @@ GltfContent::createRasterOverlayTextureCoordinates( return; } - glm::dmat4 fullTransform = + const glm::dmat4 fullTransform = transform * CesiumGeometry::AxisTransforms::Y_UP_TO_Z_UP * nodeTransform; // Generate new texture coordinates - int nextTextureCoordinateAccessorIndex = + const int nextTextureCoordinateAccessorIndex = generateOverlayTextureCoordinates( gltf_, positionAccessorIndex, diff --git a/Cesium3DTilesSelection/src/IonRasterOverlay.cpp b/Cesium3DTilesSelection/src/IonRasterOverlay.cpp index e725009cb..bee5fc1ed 100644 --- a/Cesium3DTilesSelection/src/IonRasterOverlay.cpp +++ b/Cesium3DTilesSelection/src/IonRasterOverlay.cpp @@ -81,7 +81,7 @@ IonRasterOverlay::createTileProvider( "externalType", "unknown"); if (externalType == "BING") { - auto optionsIt = response.FindMember("options"); + const auto optionsIt = response.FindMember("options"); if (optionsIt == response.MemberEnd() || !optionsIt->value.IsObject()) { SPDLOG_LOGGER_ERROR( diff --git a/Cesium3DTilesSelection/src/QuadtreeRasterOverlayTileProvider.cpp b/Cesium3DTilesSelection/src/QuadtreeRasterOverlayTileProvider.cpp index 3e5c07bd5..dccc4a8a3 100644 --- a/Cesium3DTilesSelection/src/QuadtreeRasterOverlayTileProvider.cpp +++ b/Cesium3DTilesSelection/src/QuadtreeRasterOverlayTileProvider.cpp @@ -131,12 +131,12 @@ QuadtreeRasterOverlayTileProvider::mapRasterTilesToGeometryTile( intersection.getCenter()); imageryLevel = glm::max(0U, imageryLevel); - uint32_t maximumLevel = this->getMaximumLevel(); + const uint32_t maximumLevel = this->getMaximumLevel(); if (imageryLevel > maximumLevel) { imageryLevel = maximumLevel; } - uint32_t minimumLevel = this->getMinimumLevel(); + const uint32_t minimumLevel = this->getMinimumLevel(); if (imageryLevel < minimumLevel) { imageryLevel = minimumLevel; } @@ -166,10 +166,10 @@ QuadtreeRasterOverlayTileProvider::mapRasterTilesToGeometryTile( // actually need the southernmost or westernmost tiles. // We define "very close" as being within 1/512 of the width of the tile. - double veryCloseX = geometryRectangle.computeWidth() / 512.0; - double veryCloseY = geometryRectangle.computeHeight() / 512.0; + const double veryCloseX = geometryRectangle.computeWidth() / 512.0; + const double veryCloseY = geometryRectangle.computeHeight() / 512.0; - CesiumGeometry::Rectangle southwestTileRectangle = + const CesiumGeometry::Rectangle southwestTileRectangle = imageryTilingScheme.tileToRectangle(southwestTileCoordinates); if (glm::abs(southwestTileRectangle.maximumY - geometryRectangle.minimumY) < @@ -184,7 +184,7 @@ QuadtreeRasterOverlayTileProvider::mapRasterTilesToGeometryTile( ++southwestTileCoordinates.x; } - CesiumGeometry::Rectangle northeastTileRectangle = + const CesiumGeometry::Rectangle northeastTileRectangle = imageryTilingScheme.tileToRectangle(northeastTileCoordinates); if (glm::abs(northeastTileRectangle.maximumY - geometryRectangle.minimumY) < @@ -202,7 +202,7 @@ QuadtreeRasterOverlayTileProvider::mapRasterTilesToGeometryTile( // Create TileImagery instances for each imagery tile overlapping this terrain // tile. We need to do all texture coordinate computations in the imagery // provider's projection. - CesiumGeometry::Rectangle imageryBounds = intersection; + const CesiumGeometry::Rectangle imageryBounds = intersection; std::optional clippedImageryRectangle = std::nullopt; @@ -248,18 +248,18 @@ uint32_t QuadtreeRasterOverlayTileProvider::computeLevelFromGeometricError( const CesiumGeometry::Rectangle& tilingSchemeRectangle = tilingScheme.getRectangle(); - double toMeters = computeApproximateConversionFactorToMetersNearPosition( + const double toMeters = computeApproximateConversionFactorToMetersNearPosition( this->getProjection(), position); - double levelZeroMaximumTexelSpacingMeters = + const double levelZeroMaximumTexelSpacingMeters = (tilingSchemeRectangle.computeWidth() * toMeters) / (this->_imageWidth * tilingScheme.getNumberOfXTilesAtLevel(0)); - double twoToTheLevelPower = + const double twoToTheLevelPower = levelZeroMaximumTexelSpacingMeters / geometricError; - double level = glm::log2(twoToTheLevelPower); - double rounded = glm::max(glm::round(level), 0.0); + const double level = glm::log2(twoToTheLevelPower); + const double rounded = glm::max(glm::round(level), 0.0); return static_cast(rounded); } @@ -286,8 +286,8 @@ QuadtreeRasterOverlayTileProvider::getQuadtreeTile( // non-thread-safe object from another thread and creating a (potentially very // subtle) race condition. auto loadParentTile = [tileID, this]() { - Rectangle rectangle = this->getTilingScheme().tileToRectangle(tileID); - QuadtreeTileID parentID(tileID.level - 1, tileID.x >> 1, tileID.y >> 1); + const Rectangle rectangle = this->getTilingScheme().tileToRectangle(tileID); + const QuadtreeTileID parentID(tileID.level - 1, tileID.x >> 1, tileID.y >> 1); return this->getQuadtreeTile(parentID).thenImmediately( [rectangle](const LoadedQuadtreeImage& loaded) { return LoadedQuadtreeImage{loaded.pLoaded, rectangle}; @@ -384,7 +384,7 @@ void blitImage( const ImageCesium& source, const Rectangle& sourceRectangle, const std::optional& sourceSubset) { - Rectangle sourceToCopy = sourceSubset.value_or(sourceRectangle); + const Rectangle sourceToCopy = sourceSubset.value_or(sourceRectangle); std::optional overlap = targetRectangle.computeIntersection(sourceToCopy); if (!overlap) { @@ -392,9 +392,9 @@ void blitImage( return; } - PixelRectangle targetPixels = + const PixelRectangle targetPixels = computePixelRectangle(target, targetRectangle, *overlap); - PixelRectangle sourcePixels = + const PixelRectangle sourcePixels = computePixelRectangle(source, sourceRectangle, *overlap); ImageManipulation::blitImage(target, targetPixels, source, sourcePixels); @@ -420,7 +420,7 @@ QuadtreeRasterOverlayTileProvider::loadTileImage( // This set of images is only "useful" if at least one actually has // image data, and that image data is _not_ from an ancestor. We can // identify ancestor images because they have a `subset`. - bool haveAnyUsefulImageData = std::any_of( + const bool haveAnyUsefulImageData = std::any_of( images.begin(), images.end(), [](const LoadedQuadtreeImage& image) { @@ -452,7 +452,7 @@ QuadtreeRasterOverlayTileProvider::loadTileImage( void QuadtreeRasterOverlayTileProvider::unloadCachedTiles() { CESIUM_TRACE("QuadtreeRasterOverlayTileProvider::unloadCachedTiles"); - int64_t maxCacheBytes = this->getOwner().getOptions().subTileCacheBytes; + const int64_t maxCacheBytes = this->getOwner().getOptions().subTileCacheBytes; if (this->_cachedBytes <= maxCacheBytes) { return; } @@ -461,7 +461,7 @@ void QuadtreeRasterOverlayTileProvider::unloadCachedTiles() { while (it != this->_tilesOldToRecent.end() && this->_cachedBytes > maxCacheBytes) { - SharedFuture& future = it->future; + const SharedFuture& future = it->future; if (!future.isReady()) { // Don't unload tiles that are still loading. ++it; @@ -532,7 +532,7 @@ QuadtreeRasterOverlayTileProvider::measureCombinedImage( } // The portion of the source that we actually need to copy. - Rectangle sourceSubset = image.subset.value_or(loaded.rectangle); + const Rectangle sourceSubset = image.subset.value_or(loaded.rectangle); // Find the bounds of the combined image. // Intersect the loaded image's rectangle with the target rectangle. @@ -587,10 +587,10 @@ QuadtreeRasterOverlayTileProvider::measureCombinedImage( } // Compute the pixel dimensions needed for the combined image. - int32_t combinedWidthPixels = static_cast(Math::roundUp( + const int32_t combinedWidthPixels = static_cast(Math::roundUp( combinedRectangle->computeWidth() / projectedWidthPerPixel, pixelTolerance)); - int32_t combinedHeightPixels = static_cast(Math::roundUp( + const int32_t combinedHeightPixels = static_cast(Math::roundUp( combinedRectangle->computeHeight() / projectedHeightPerPixel, pixelTolerance)); @@ -608,12 +608,12 @@ QuadtreeRasterOverlayTileProvider::combineImages( const Projection& /* projection */, std::vector&& images) { - CombinedImageMeasurements measurements = + const CombinedImageMeasurements measurements = QuadtreeRasterOverlayTileProvider::measureCombinedImage( targetRectangle, images); - int32_t targetImageBytes = measurements.widthPixels * + const int32_t targetImageBytes = measurements.widthPixels * measurements.heightPixels * measurements.channels * measurements.bytesPerChannel; if (targetImageBytes <= 0) { diff --git a/Cesium3DTilesSelection/src/QuantizedMeshContent.cpp b/Cesium3DTilesSelection/src/QuantizedMeshContent.cpp index d23b304e1..d37dd5be9 100644 --- a/Cesium3DTilesSelection/src/QuantizedMeshContent.cpp +++ b/Cesium3DTilesSelection/src/QuantizedMeshContent.cpp @@ -158,7 +158,7 @@ static glm::dvec3 octDecode(uint8_t x, uint8_t y) { result.z = 1.0 - (glm::abs(result.x) + glm::abs(result.y)); if (result.z < 0.0) { - double oldVX = result.x; + const double oldVX = result.x; result.x = (1.0 - glm::abs(result.y)) * CesiumUtility::Math::signNotZero(oldVX); result.y = @@ -189,7 +189,7 @@ static std::optional parseQuantizedMesh( readIndex += headerLength; // parse u, v, and height buffers - uint32_t vertexCount = meshView.header->vertexCount; + const uint32_t vertexCount = meshView.header->vertexCount; meshView.uBuffer = gsl::span( reinterpret_cast(data.data() + readIndex), @@ -232,7 +232,7 @@ static std::optional parseQuantizedMesh( return std::nullopt; } - uint32_t indicesCount = meshView.triangleCount * 3; + const uint32_t indicesCount = meshView.triangleCount * 3; meshView.indicesBuffer = gsl::span( data.data() + readIndex, indicesCount * sizeof(uint32_t)); @@ -251,7 +251,7 @@ static std::optional parseQuantizedMesh( return std::nullopt; } - uint32_t indicesCount = meshView.triangleCount * 3; + const uint32_t indicesCount = meshView.triangleCount * 3; meshView.indicesBuffer = gsl::span( data.data() + readIndex, indicesCount * sizeof(uint16_t)); @@ -321,10 +321,10 @@ static std::optional parseQuantizedMesh( break; } - uint8_t extensionID = + const uint8_t extensionID = *reinterpret_cast(data.data() + readIndex); readIndex += sizeof(uint8_t); - uint32_t extensionLength = + const uint32_t extensionLength = *reinterpret_cast(data.data() + readIndex); readIndex += sizeof(uint32_t); @@ -380,7 +380,7 @@ static std::optional parseQuantizedMesh( static double calculateSkirtHeight( const CesiumGeospatial::Ellipsoid& ellipsoid, const CesiumGeospatial::GlobeRectangle& rectangle) { - double levelMaximumGeometricError = + const double levelMaximumGeometricError = calcQuadtreeMaxGeometricError(ellipsoid) * rectangle.computeWidth(); return levelMaximumGeometricError * 5.0; } @@ -402,10 +402,10 @@ static void addSkirt( gsl::span& positions, gsl::span& normals, gsl::span& indices) { - double west = rectangle.getWest(); - double south = rectangle.getSouth(); - double east = rectangle.getEast(); - double north = rectangle.getNorth(); + const double west = rectangle.getWest(); + const double south = rectangle.getSouth(); + const double east = rectangle.getEast(); + const double north = rectangle.getNorth(); size_t newEdgeIndex = currentVertexCount; size_t positionIdx = currentVertexCount * 3; @@ -413,12 +413,12 @@ static void addSkirt( for (size_t i = 0; i < edgeIndices.size(); ++i) { E edgeIdx = edgeIndices[i]; - double uRatio = uvsAndHeights[edgeIdx].x; - double vRatio = uvsAndHeights[edgeIdx].y; - double heightRatio = uvsAndHeights[edgeIdx].z; - double longitude = Math::lerp(west, east, uRatio) + longitudeOffset; - double latitude = Math::lerp(south, north, vRatio) + latitudeOffset; - double heightMeters = + const double uRatio = uvsAndHeights[edgeIdx].x; + const double vRatio = uvsAndHeights[edgeIdx].y; + const double heightRatio = uvsAndHeights[edgeIdx].z; + const double longitude = Math::lerp(west, east, uRatio) + longitudeOffset; + const double latitude = Math::lerp(south, north, vRatio) + latitudeOffset; + const double heightMeters = Math::lerp(minimumHeight, maximumHeight, heightRatio) - skirtHeight; glm::dvec3 position = ellipsoid.cartographicToCartesian( Cartographic(longitude, latitude, heightMeters)); @@ -429,7 +429,7 @@ static void addSkirt( positions[positionIdx + 2] = static_cast(position.z); if (!normals.empty()) { - size_t componentIndex = static_cast(3 * edgeIdx); + const size_t componentIndex = static_cast(3 * edgeIdx); normals[positionIdx] = normals[componentIndex]; normals[positionIdx + 1] = normals[componentIndex + 1]; normals[positionIdx + 2] = normals[componentIndex + 2]; @@ -471,13 +471,13 @@ static void addSkirts( gsl::span& outputPositions, gsl::span& outputNormals, gsl::span& outputIndices) { - uint32_t westVertexCount = + const uint32_t westVertexCount = static_cast(westEdgeIndicesBuffer.size() / sizeof(E)); - uint32_t southVertexCount = + const uint32_t southVertexCount = static_cast(southEdgeIndicesBuffer.size() / sizeof(E)); - uint32_t eastVertexCount = + const uint32_t eastVertexCount = static_cast(eastEdgeIndicesBuffer.size() / sizeof(E)); - uint32_t northVertexCount = + const uint32_t northVertexCount = static_cast(northEdgeIndicesBuffer.size() / sizeof(E)); // allocate edge indices to be sort later @@ -635,22 +635,22 @@ static std::vector generateNormals( const gsl::span& indices, size_t currentNumOfIndex) { std::vector normalsBuffer(positions.size() * sizeof(float)); - gsl::span normals( + const gsl::span normals( reinterpret_cast(normalsBuffer.data()), positions.size()); for (size_t i = 0; i < currentNumOfIndex; i += 3) { T id0 = indices[i]; T id1 = indices[i + 1]; T id2 = indices[i + 2]; - size_t id0x3 = static_cast(id0) * 3; - size_t id1x3 = static_cast(id1) * 3; - size_t id2x3 = static_cast(id2) * 3; + const size_t id0x3 = static_cast(id0) * 3; + const size_t id1x3 = static_cast(id1) * 3; + const size_t id2x3 = static_cast(id2) * 3; - glm::vec3 p0 = + const glm::vec3 p0 = glm::vec3(positions[id0x3], positions[id0x3 + 1], positions[id0x3 + 2]); - glm::vec3 p1 = + const glm::vec3 p1 = glm::vec3(positions[id1x3], positions[id1x3 + 1], positions[id1x3 + 2]); - glm::vec3 p2 = + const glm::vec3 p2 = glm::vec3(positions[id2x3], positions[id2x3 + 1], positions[id2x3 + 2]); glm::vec3 normal = glm::cross(p1 - p0, p2 - p0); @@ -736,12 +736,12 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { // get vertex count for this mesh const QuantizedMeshHeader* pHeader = meshView->header; - uint32_t vertexCount = pHeader->vertexCount; - uint32_t indicesCount = meshView->triangleCount * 3; - uint32_t skirtVertexCount = + const uint32_t vertexCount = pHeader->vertexCount; + const uint32_t indicesCount = meshView->triangleCount * 3; + const uint32_t skirtVertexCount = meshView->westEdgeIndicesCount + meshView->southEdgeIndicesCount + meshView->eastEdgeIndicesCount + meshView->northEdgeIndicesCount; - uint32_t skirtIndicesCount = (skirtVertexCount - 4) * 6; + const uint32_t skirtIndicesCount = (skirtVertexCount - 4) * 6; // decode position without skirt, but preallocate position buffer to include // skirt as well @@ -752,16 +752,16 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { (vertexCount + skirtVertexCount) * 3); size_t positionOutputIndex = 0; - glm::dvec3 center( + const glm::dvec3 center( pHeader->BoundingSphereCenterX, pHeader->BoundingSphereCenterY, pHeader->BoundingSphereCenterZ); - glm::dvec3 horizonOcclusionPoint( + const glm::dvec3 horizonOcclusionPoint( pHeader->HorizonOcclusionPointX, pHeader->HorizonOcclusionPointY, pHeader->HorizonOcclusionPointZ); - double minimumHeight = pHeader->MinimumHeight; - double maximumHeight = pHeader->MaximumHeight; + const double minimumHeight = pHeader->MinimumHeight; + const double maximumHeight = pHeader->MaximumHeight; double minX = std::numeric_limits::max(); double minY = std::numeric_limits::max(); @@ -772,10 +772,10 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { const Ellipsoid& ellipsoid = Ellipsoid::WGS84; const CesiumGeospatial::GlobeRectangle& rectangle = pRegion->getRectangle(); - double west = rectangle.getWest(); - double south = rectangle.getSouth(); - double east = rectangle.getEast(); - double north = rectangle.getNorth(); + const double west = rectangle.getWest(); + const double south = rectangle.getSouth(); + const double east = rectangle.getEast(); + const double north = rectangle.getNorth(); int32_t u = 0; int32_t v = 0; @@ -791,9 +791,9 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { double vRatio = static_cast(v) / 32767.0; double heightRatio = static_cast(height) / 32767.0; - double longitude = Math::lerp(west, east, uRatio); - double latitude = Math::lerp(south, north, vRatio); - double heightMeters = Math::lerp(minimumHeight, maximumHeight, heightRatio); + const double longitude = Math::lerp(west, east, uRatio); + const double latitude = Math::lerp(south, north, vRatio); + const double heightMeters = Math::lerp(minimumHeight, maximumHeight, heightRatio); glm::dvec3 position = ellipsoid.cartographicToCartesian( Cartographic(longitude, latitude, heightMeters)); @@ -817,7 +817,7 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { std::vector outputNormalsBuffer; gsl::span outputNormals; if (!meshView->octEncodedNormalBuffer.empty()) { - uint32_t totalNormalFloats = (vertexCount + skirtVertexCount) * 3; + const uint32_t totalNormalFloats = (vertexCount + skirtVertexCount) * 3; outputNormalsBuffer.resize(totalNormalFloats * sizeof(float)); outputNormals = gsl::span( reinterpret_cast(outputNormalsBuffer.data()), @@ -842,14 +842,14 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { meshView->indexType == QuantizedMeshIndexType::UnsignedInt ? sizeof(uint32_t) : sizeof(uint16_t); - double skirtHeight = calculateSkirtHeight(ellipsoid, rectangle); - double longitudeOffset = (east - west) * 0.0001; - double latitudeOffset = (north - south) * 0.0001; + const double skirtHeight = calculateSkirtHeight(ellipsoid, rectangle); + const double longitudeOffset = (east - west) * 0.0001; + const double latitudeOffset = (north - south) * 0.0001; if (meshView->indexType == QuantizedMeshIndexType::UnsignedInt) { // decode the tile indices without skirt. - size_t outputIndicesCount = indicesCount + skirtIndicesCount; + const size_t outputIndicesCount = indicesCount + skirtIndicesCount; outputIndicesBuffer.resize(outputIndicesCount * sizeof(uint32_t)); - gsl::span indices( + const gsl::span indices( reinterpret_cast(meshView->indicesBuffer.data()), indicesCount); gsl::span outputIndices( @@ -889,8 +889,8 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { indexSizeBytes = sizeof(uint32_t); } else { - size_t outputIndicesCount = indicesCount + skirtIndicesCount; - gsl::span indices( + const size_t outputIndicesCount = indicesCount + skirtIndicesCount; + const gsl::span indices( reinterpret_cast(meshView->indicesBuffer.data()), indicesCount); if (vertexCount + skirtVertexCount < std::numeric_limits::max()) { @@ -981,7 +981,7 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { pbr.metallicFactor = 0.0; pbr.roughnessFactor = 1.0; - size_t meshId = model.meshes.size(); + const size_t meshId = model.meshes.size(); model.meshes.emplace_back(); CesiumGltf::Mesh& mesh = model.meshes[meshId]; mesh.primitives.emplace_back(); @@ -991,12 +991,12 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { primitive.material = 0; // add position buffer to gltf - size_t positionBufferId = model.buffers.size(); + const size_t positionBufferId = model.buffers.size(); model.buffers.emplace_back(); CesiumGltf::Buffer& positionBuffer = model.buffers[positionBufferId]; positionBuffer.cesium.data = std::move(outputPositionsBuffer); - size_t positionBufferViewId = model.bufferViews.size(); + const size_t positionBufferViewId = model.bufferViews.size(); model.bufferViews.emplace_back(); CesiumGltf::BufferView& positionBufferView = model.bufferViews[positionBufferViewId]; @@ -1006,7 +1006,7 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { positionBufferView.byteLength = int64_t(positionBuffer.cesium.data.size()); positionBufferView.target = CesiumGltf::BufferView::Target::ARRAY_BUFFER; - size_t positionAccessorId = model.accessors.size(); + const size_t positionAccessorId = model.accessors.size(); model.accessors.emplace_back(); CesiumGltf::Accessor& positionAccessor = model.accessors[positionAccessorId]; positionAccessor.bufferView = static_cast(positionBufferViewId); @@ -1021,12 +1021,12 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { // add normal buffer to gltf if there are any if (!outputNormalsBuffer.empty()) { - size_t normalBufferId = model.buffers.size(); + const size_t normalBufferId = model.buffers.size(); model.buffers.emplace_back(); CesiumGltf::Buffer& normalBuffer = model.buffers[normalBufferId]; normalBuffer.cesium.data = std::move(outputNormalsBuffer); - size_t normalBufferViewId = model.bufferViews.size(); + const size_t normalBufferViewId = model.bufferViews.size(); model.bufferViews.emplace_back(); CesiumGltf::BufferView& normalBufferView = model.bufferViews[normalBufferViewId]; @@ -1036,7 +1036,7 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { normalBufferView.byteLength = int64_t(normalBuffer.cesium.data.size()); normalBufferView.target = CesiumGltf::BufferView::Target::ARRAY_BUFFER; - size_t normalAccessorId = model.accessors.size(); + const size_t normalAccessorId = model.accessors.size(); model.accessors.emplace_back(); CesiumGltf::Accessor& normalAccessor = model.accessors[normalAccessorId]; normalAccessor.bufferView = int32_t(normalBufferViewId); @@ -1049,12 +1049,12 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { } // add indices buffer to gltf - size_t indicesBufferId = model.buffers.size(); + const size_t indicesBufferId = model.buffers.size(); model.buffers.emplace_back(); CesiumGltf::Buffer& indicesBuffer = model.buffers[indicesBufferId]; indicesBuffer.cesium.data = std::move(outputIndicesBuffer); - size_t indicesBufferViewId = model.bufferViews.size(); + const size_t indicesBufferViewId = model.bufferViews.size(); model.bufferViews.emplace_back(); CesiumGltf::BufferView& indicesBufferView = model.bufferViews[indicesBufferViewId]; @@ -1064,7 +1064,7 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { indicesBufferView.byteStride = indexSizeBytes; indicesBufferView.target = CesiumGltf::BufferView::Target::ARRAY_BUFFER; - size_t indicesAccessorId = model.accessors.size(); + const size_t indicesAccessorId = model.accessors.size(); model.accessors.emplace_back(); CesiumGltf::Accessor& indicesAccessor = model.accessors[indicesAccessorId]; indicesAccessor.bufferView = int32_t(indicesBufferViewId); @@ -1103,7 +1103,7 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { if (!meshView->onlyWater && !meshView->onlyLand) { // create source image - size_t waterMaskImageId = model.images.size(); + const size_t waterMaskImageId = model.images.size(); model.images.emplace_back(); CesiumGltf::Image& waterMaskImage = model.images[waterMaskImageId]; waterMaskImage.cesium.width = 256; @@ -1117,7 +1117,7 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { 65536); // create sampler parameters - size_t waterMaskSamplerId = model.samplers.size(); + const size_t waterMaskSamplerId = model.samplers.size(); model.samplers.emplace_back(); CesiumGltf::Sampler& waterMaskSampler = model.samplers[waterMaskSamplerId]; waterMaskSampler.magFilter = CesiumGltf::Sampler::MagFilter::LINEAR; @@ -1127,7 +1127,7 @@ QuantizedMeshContent::load(const TileContentLoadInput& input) { waterMaskSampler.wrapT = CesiumGltf::Sampler::WrapT::CLAMP_TO_EDGE; // create texture - size_t waterMaskTextureId = model.textures.size(); + const size_t waterMaskTextureId = model.textures.size(); model.textures.emplace_back(); CesiumGltf::Texture& waterMaskTexture = model.textures[waterMaskTextureId]; waterMaskTexture.sampler = int32_t(waterMaskSamplerId); @@ -1197,7 +1197,7 @@ static void processMetadata( return; } - auto availableIt = metadata.FindMember("available"); + const auto availableIt = metadata.FindMember("available"); if (availableIt == metadata.MemberEnd() || !availableIt->value.IsArray()) { return; } diff --git a/Cesium3DTilesSelection/src/RasterMappedTo3DTile.cpp b/Cesium3DTilesSelection/src/RasterMappedTo3DTile.cpp index db418eba0..149809189 100644 --- a/Cesium3DTilesSelection/src/RasterMappedTo3DTile.cpp +++ b/Cesium3DTilesSelection/src/RasterMappedTo3DTile.cpp @@ -86,7 +86,7 @@ RasterMappedTo3DTile::update(Tile& tile) { this->_pLoadingTile->getState() >= RasterOverlayTile::LoadState::Loaded) { // Unattach the old tile if (this->_pReadyTile && this->getState() != AttachmentState::Unattached) { - TilesetExternals& externals = tile.getTileset()->getExternals(); + const TilesetExternals& externals = tile.getTileset()->getExternals(); externals.pPrepareRendererResources->detachRasterInMainThread( tile, this->getTextureCoordinateID(), @@ -121,7 +121,7 @@ RasterMappedTo3DTile::update(Tile& tile) { pCandidate->getState() >= RasterOverlayTile::LoadState::Loaded && this->_pReadyTile != pCandidate) { if (this->getState() != AttachmentState::Unattached) { - TilesetExternals& externals = tile.getTileset()->getExternals(); + const TilesetExternals& externals = tile.getTileset()->getExternals(); externals.pPrepareRendererResources->detachRasterInMainThread( tile, this->getTextureCoordinateID(), @@ -142,7 +142,7 @@ RasterMappedTo3DTile::update(Tile& tile) { this->getState() == RasterMappedTo3DTile::AttachmentState::Unattached) { this->_pReadyTile->loadInMainThread(); - TilesetExternals& externals = tile.getTileset()->getExternals(); + const TilesetExternals& externals = tile.getTileset()->getExternals(); externals.pPrepareRendererResources->attachRasterInMainThread( tile, this->getTextureCoordinateID(), @@ -177,7 +177,7 @@ void RasterMappedTo3DTile::detachFromTile(Tile& tile) noexcept { return; } - TilesetExternals& externals = tile.getTileset()->getExternals(); + const TilesetExternals& externals = tile.getTileset()->getExternals(); externals.pPrepareRendererResources->detachRasterInMainThread( tile, this->getTextureCoordinateID(), @@ -198,18 +198,18 @@ void RasterMappedTo3DTile::computeTranslationAndScale(Tile& tile) { return; } - RasterOverlayTileProvider& tileProvider = + const RasterOverlayTileProvider& tileProvider = *this->_pReadyTile->getOverlay().getTileProvider(); - CesiumGeometry::Rectangle geometryRectangle = + const CesiumGeometry::Rectangle geometryRectangle = projectRectangleSimple(tileProvider.getProjection(), *pRectangle); - CesiumGeometry::Rectangle imageryRectangle = + const CesiumGeometry::Rectangle imageryRectangle = this->_pReadyTile->getRectangle(); - double terrainWidth = geometryRectangle.computeWidth(); - double terrainHeight = geometryRectangle.computeHeight(); + const double terrainWidth = geometryRectangle.computeWidth(); + const double terrainHeight = geometryRectangle.computeHeight(); - double scaleX = terrainWidth / imageryRectangle.computeWidth(); - double scaleY = terrainHeight / imageryRectangle.computeHeight(); + const double scaleX = terrainWidth / imageryRectangle.computeWidth(); + const double scaleY = terrainHeight / imageryRectangle.computeHeight(); this->_translation = glm::dvec2( (scaleX * (geometryRectangle.minimumX - imageryRectangle.minimumX)) / terrainWidth, diff --git a/Cesium3DTilesSelection/src/RasterOverlayTile.cpp b/Cesium3DTilesSelection/src/RasterOverlayTile.cpp index e5f8c6780..848ee41b6 100644 --- a/Cesium3DTilesSelection/src/RasterOverlayTile.cpp +++ b/Cesium3DTilesSelection/src/RasterOverlayTile.cpp @@ -80,7 +80,7 @@ void RasterOverlayTile::addReference() noexcept { ++this->_references; } void RasterOverlayTile::releaseReference() noexcept { assert(this->_references > 0); - uint32_t references = --this->_references; + const uint32_t references = --this->_references; if (references == 0) { assert(this->_pOverlay != nullptr); assert(this->_pOverlay->getTileProvider() != nullptr); diff --git a/Cesium3DTilesSelection/src/RasterOverlayTileProvider.cpp b/Cesium3DTilesSelection/src/RasterOverlayTileProvider.cpp index 71600b358..7aa3c44a2 100644 --- a/Cesium3DTilesSelection/src/RasterOverlayTileProvider.cpp +++ b/Cesium3DTilesSelection/src/RasterOverlayTileProvider.cpp @@ -164,7 +164,7 @@ RasterOverlayTileProvider::loadTileImageFromUrl( options.moreDetailAvailable}; } - gsl::span data = pResponse->data(); + const gsl::span data = pResponse->data(); CesiumGltf::ImageReaderResult loadedImage = RasterOverlayTileProvider::_gltfReader.readImage(data); @@ -244,8 +244,8 @@ static LoadResult createLoadResultFromLoadedImage( CesiumGltf::ImageCesium& image = loadedImage.image.value(); - int32_t bytesPerPixel = image.channels * image.bytesPerChannel; - int64_t requiredBytes = + const int32_t bytesPerPixel = image.channels * image.bytesPerChannel; + const int64_t requiredBytes = static_cast(image.width) * image.height * bytesPerPixel; if (image.width > 0 && image.height > 0 && image.pixelData.size() >= static_cast(requiredBytes)) { diff --git a/Cesium3DTilesSelection/src/RasterizedPolygonsOverlay.cpp b/Cesium3DTilesSelection/src/RasterizedPolygonsOverlay.cpp index 748c10cd0..5c1886f57 100644 --- a/Cesium3DTilesSelection/src/RasterizedPolygonsOverlay.cpp +++ b/Cesium3DTilesSelection/src/RasterizedPolygonsOverlay.cpp @@ -58,8 +58,8 @@ void rasterizePolygons( return; } - double rectangleWidth = rectangle.computeWidth(); - double rectangleHeight = rectangle.computeHeight(); + const double rectangleWidth = rectangle.computeWidth(); + const double rectangleHeight = rectangle.computeHeight(); // create source image image.width = 256; @@ -81,39 +81,39 @@ void rasterizePolygons( const glm::dvec2& c = vertices[indices[3 * triangle + 2]]; // TODO: deal with the corner cases here - double minX = glm::min(a.x, glm::min(b.x, c.x)); - double minY = glm::min(a.y, glm::min(b.y, c.y)); - double maxX = glm::max(a.x, glm::max(b.x, c.x)); - double maxY = glm::max(a.y, glm::max(b.y, c.y)); + const double minX = glm::min(a.x, glm::min(b.x, c.x)); + const double minY = glm::min(a.y, glm::min(b.y, c.y)); + const double maxX = glm::max(a.x, glm::max(b.x, c.x)); + const double maxY = glm::max(a.y, glm::max(b.y, c.y)); - CesiumGeospatial::GlobeRectangle triangleBounds(minX, minY, maxX, maxY); + const CesiumGeospatial::GlobeRectangle triangleBounds(minX, minY, maxX, maxY); // skip this triangle if it is entirely outside the tile bounds if (!rectangle.computeIntersection(triangleBounds)) { continue; } - glm::dvec2 ab = b - a; - glm::dvec2 ab_perp(-ab.y, ab.x); - glm::dvec2 bc = c - b; - glm::dvec2 bc_perp(-bc.y, bc.x); - glm::dvec2 ca = a - c; - glm::dvec2 ca_perp(-ca.y, ca.x); + const glm::dvec2 ab = b - a; + const glm::dvec2 ab_perp(-ab.y, ab.x); + const glm::dvec2 bc = c - b; + const glm::dvec2 bc_perp(-bc.y, bc.x); + const glm::dvec2 ca = a - c; + const glm::dvec2 ca_perp(-ca.y, ca.x); for (size_t j = 0; j < 256; ++j) { - double pixelY = rectangle.getSouth() + + const double pixelY = rectangle.getSouth() + rectangleHeight * (1.0 - (double(j) + 0.5) / 256.0); for (size_t i = 0; i < 256; ++i) { - double pixelX = + const double pixelX = rectangle.getWest() + rectangleWidth * (double(i) + 0.5) / 256.0; - glm::dvec2 v(pixelX, pixelY); + const glm::dvec2 v(pixelX, pixelY); - glm::dvec2 av = v - a; - glm::dvec2 cv = v - c; + const glm::dvec2 av = v - a; + const glm::dvec2 cv = v - c; - double v_proj_ab_perp = glm::dot(av, ab_perp); - double v_proj_bc_perp = glm::dot(cv, bc_perp); - double v_proj_ca_perp = glm::dot(cv, ca_perp); + const double v_proj_ab_perp = glm::dot(av, ab_perp); + const double v_proj_bc_perp = glm::dot(cv, bc_perp); + const double v_proj_ca_perp = glm::dot(cv, ca_perp); // will determine in or out, irrespective of winding if ((v_proj_ab_perp >= 0.0 && v_proj_ca_perp >= 0.0 && @@ -161,7 +161,7 @@ class CESIUM3DTILESSELECTION_API RasterizedPolygonsTileProvider final [&polygons = this->_polygons, projection = this->getProjection(), rectangle = overlayTile.getRectangle()]() -> LoadedRasterOverlayImage { - CesiumGeospatial::GlobeRectangle tileRectangle = + const CesiumGeospatial::GlobeRectangle tileRectangle = CesiumGeospatial::unprojectRectangleSimple(projection, rectangle); LoadedRasterOverlayImage resultImage; diff --git a/Cesium3DTilesSelection/src/SkirtMeshMetadata.cpp b/Cesium3DTilesSelection/src/SkirtMeshMetadata.cpp index 85f2b3c2b..e37eb471d 100644 --- a/Cesium3DTilesSelection/src/SkirtMeshMetadata.cpp +++ b/Cesium3DTilesSelection/src/SkirtMeshMetadata.cpp @@ -26,9 +26,9 @@ SkirtMeshMetadata::parseFromGltfExtras(const JsonValue::Object& extras) { return std::nullopt; } - double noSkirtIndicesBegin = + const double noSkirtIndicesBegin = (*pNoSkirtRange)[0].getSafeNumberOrDefault(-1.0); - double noSkirtIndicesCount = + const double noSkirtIndicesCount = (*pNoSkirtRange)[1].getSafeNumberOrDefault(-1.0); if (noSkirtIndicesBegin < 0.0 || noSkirtIndicesCount < 0.0) { diff --git a/Cesium3DTilesSelection/src/Tile.cpp b/Cesium3DTilesSelection/src/Tile.cpp index 506eb0362..340657e0a 100644 --- a/Cesium3DTilesSelection/src/Tile.cpp +++ b/Cesium3DTilesSelection/src/Tile.cpp @@ -157,7 +157,7 @@ void mapRasterOverlaysToTile( // TODO: we can compute a much more precise projected rectangle by // projecting each vertex, but that would require us to have // geometry first. - Rectangle overlayRectangle = + const Rectangle overlayRectangle = projectRectangleSimple(pProvider->getProjection(), *pRectangle); IntrusivePointer pRaster = @@ -171,7 +171,7 @@ void mapRasterOverlaysToTile( const CesiumGeospatial::Projection& projection = pRaster->getOverlay().getTileProvider()->getProjection(); - int32_t projectionID = + const int32_t projectionID = getTextureCoordinatesForProjection(projections, projection); mappedTile.setTextureCoordinateID(projectionID); @@ -502,22 +502,22 @@ static void createQuadtreeSubdividedChildren(Tile& parent) { return; } - QuadtreeTileID swID( + const QuadtreeTileID swID( pParentTileID->level + 1, pParentTileID->x * 2, pParentTileID->y * 2); - QuadtreeTileID seID(swID.level, swID.x + 1, swID.y); - QuadtreeTileID nwID(swID.level, swID.x, swID.y + 1); - QuadtreeTileID neID(swID.level, swID.x + 1, swID.y + 1); + const QuadtreeTileID seID(swID.level, swID.x + 1, swID.y); + const QuadtreeTileID nwID(swID.level, swID.x, swID.y + 1); + const QuadtreeTileID neID(swID.level, swID.x + 1, swID.y + 1); - QuadtreeTilingScheme& tilingScheme = + const QuadtreeTilingScheme& tilingScheme = parent.getContext()->implicitContext.value().tilingScheme; - Projection& projection = + const Projection& projection = parent.getContext()->implicitContext.value().projection; parent.createChildTiles(4); - gsl::span children = parent.getChildren(); + const gsl::span children = parent.getChildren(); Tile& sw = children[0]; Tile& se = children[1]; Tile& nw = children[2]; @@ -528,7 +528,7 @@ static void createQuadtreeSubdividedChildren(Tile& parent) { nw.setContext(parent.getContext()); ne.setContext(parent.getContext()); - double geometricError = parent.getGeometricError() * 0.5; + const double geometricError = parent.getGeometricError() * 0.5; sw.setGeometricError(geometricError); se.setGeometricError(geometricError); nw.setGeometricError(geometricError); @@ -544,8 +544,8 @@ static void createQuadtreeSubdividedChildren(Tile& parent) { nw.setTileID(UpsampledQuadtreeNode{nwID}); ne.setTileID(UpsampledQuadtreeNode{neID}); - double minimumHeight = pRegion->getMinimumHeight(); - double maximumHeight = pRegion->getMaximumHeight(); + const double minimumHeight = pRegion->getMinimumHeight(); + const double maximumHeight = pRegion->getMaximumHeight(); sw.setBoundingVolume(BoundingRegionWithLooseFittingHeights(BoundingRegion( unprojectRectangleSimple(projection, tilingScheme.tileToRectangle(swID)), @@ -573,7 +573,7 @@ void Tile::update( if (this->getState() == LoadState::FailedTemporarily) { // Check with the TileContext to see if we should retry. if (this->_pContext->failedTileCallback) { - FailedTileAction action = this->_pContext->failedTileCallback(*this); + const FailedTileAction action = this->_pContext->failedTileCallback(*this); switch (action) { case FailedTileAction::GiveUp: this->setState(LoadState::Failed); @@ -663,21 +663,21 @@ void Tile::update( const CesiumGeometry::QuadtreeTileAvailability& availability = implicitContext.availability; - QuadtreeTileID id = std::get(this->_id); + const QuadtreeTileID id = std::get(this->_id); - QuadtreeTileID swID(id.level + 1, id.x * 2, id.y * 2); - uint32_t sw = availability.isTileAvailable(swID) ? 1 : 0; + const QuadtreeTileID swID(id.level + 1, id.x * 2, id.y * 2); + const uint32_t sw = availability.isTileAvailable(swID) ? 1 : 0; - QuadtreeTileID seID(swID.level, swID.x + 1, swID.y); - uint32_t se = availability.isTileAvailable(seID) ? 1 : 0; + const QuadtreeTileID seID(swID.level, swID.x + 1, swID.y); + const uint32_t se = availability.isTileAvailable(seID) ? 1 : 0; - QuadtreeTileID nwID(swID.level, swID.x, swID.y + 1); - uint32_t nw = availability.isTileAvailable(nwID) ? 1 : 0; + const QuadtreeTileID nwID(swID.level, swID.x, swID.y + 1); + const uint32_t nw = availability.isTileAvailable(nwID) ? 1 : 0; - QuadtreeTileID neID(swID.level, swID.x + 1, swID.y + 1); - uint32_t ne = availability.isTileAvailable(neID) ? 1 : 0; + const QuadtreeTileID neID(swID.level, swID.x + 1, swID.y + 1); + const uint32_t ne = availability.isTileAvailable(neID) ? 1 : 0; - size_t childCount = sw + se + nw + ne; + const size_t childCount = sw + se + nw + ne; if (childCount > 0) { // If any children are available, we need to create all four in order to // avoid holes. But non-available tiles will be upsampled instead of @@ -722,7 +722,7 @@ void Tile::update( i)); --i; - Rectangle projectedRectangle = + const Rectangle projectedRectangle = projectRectangleSimple(pProvider->getProjection(), *pRectangle); CesiumUtility::IntrusivePointer pTile = pProvider->getTile(projectedRectangle, this->getGeometricError()); @@ -732,7 +732,7 @@ void Tile::update( continue; } - RasterOverlayTile::MoreDetailAvailable moreDetailAvailable = + const RasterOverlayTile::MoreDetailAvailable moreDetailAvailable = mappedRasterTile.update(*this); moreRasterDetailAvailable |= moreDetailAvailable == RasterOverlayTile::MoreDetailAvailable::Yes; @@ -769,7 +769,7 @@ int64_t Tile::computeByteSize() const noexcept { // the decoded image size instead. const std::vector& bufferViews = model.bufferViews; for (const CesiumGltf::Image& image : model.images) { - int32_t bufferView = image.bufferView; + const int32_t bufferView = image.bufferView; if (bufferView < 0 || bufferView >= static_cast(bufferViews.size())) { continue; @@ -803,9 +803,9 @@ Tile::generateTextureCoordinates( for (size_t i = 0; i < projections.size(); ++i) { const Projection& projection = projections[i]; - int textureCoordinateID = static_cast(i); + const int textureCoordinateID = static_cast(i); - CesiumGeometry::Rectangle rectangle = + const CesiumGeometry::Rectangle rectangle = projectRectangleSimple(projection, *pRectangle); CesiumGeospatial::BoundingRegion boundingRegion = @@ -910,7 +910,7 @@ void Tile::loadOverlays( Tileset* pTileset = this->getTileset(); if (pTileset->supportsRasterOverlays()) { - RasterOverlayCollection& overlays = pTileset->getOverlays(); + const RasterOverlayCollection& overlays = pTileset->getOverlays(); mapRasterOverlaysToTile(*this, overlays, projections); } } diff --git a/Cesium3DTilesSelection/src/TileContentFactory.cpp b/Cesium3DTilesSelection/src/TileContentFactory.cpp index ecb542810..c10f90760 100644 --- a/Cesium3DTilesSelection/src/TileContentFactory.cpp +++ b/Cesium3DTilesSelection/src/TileContentFactory.cpp @@ -86,7 +86,7 @@ TileContentFactory::createContent(const TileContentLoadInput& input) { std::optional TileContentFactory::getMagic(const gsl::span& data) { if (data.size() >= 4) { - gsl::span magicData = data.subspan(0, 4); + const gsl::span magicData = data.subspan(0, 4); return std::string(reinterpret_cast(magicData.data()), 4); } diff --git a/Cesium3DTilesSelection/src/TileMapServiceRasterOverlay.cpp b/Cesium3DTilesSelection/src/TileMapServiceRasterOverlay.cpp index c92690ab6..bf7bf59b8 100644 --- a/Cesium3DTilesSelection/src/TileMapServiceRasterOverlay.cpp +++ b/Cesium3DTilesSelection/src/TileMapServiceRasterOverlay.cpp @@ -135,7 +135,7 @@ TileMapServiceRasterOverlay::createTileProvider( pOwner = pOwner ? pOwner : this; - std::optional credit = + const std::optional credit = this->_options.credit ? std::make_optional(pCreditSystem->createCredit( this->_options.credit.value())) : std::nullopt; @@ -161,10 +161,10 @@ TileMapServiceRasterOverlay::createTileProvider( return nullptr; } - gsl::span data = pResponse->data(); + const gsl::span data = pResponse->data(); tinyxml2::XMLDocument doc; - tinyxml2::XMLError error = doc.Parse( + const tinyxml2::XMLError error = doc.Parse( reinterpret_cast(data.data()), data.size_bytes()); if (error != tinyxml2::XMLError::XML_SUCCESS) { @@ -204,7 +204,7 @@ TileMapServiceRasterOverlay::createTileProvider( tinyxml2::XMLElement* pTileset = pTilesets->FirstChildElement("TileSet"); while (pTileset) { - uint32_t level = + const uint32_t level = getAttributeUint32(pTileset, "order").value_or(0); minimumLevel = glm::min(minimumLevel, level); maximumLevel = glm::max(maximumLevel, level); diff --git a/Cesium3DTilesSelection/src/TileUtilities.cpp b/Cesium3DTilesSelection/src/TileUtilities.cpp index a7788b0d5..8462f2421 100644 --- a/Cesium3DTilesSelection/src/TileUtilities.cpp +++ b/Cesium3DTilesSelection/src/TileUtilities.cpp @@ -78,19 +78,19 @@ bool withinPolygons( const glm::dvec2& b = vertices[indices[j - 1]]; const glm::dvec2& c = vertices[indices[j]]; - glm::dvec2 ab = b - a; - glm::dvec2 ab_perp(-ab.y, ab.x); - glm::dvec2 bc = c - b; - glm::dvec2 bc_perp(-bc.y, bc.x); - glm::dvec2 ca = a - c; - glm::dvec2 ca_perp(-ca.y, ca.x); + const glm::dvec2 ab = b - a; + const glm::dvec2 ab_perp(-ab.y, ab.x); + const glm::dvec2 bc = c - b; + const glm::dvec2 bc_perp(-bc.y, bc.x); + const glm::dvec2 ca = a - c; + const glm::dvec2 ca_perp(-ca.y, ca.x); - glm::dvec2 av = rectangleCorners[0] - a; - glm::dvec2 cv = rectangleCorners[0] - c; + const glm::dvec2 av = rectangleCorners[0] - a; + const glm::dvec2 cv = rectangleCorners[0] - c; - double v_proj_ab_perp = glm::dot(av, ab_perp); - double v_proj_bc_perp = glm::dot(cv, bc_perp); - double v_proj_ca_perp = glm::dot(cv, ca_perp); + const double v_proj_ab_perp = glm::dot(av, ab_perp); + const double v_proj_bc_perp = glm::dot(cv, bc_perp); + const double v_proj_ca_perp = glm::dot(cv, ca_perp); // This will determine in or out, irrespective of winding. if ((v_proj_ab_perp >= 0.0 && v_proj_ca_perp >= 0.0 && @@ -115,17 +115,17 @@ bool withinPolygons( const glm::dvec2& a = vertices[j]; const glm::dvec2& b = vertices[(j + 1) % vertices.size()]; - glm::dvec2 ba = a - b; + const glm::dvec2 ba = a - b; // Check each rectangle edge. for (size_t k = 0; k < 4; ++k) { const glm::dvec2& cd = rectangleEdges[k]; - glm::dmat2 lineSegmentMatrix(cd, ba); - glm::dvec2 ca = a - rectangleCorners[k]; + const glm::dmat2 lineSegmentMatrix(cd, ba); + const glm::dvec2 ca = a - rectangleCorners[k]; // s and t are calculated such that: // line_intersection = a + t * ab = c + s * cd - glm::dvec2 st = glm::inverse(lineSegmentMatrix) * ca; + const glm::dvec2 st = glm::inverse(lineSegmentMatrix) * ca; // check that the intersection is within the line segments if (st.x <= 1.0 && st.x >= 0.0 && st.y <= 1.0 && st.y >= 0.0) { diff --git a/Cesium3DTilesSelection/src/Tileset.cpp b/Cesium3DTilesSelection/src/Tileset.cpp index 419c27054..aef7f7b28 100644 --- a/Cesium3DTilesSelection/src/Tileset.cpp +++ b/Cesium3DTilesSelection/src/Tileset.cpp @@ -160,7 +160,7 @@ Tileset::_handleAssetResponse(std::shared_ptr&& pRequest) { return this->getAsyncSystem().createResolvedFuture(); } - gsl::span data = pResponse->data(); + const gsl::span data = pResponse->data(); rapidjson::Document ionResponse; ionResponse.Parse(reinterpret_cast(data.data()), data.size()); @@ -177,14 +177,14 @@ Tileset::_handleAssetResponse(std::shared_ptr&& pRequest) { if (this->_externals.pCreditSystem) { - auto attributionsIt = ionResponse.FindMember("attributions"); + const auto attributionsIt = ionResponse.FindMember("attributions"); if (attributionsIt != ionResponse.MemberEnd() && attributionsIt->value.IsArray()) { for (const rapidjson::Value& attribution : attributionsIt->value.GetArray()) { - auto html = attribution.FindMember("html"); + const auto html = attribution.FindMember("html"); if (html != attribution.MemberEnd() && html->value.IsString()) { this->_tilesetCredits.push_back( this->_externals.pCreditSystem->createCredit( @@ -239,7 +239,7 @@ operator<(const FogDensityAtHeight& fogDensity, double height) noexcept { static double computeFogDensity( const std::vector& fogDensityTable, const ViewState& viewState) { - double height = viewState.getPositionCartographic() + const double height = viewState.getPositionCartographic() .value_or(Cartographic(0.0, 0.0, 0.0)) .height; @@ -256,15 +256,15 @@ static double computeFogDensity( auto prevIt = nextIt - 1; - double heightA = prevIt->cameraHeight; - double densityA = prevIt->fogDensity; + const double heightA = prevIt->cameraHeight; + const double densityA = prevIt->fogDensity; - double heightB = nextIt->cameraHeight; - double densityB = nextIt->fogDensity; + const double heightB = nextIt->cameraHeight; + const double densityB = nextIt->fogDensity; - double t = glm::clamp((height - heightA) / (heightB - heightA), 0.0, 1.0); + const double t = glm::clamp((height - heightA) / (heightB - heightA), 0.0, 1.0); - double density = glm::mix(densityA, densityB, t); + const double density = glm::mix(densityA, densityB, t); // CesiumJS will also fade out the fog based on the camera angle, // so when we're looking straight down there's no fog. This is unfortunate @@ -310,8 +310,8 @@ const ViewUpdateResult& Tileset::updateView(const std::vector& frustums) { this->_asyncSystem.dispatchMainThreadTasks(); - int32_t previousFrameNumber = this->_previousFrameNumber; - int32_t currentFrameNumber = previousFrameNumber + 1; + const int32_t previousFrameNumber = this->_previousFrameNumber; + const int32_t currentFrameNumber = previousFrameNumber + 1; ViewUpdateResult& result = this->_updateResult; // result.tilesLoading = 0; @@ -379,7 +379,7 @@ Tileset::updateView(const std::vector& frustums) { } // per-tileset ion-specified credit - for (Credit& credit : this->_tilesetCredits) { + for (const Credit& credit : this->_tilesetCredits) { pCreditSystem->addCreditToFrame(credit); } @@ -400,7 +400,7 @@ Tileset::updateView(const std::vector& frustums) { const RasterOverlayTile* pRasterOverlayTile = mappedRasterTile.getReadyTile(); if (pRasterOverlayTile != nullptr) { - for (Credit credit : pRasterOverlayTile->getCredits()) { + for (const Credit credit : pRasterOverlayTile->getCredits()) { pCreditSystem->addCreditToFrame(credit); } } @@ -560,12 +560,12 @@ namespace { * @return The up-axis to use for glTF content */ CesiumGeometry::Axis obtainGltfUpAxis(const rapidjson::Document& tileset) { - auto assetIt = tileset.FindMember("asset"); + const auto assetIt = tileset.FindMember("asset"); if (assetIt == tileset.MemberEnd()) { return CesiumGeometry::Axis::Y; } const rapidjson::Value& assetJson = assetIt->value; - auto gltfUpAxisIt = assetJson.FindMember("gltfUpAxis"); + const auto gltfUpAxisIt = assetJson.FindMember("gltfUpAxis"); if (gltfUpAxisIt == assetJson.MemberEnd()) { return CesiumGeometry::Axis::Y; } @@ -616,7 +616,7 @@ CesiumGeometry::Axis obtainGltfUpAxis(const rapidjson::Document& tileset) { pContext->baseUrl = pRequest->url(); - gsl::span data = pResponse->data(); + const gsl::span data = pResponse->data(); rapidjson::Document tileset; tileset.Parse(reinterpret_cast(data.data()), data.size()); @@ -635,13 +635,13 @@ CesiumGeometry::Axis obtainGltfUpAxis(const rapidjson::Document& tileset) { std::unique_ptr pRootTile = std::make_unique(); pRootTile->setContext(pContext.get()); - auto rootIt = tileset.FindMember("root"); - auto formatIt = tileset.FindMember("format"); + const auto rootIt = tileset.FindMember("root"); + const auto formatIt = tileset.FindMember("format"); bool supportsRasterOverlays = false; if (rootIt != tileset.MemberEnd()) { - rapidjson::Value& rootJson = rootIt->value; + const rapidjson::Value& rootJson = rootIt->value; Tileset::_createTile( *pRootTile, rootJson, @@ -670,12 +670,12 @@ CesiumGeometry::Axis obtainGltfUpAxis(const rapidjson::Document& tileset) { static std::optional getBoundingVolumeProperty( const rapidjson::Value& tileJson, const std::string& key) { - auto bvIt = tileJson.FindMember(key.c_str()); + const auto bvIt = tileJson.FindMember(key.c_str()); if (bvIt == tileJson.MemberEnd() || !bvIt->value.IsObject()) { return std::nullopt; } - auto boxIt = bvIt->value.FindMember("box"); + const auto boxIt = bvIt->value.FindMember("box"); if (boxIt != bvIt->value.MemberEnd() && boxIt->value.IsArray() && boxIt->value.Size() >= 12) { const auto& a = boxIt->value.GetArray(); @@ -698,7 +698,7 @@ static std::optional getBoundingVolumeProperty( a[11].GetDouble())); } - auto regionIt = bvIt->value.FindMember("region"); + const auto regionIt = bvIt->value.FindMember("region"); if (regionIt != bvIt->value.MemberEnd() && regionIt->value.IsArray() && regionIt->value.Size() >= 6) { const auto& a = regionIt->value; @@ -717,7 +717,7 @@ static std::optional getBoundingVolumeProperty( a[5].GetDouble()); } - auto sphereIt = bvIt->value.FindMember("sphere"); + const auto sphereIt = bvIt->value.FindMember("sphere"); if (sphereIt != bvIt->value.MemberEnd() && sphereIt->value.IsArray() && sphereIt->value.Size() >= 4) { const auto& a = sphereIt->value; @@ -747,14 +747,14 @@ static std::optional getBoundingVolumeProperty( tile.setContext(const_cast(&context)); - std::optional tileTransform = + const std::optional tileTransform = JsonHelpers::getTransformProperty(tileJson, "transform"); glm::dmat4x4 transform = parentTransform * tileTransform.value_or(glm::dmat4x4(1.0)); tile.setTransform(transform); - auto contentIt = tileJson.FindMember("content"); - auto childrenIt = tileJson.FindMember("children"); + const auto contentIt = tileJson.FindMember("content"); + const auto childrenIt = tileJson.FindMember("children"); if (contentIt != tileJson.MemberEnd() && contentIt->value.IsObject()) { auto uriIt = contentIt->value.FindMember("uri"); @@ -790,11 +790,11 @@ static std::optional getBoundingVolumeProperty( tile.setBoundingVolume( transformBoundingVolume(transform, boundingVolume.value())); - glm::dvec3 scale = glm::dvec3( + const glm::dvec3 scale = glm::dvec3( glm::length(transform[0]), glm::length(transform[1]), glm::length(transform[2])); - double maxScaleComponent = glm::max(scale.x, glm::max(scale.y, scale.z)); + const double maxScaleComponent = glm::max(scale.x, glm::max(scale.y, scale.z)); tile.setGeometricError(geometricError.value() * maxScaleComponent); std::optional viewerRequestVolume = @@ -804,7 +804,7 @@ static std::optional getBoundingVolumeProperty( transformBoundingVolume(transform, viewerRequestVolume.value())); } - auto refineIt = tileJson.FindMember("refine"); + const auto refineIt = tileJson.FindMember("refine"); if (refineIt != tileJson.MemberEnd() && refineIt->value.IsString()) { std::string refine = refineIt->value.GetString(); if (refine == "REPLACE") { @@ -824,7 +824,7 @@ static std::optional getBoundingVolumeProperty( if (childrenIt != tileJson.MemberEnd() && childrenIt->value.IsArray()) { const auto& childrenJson = childrenIt->value; tile.createChildTiles(childrenJson.Size()); - gsl::span childTiles = tile.getChildren(); + const gsl::span childTiles = tile.getChildren(); for (rapidjson::SizeType i = 0; i < childrenJson.Size(); ++i) { const auto& childJson = childrenJson[i]; @@ -896,7 +896,7 @@ static BoundingVolume createDefaultLooseEarthBoundingVolume( "application/vnd.quantized-mesh,application/octet-stream;q=0.9,*/" "*;q=0.01")); - auto tilesetVersionIt = layerJson.FindMember("version"); + const auto tilesetVersionIt = layerJson.FindMember("version"); if (tilesetVersionIt != layerJson.MemberEnd() && tilesetVersionIt->value.IsString()) { context.version = tilesetVersionIt->value.GetString(); @@ -949,7 +949,7 @@ static BoundingVolume createDefaultLooseEarthBoundingVolume( return; } - CesiumGeometry::QuadtreeTilingScheme tilingScheme( + const CesiumGeometry::QuadtreeTilingScheme tilingScheme( quadtreeRectangleProjected, quadtreeXTiles, 1); @@ -996,7 +996,7 @@ static BoundingVolume createDefaultLooseEarthBoundingVolume( childTile.setContext(&context); childTile.setParent(&tile); childTile.setTileID(id); - CesiumGeospatial::GlobeRectangle childGlobeRectangle = + const CesiumGeospatial::GlobeRectangle childGlobeRectangle = unprojectRectangleSimple(projection, tilingScheme.tileToRectangle(id)); childTile.setBoundingVolume( createDefaultLooseEarthBoundingVolume(childGlobeRectangle)); @@ -1022,7 +1022,7 @@ static bool updateContextWithNewToken( TileContext* pContext, const IAssetResponse* pIonResponse, const std::shared_ptr& pLogger) { - gsl::span data = pIonResponse->data(); + const gsl::span data = pIonResponse->data(); rapidjson::Document ionResponse; ionResponse.Parse(reinterpret_cast(data.data()), data.size()); @@ -1148,7 +1148,7 @@ static void markTileNonRendered( int32_t lastFrameNumber, Tile& tile, ViewUpdateResult& result) { - TileSelectionState::Result lastResult = + const TileSelectionState::Result lastResult = tile.getLastSelectionState().getResult(lastFrameNumber); markTileNonRendered(lastResult, tile, result); } @@ -1160,7 +1160,7 @@ static void markChildrenNonRendered( ViewUpdateResult& result) { if (lastResult == TileSelectionState::Result::Refined) { for (Tile& child : tile.getChildren()) { - TileSelectionState::Result childLastResult = + const TileSelectionState::Result childLastResult = child.getLastSelectionState().getResult(lastFrameNumber); markTileNonRendered(childLastResult, child, result); markChildrenNonRendered(lastFrameNumber, childLastResult, child, result); @@ -1172,7 +1172,7 @@ static void markChildrenNonRendered( int32_t lastFrameNumber, Tile& tile, ViewUpdateResult& result) { - TileSelectionState::Result lastResult = + const TileSelectionState::Result lastResult = tile.getLastSelectionState().getResult(lastFrameNumber); markChildrenNonRendered(lastFrameNumber, lastResult, tile, result); } @@ -1181,7 +1181,7 @@ static void markTileAndChildrenNonRendered( int32_t lastFrameNumber, Tile& tile, ViewUpdateResult& result) { - TileSelectionState::Result lastResult = + const TileSelectionState::Result lastResult = tile.getLastSelectionState().getResult(lastFrameNumber); markTileNonRendered(lastResult, tile, result); markChildrenNonRendered(lastFrameNumber, lastResult, tile, result); @@ -1235,7 +1235,7 @@ static bool isVisibleInFog(double distance, double fogDensity) noexcept { return true; } - double fogScalar = distance * fogDensity; + const double fogScalar = distance * fogDensity; return glm::exp(-(fogScalar * fogScalar)) > 0.0; } @@ -1312,7 +1312,7 @@ Tileset::TraversalDetails Tileset::_visitTileIfNeeded( // Use a unique_ptr to ensure the _nextDistancesVector gets decrements when we // leave this scope. - auto decrementNextDistancesVector = [this](std::vector*) { + const auto decrementNextDistancesVector = [this](std::vector*) { --this->_nextDistancesVector; }; std::unique_ptr, decltype(decrementNextDistancesVector)> @@ -1333,8 +1333,8 @@ Tileset::TraversalDetails Tileset::_visitTileIfNeeded( bool isFogCulled = true; for (size_t i = 0; i < frustums.size(); ++i) { - double distance = distances[i]; - double fogDensity = fogDensities[i]; + const double distance = distances[i]; + const double fogDensity = fogDensities[i]; if (isVisibleInFog(distance, fogDensity)) { isFogCulled = false; @@ -1388,7 +1388,7 @@ Tileset::TraversalDetails Tileset::_renderLeaf( const std::vector& distances, ViewUpdateResult& result) { - TileSelectionState lastFrameSelectionState = tile.getLastSelectionState(); + const TileSelectionState lastFrameSelectionState = tile.getLastSelectionState(); tile.setLastSelectionState(TileSelectionState( frameState.currentFrameNumber, @@ -1449,10 +1449,10 @@ bool Tileset::_meetsSse( for (size_t i = 0; i < frustums.size() && i < distances.size(); ++i) { const ViewState& frustum = frustums[i]; - double distance = distances[i]; + const double distance = distances[i]; // Does this tile meet the screen-space error? - double sse = + const double sse = frustum.computeScreenSpaceError(tile.getGeometricError(), distance); if (sse > largestSse) { largestSse = sse; @@ -1477,7 +1477,7 @@ static bool shouldRenderThisTile( const Tile& tile, const TileSelectionState& lastFrameSelectionState, int32_t lastFrameNumber) noexcept { - TileSelectionState::Result originalResult = + const TileSelectionState::Result originalResult = lastFrameSelectionState.getOriginalResult(lastFrameNumber); if (originalResult == TileSelectionState::Result::Rendered) { return true; @@ -1500,7 +1500,7 @@ Tileset::TraversalDetails Tileset::_renderInnerTile( Tile& tile, ViewUpdateResult& result) { - TileSelectionState lastFrameSelectionState = tile.getLastSelectionState(); + const TileSelectionState lastFrameSelectionState = tile.getLastSelectionState(); markChildrenNonRendered(frameState.lastFrameNumber, tile, result); tile.setLastSelectionState(TileSelectionState( @@ -1525,7 +1525,7 @@ Tileset::TraversalDetails Tileset::_refineToNothing( ViewUpdateResult& result, bool areChildrenRenderable) { - TileSelectionState lastFrameSelectionState = tile.getLastSelectionState(); + const TileSelectionState lastFrameSelectionState = tile.getLastSelectionState(); // Nothing else to do except mark this tile refined and return. TraversalDetails noChildrenTraversalDetails; @@ -1579,7 +1579,7 @@ bool Tileset::_kickDescendantsAndRenderTile( size_t loadIndexHigh, bool queuedForLoad, const std::vector& distances) { - TileSelectionState lastFrameSelectionState = tile.getLastSelectionState(); + const TileSelectionState lastFrameSelectionState = tile.getLastSelectionState(); std::vector& renderList = result.tilesToRenderThisFrame; @@ -1615,10 +1615,10 @@ bool Tileset::_kickDescendantsAndRenderTile( // in that case, load this tile INSTEAD of loading any of the descendants, and // tell the up-level we're only waiting on this tile. Keep doing this until we // actually manage to render this tile. - bool wasRenderedLastFrame = + const bool wasRenderedLastFrame = lastFrameSelectionState.getResult(frameState.lastFrameNumber) == TileSelectionState::Result::Rendered; - bool wasReallyRenderedLastFrame = wasRenderedLastFrame && tile.isRenderable(); + const bool wasReallyRenderedLastFrame = wasRenderedLastFrame && tile.isRenderable(); if (!wasReallyRenderedLastFrame && traversalDetails.notYetRenderableCount > @@ -1685,8 +1685,8 @@ Tileset::TraversalDetails Tileset::_visitTile( return _renderLeaf(frameState, tile, distances, result); } - bool meetsSse = _meetsSse(frameState.frustums, tile, distances, culled); - bool waitingForChildren = + const bool meetsSse = _meetsSse(frameState.frustums, tile, distances, culled); + const bool waitingForChildren = _queueLoadOfChildrenRequiredForRefinement(frameState, tile, distances); if (meetsSse || ancestorMeetsSse || waitingForChildren) { @@ -1702,8 +1702,8 @@ Tileset::TraversalDetails Tileset::_visitTile( // // Note that even if we decide to render a tile here, it may later get // "kicked" in favor of an ancestor. - TileSelectionState lastFrameSelectionState = tile.getLastSelectionState(); - bool renderThisTile = shouldRenderThisTile( + const TileSelectionState lastFrameSelectionState = tile.getLastSelectionState(); + const bool renderThisTile = shouldRenderThisTile( tile, lastFrameSelectionState, frameState.lastFrameNumber); @@ -1746,10 +1746,10 @@ Tileset::TraversalDetails Tileset::_visitTile( bool queuedForLoad = _loadAndRenderAdditiveRefinedTile(frameState, tile, result, distances); - size_t firstRenderedDescendantIndex = result.tilesToRenderThisFrame.size(); - size_t loadIndexLow = this->_loadQueueLow.size(); - size_t loadIndexMedium = this->_loadQueueMedium.size(); - size_t loadIndexHigh = this->_loadQueueHigh.size(); + const size_t firstRenderedDescendantIndex = result.tilesToRenderThisFrame.size(); + const size_t loadIndexLow = this->_loadQueueLow.size(); + const size_t loadIndexMedium = this->_loadQueueMedium.size(); + const size_t loadIndexHigh = this->_loadQueueHigh.size(); TraversalDetails traversalDetails = this->_visitVisibleChildrenNearToFar( frameState, @@ -1758,7 +1758,7 @@ Tileset::TraversalDetails Tileset::_visitTile( tile, result); - bool descendantTilesAdded = + const bool descendantTilesAdded = firstRenderedDescendantIndex != result.tilesToRenderThisFrame.size(); if (!descendantTilesAdded) { // No descendant tiles were added to the render list by the function above, @@ -1820,7 +1820,7 @@ Tileset::TraversalDetails Tileset::_visitVisibleChildrenNearToFar( // TODO: actually visit near-to-far, rather than in order of occurrence. gsl::span children = tile.getChildren(); for (Tile& child : children) { - TraversalDetails childTraversal = this->_visitTileIfNeeded( + const TraversalDetails childTraversal = this->_visitTileIfNeeded( frameState, depth + 1, ancestorMeetsSse, @@ -1867,7 +1867,7 @@ void Tileset::_unloadCachedTiles() noexcept { Tile* pNext = this->_loadedTiles.next(*pTile); - bool removed = pTile->unloadContent(); + const bool removed = pTile->unloadContent(); if (removed) { this->_loadedTiles.remove(*pTile); } @@ -1979,20 +1979,20 @@ static bool anyRasterOverlaysNeedLoading(const Tile& tile) noexcept { if (tile.getState() == Tile::LoadState::Unloaded || anyRasterOverlaysNeedLoading(tile)) { - glm::dvec3 boundingVolumeCenter = + const glm::dvec3 boundingVolumeCenter = getBoundingVolumeCenter(tile.getBoundingVolume()); double highestLoadPriority = std::numeric_limits::max(); for (size_t i = 0; i < frustums.size() && i < distances.size(); ++i) { const ViewState& frustum = frustums[i]; - double distance = distances[i]; + const double distance = distances[i]; glm::dvec3 tileDirection = boundingVolumeCenter - frustum.getPosition(); - double magnitude = glm::length(tileDirection); + const double magnitude = glm::length(tileDirection); if (magnitude >= CesiumUtility::Math::EPSILON5) { tileDirection /= magnitude; - double loadPriority = + const double loadPriority = (1.0 - glm::dot(tileDirection, frustum.getDirection())) * distance; if (loadPriority < highestLoadPriority) { highestLoadPriority = loadPriority; diff --git a/Cesium3DTilesSelection/src/ViewState.cpp b/Cesium3DTilesSelection/src/ViewState.cpp index 7af86fc7c..d65413af9 100644 --- a/Cesium3DTilesSelection/src/ViewState.cpp +++ b/Cesium3DTilesSelection/src/ViewState.cpp @@ -54,22 +54,22 @@ template static bool isBoundingVolumeVisible( const T& boundingVolume, const CullingVolume& cullingVolume) noexcept { - CullingResult left = boundingVolume.intersectPlane(cullingVolume.leftPlane); + const CullingResult left = boundingVolume.intersectPlane(cullingVolume.leftPlane); if (left == CullingResult::Outside) { return false; } - CullingResult right = boundingVolume.intersectPlane(cullingVolume.rightPlane); + const CullingResult right = boundingVolume.intersectPlane(cullingVolume.rightPlane); if (right == CullingResult::Outside) { return false; } - CullingResult top = boundingVolume.intersectPlane(cullingVolume.topPlane); + const CullingResult top = boundingVolume.intersectPlane(cullingVolume.topPlane); if (top == CullingResult::Outside) { return false; } - CullingResult bottom = + const CullingResult bottom = boundingVolume.intersectPlane(cullingVolume.bottomPlane); if (bottom == CullingResult::Outside) { return false; @@ -157,7 +157,7 @@ double ViewState::computeScreenSpaceError( double distance) const noexcept { // Avoid divide by zero when viewer is inside the tile distance = glm::max(distance, 1e-7); - double sseDenominator = this->_sseDenominator; + const double sseDenominator = this->_sseDenominator; return (geometricError * this->_viewportSize.y) / (distance * sseDenominator); } } // namespace Cesium3DTilesSelection diff --git a/Cesium3DTilesSelection/src/upgradeBatchTableToFeatureMetadata.cpp b/Cesium3DTilesSelection/src/upgradeBatchTableToFeatureMetadata.cpp index 5cb029966..8c175433d 100644 --- a/Cesium3DTilesSelection/src/upgradeBatchTableToFeatureMetadata.cpp +++ b/Cesium3DTilesSelection/src/upgradeBatchTableToFeatureMetadata.cpp @@ -115,7 +115,7 @@ CompatibleTypes findCompatibleTypes(const rapidjson::Value& propertyValue) { type.isBool = true; type.isArray = false; } else if (it->IsInt64()) { - int64_t value = it->GetInt64(); + const int64_t value = it->GetInt64(); type.isInt8 &= isInRangeForSignedInteger(value); type.isUint8 &= isInRangeForSignedInteger(value); type.isInt16 &= isInRangeForSignedInteger(value); @@ -241,7 +241,7 @@ void updateExtensionWithJsonStringProperty( ++it; } - uint64_t totalSize = rapidjsonOffsets.back(); + const uint64_t totalSize = rapidjsonOffsets.back(); std::vector buffer; std::vector offsetBuffer; if (isInRangeForUnsignedInteger(totalSize)) { @@ -282,7 +282,7 @@ void updateExtensionWithJsonStringProperty( gltfBufferView.buffer = static_cast(gltf.buffers.size() - 1); gltfBufferView.byteOffset = 0; gltfBufferView.byteLength = static_cast(totalSize); - int32_t valueBufferViewIdx = + const int32_t valueBufferViewIdx = static_cast(gltf.bufferViews.size() - 1); Buffer& gltfOffsetBuffer = gltf.buffers.emplace_back(); @@ -294,7 +294,7 @@ void updateExtensionWithJsonStringProperty( gltfOffsetBufferView.byteOffset = 0; gltfOffsetBufferView.byteLength = static_cast(gltfOffsetBuffer.cesium.data.size()); - int32_t offsetBufferViewIdx = + const int32_t offsetBufferViewIdx = static_cast(gltf.bufferViews.size() - 1); classProperty.type = "STRING"; @@ -316,13 +316,13 @@ void updateExtensionWithJsonNumericProperty( classProperty.type = typeName; // Create a new buffer for this property. - size_t bufferIndex = gltf.buffers.size(); + const size_t bufferIndex = gltf.buffers.size(); Buffer& buffer = gltf.buffers.emplace_back(); buffer.byteLength = static_cast(sizeof(T) * static_cast(featureTable.count)); buffer.cesium.data.resize(static_cast(buffer.byteLength)); - size_t bufferViewIndex = gltf.bufferViews.size(); + const size_t bufferViewIndex = gltf.bufferViews.size(); BufferView& bufferView = gltf.bufferViews.emplace_back(); bufferView.buffer = int32_t(bufferIndex); bufferView.byteOffset = 0; @@ -353,14 +353,14 @@ void updateExtensionWithJsonBoolProperty( for (rapidjson::SizeType i = 0; i < static_cast(featureTable.count); ++i) { - bool value = jsonArray[i].GetBool(); - size_t byteIndex = i / 8; - size_t bitIndex = i % 8; + const bool value = jsonArray[i].GetBool(); + const size_t byteIndex = i / 8; + const size_t bitIndex = i % 8; data[byteIndex] = static_cast(value << bitIndex) | data[byteIndex]; } - size_t bufferIndex = gltf.buffers.size(); + const size_t bufferIndex = gltf.buffers.size(); Buffer& buffer = gltf.buffers.emplace_back(); buffer.byteLength = static_cast(data.size()); buffer.cesium.data = std::move(data); @@ -420,7 +420,7 @@ void updateNumericArrayProperty( // check if it's a fixed array if (compatibleTypes.minComponentCount == compatibleTypes.maxComponentCount) { - size_t numOfValues = static_cast(featureTable.count) * + const size_t numOfValues = static_cast(featureTable.count) * *compatibleTypes.minComponentCount; std::vector valueBuffer(sizeof(ValueType) * numOfValues); ValueType* value = reinterpret_cast(valueBuffer.data()); @@ -465,7 +465,7 @@ void updateNumericArrayProperty( PropertyType offsetType = PropertyType::None; std::vector valueBuffer; std::vector offsetBuffer; - uint64_t maxOffsetValue = numOfElements * sizeof(ValueType); + const uint64_t maxOffsetValue = numOfElements * sizeof(ValueType); if (isInRangeForUnsignedInteger(maxOffsetValue)) { copyNumericDynamicArrayBuffers( valueBuffer, @@ -509,7 +509,7 @@ void updateNumericArrayProperty( gltfValueBufferView.byteOffset = 0; gltfValueBufferView.byteLength = static_cast(gltfValueBuffer.cesium.data.size()); - int32_t valueBufferIdx = static_cast(gltf.bufferViews.size() - 1); + const int32_t valueBufferIdx = static_cast(gltf.bufferViews.size() - 1); Buffer& gltfOffsetBuffer = gltf.buffers.emplace_back(); gltfOffsetBuffer.byteLength = static_cast(offsetBuffer.size()); @@ -520,7 +520,7 @@ void updateNumericArrayProperty( gltfOffsetBufferView.byteOffset = 0; gltfOffsetBufferView.byteLength = static_cast(gltfOffsetBuffer.cesium.data.size()); - int32_t offsetBufferIdx = static_cast(gltf.bufferViews.size() - 1); + const int32_t offsetBufferIdx = static_cast(gltf.bufferViews.size() - 1); classProperty.type = "ARRAY"; classProperty.componentType = convertPropertyTypeToString( @@ -609,7 +609,7 @@ void updateStringArrayProperty( } } - uint64_t totalByteLength = totalChars * sizeof(rapidjson::Value::Ch); + const uint64_t totalByteLength = totalChars * sizeof(rapidjson::Value::Ch); std::vector valueBuffer; std::vector offsetBuffer; PropertyType offsetType = PropertyType::None; @@ -661,7 +661,7 @@ void updateStringArrayProperty( static_cast(gltf.buffers.size() - 1); gltfValueBufferView.byteOffset = 0; gltfValueBufferView.byteLength = gltfValueBuffer.byteLength; - int32_t valueBufferViewIdx = + const int32_t valueBufferViewIdx = static_cast(gltf.bufferViews.size() - 1); // create gltf string offset buffer view @@ -673,7 +673,7 @@ void updateStringArrayProperty( gltfOffsetBufferView.buffer = static_cast(gltf.buffers.size() - 1); gltfOffsetBufferView.byteOffset = 0; gltfOffsetBufferView.byteLength = gltfOffsetBuffer.byteLength; - int32_t offsetBufferViewIdx = + const int32_t offsetBufferViewIdx = static_cast(gltf.bufferViews.size() - 1); // fixed array of string @@ -730,7 +730,7 @@ void updateStringArrayProperty( static_cast(gltf.buffers.size() - 1); gltfArrayOffsetBufferView.byteOffset = 0; gltfArrayOffsetBufferView.byteLength = gltfArrayOffsetBuffer.byteLength; - int32_t arrayOffsetBufferViewIdx = + const int32_t arrayOffsetBufferViewIdx = static_cast(gltf.bufferViews.size() - 1); classProperty.type = "ARRAY"; @@ -750,7 +750,7 @@ void copyBooleanArrayBuffers( const FeatureTable& featureTable, const rapidjson::Value& propertyValue) { size_t currentIndex = 0; - size_t totalByteLength = + const size_t totalByteLength = static_cast(glm::ceil(static_cast(numOfElements) / 8.0)); valueBuffer.resize(totalByteLength); offsetBuffer.resize( @@ -766,9 +766,9 @@ void copyBooleanArrayBuffers( ++offset; prevOffset = static_cast(prevOffset + arrayMember.Size()); for (const auto& data : arrayMember.GetArray()) { - bool value = data.GetBool(); - size_t byteIndex = currentIndex / 8; - size_t bitIndex = currentIndex % 8; + const bool value = data.GetBool(); + const size_t byteIndex = currentIndex / 8; + const size_t bitIndex = currentIndex % 8; valueBuffer[byteIndex] = static_cast(value << bitIndex) | valueBuffer[byteIndex]; ++currentIndex; @@ -789,9 +789,9 @@ void updateBooleanArrayProperty( // fixed array of boolean if (compatibleTypes.minComponentCount == compatibleTypes.maxComponentCount) { - size_t numOfElements = static_cast( + const size_t numOfElements = static_cast( featureTable.count * compatibleTypes.minComponentCount.value()); - size_t totalByteLength = static_cast( + const size_t totalByteLength = static_cast( glm::ceil(static_cast(numOfElements) / 8.0)); std::vector valueBuffer(totalByteLength); size_t currentIndex = 0; @@ -800,9 +800,9 @@ void updateBooleanArrayProperty( const auto& arrayMember = jsonOuterArray[static_cast(i)]; for (const auto& data : arrayMember.GetArray()) { - bool value = data.GetBool(); - size_t byteIndex = currentIndex / 8; - size_t bitIndex = currentIndex % 8; + const bool value = data.GetBool(); + const size_t byteIndex = currentIndex / 8; + const size_t bitIndex = currentIndex % 8; valueBuffer[byteIndex] = static_cast(value << bitIndex) | valueBuffer[byteIndex]; ++currentIndex; @@ -883,7 +883,7 @@ void updateBooleanArrayProperty( gltfValueBufferView.byteOffset = 0; gltfValueBufferView.byteLength = static_cast(gltfValueBuffer.cesium.data.size()); - int32_t valueBufferIdx = static_cast(gltf.bufferViews.size() - 1); + const int32_t valueBufferIdx = static_cast(gltf.bufferViews.size() - 1); Buffer& gltfOffsetBuffer = gltf.buffers.emplace_back(); gltfOffsetBuffer.byteLength = static_cast(offsetBuffer.size()); @@ -894,7 +894,7 @@ void updateBooleanArrayProperty( gltfOffsetBufferView.byteOffset = 0; gltfOffsetBufferView.byteLength = static_cast(gltfOffsetBuffer.cesium.data.size()); - int32_t offsetBufferIdx = static_cast(gltf.bufferViews.size() - 1); + const int32_t offsetBufferIdx = static_cast(gltf.bufferViews.size() - 1); classProperty.type = "ARRAY"; classProperty.componentType = "BOOLEAN"; @@ -1032,7 +1032,7 @@ void updateExtensionWithJsonProperty( // Figure out which types we can use for this data. // Use the smallest type we can, and prefer signed to unsigned. - CompatibleTypes compatibleTypes = findCompatibleTypes(propertyValue); + const CompatibleTypes compatibleTypes = findCompatibleTypes(propertyValue); if (compatibleTypes.type.isBool) { updateExtensionWithJsonBoolProperty( gltf, @@ -1186,7 +1186,7 @@ void updateExtensionWithBinaryProperty( } // convert class property - int64_t byteOffset = byteOffsetIt->value.GetInt64(); + const int64_t byteOffset = byteOffsetIt->value.GetInt64(); const std::string& componentType = componentTypeIt->value.GetString(); const std::string& type = typeIt->value.GetString(); @@ -1219,7 +1219,7 @@ void updateExtensionWithBinaryProperty( } // convert feature table - size_t typeSize = gltfType.typeSize; + const size_t typeSize = gltfType.typeSize; auto& bufferView = gltf.bufferViews.emplace_back(); bufferView.buffer = gltfBufferIndex; bufferView.byteOffset = gltfBufferOffset; @@ -1256,7 +1256,7 @@ void upgradeBatchTableToFeatureMetadata( // If the feature table is missing the BATCH_LENGTH semantic, ignore the batch // table completely. - auto batchLengthIt = featureTableJson.FindMember("BATCH_LENGTH"); + const auto batchLengthIt = featureTableJson.FindMember("BATCH_LENGTH"); if (batchLengthIt == featureTableJson.MemberEnd() || !batchLengthIt->value.IsInt64()) { SPDLOG_LOGGER_WARN( @@ -1267,7 +1267,7 @@ void upgradeBatchTableToFeatureMetadata( return; } - int64_t batchLength = batchLengthIt->value.GetInt64(); + const int64_t batchLength = batchLengthIt->value.GetInt64(); // Add the binary part of the batch table - if any - to the glTF as a buffer. // We will reallign this buffer later on diff --git a/Cesium3DTilesSelection/src/upsampleGltfForRasterOverlays.cpp b/Cesium3DTilesSelection/src/upsampleGltfForRasterOverlays.cpp index 583baf4c6..e9a9b2e20 100644 --- a/Cesium3DTilesSelection/src/upsampleGltfForRasterOverlays.cpp +++ b/Cesium3DTilesSelection/src/upsampleGltfForRasterOverlays.cpp @@ -121,7 +121,7 @@ Model upsampleGltfForRasterOverlays( auto nameIt = result.extras.find("Cesium3DTiles_TileUrl"); if (nameIt != result.extras.end()) { std::string name = nameIt->second.getStringOrDefault(""); - std::string::size_type upsampledIndex = name.find(" upsampled"); + const std::string::size_type upsampledIndex = name.find(" upsampled"); if (upsampledIndex != std::string::npos) { name = name.substr(0, upsampledIndex); } @@ -161,7 +161,7 @@ static void copyVertexAttributes( attribute.buffer.data() + attribute.offset + attribute.stride * vertexIndex); for (int32_t i = 0; i < attribute.numberOfFloatsPerVertex; ++i) { - float value = *pInput; + const float value = *pInput; output.push_back(value); if (!skipMinMaxUpdate) { attribute.minimums[static_cast(i)] = glm::min( @@ -185,7 +185,7 @@ static void copyVertexAttributes( attribute.buffer.data() + attribute.offset + attribute.stride * vertex.second); for (int32_t i = 0; i < attribute.numberOfFloatsPerVertex; ++i) { - float value = glm::mix(*pInput0, *pInput1, vertex.t); + const float value = glm::mix(*pInput0, *pInput1, vertex.t); output.push_back(value); if (!skipMinMaxUpdate) { attribute.minimums[static_cast(i)] = glm::min( @@ -368,16 +368,16 @@ static void upsamplePrimitiveForRasterOverlays( std::vector attributes; attributes.reserve(primitive.attributes.size()); - size_t vertexBufferIndex = model.buffers.size(); + const size_t vertexBufferIndex = model.buffers.size(); model.buffers.emplace_back(); - size_t indexBufferIndex = model.buffers.size(); + const size_t indexBufferIndex = model.buffers.size(); model.buffers.emplace_back(); - size_t vertexBufferViewIndex = model.bufferViews.size(); + const size_t vertexBufferViewIndex = model.bufferViews.size(); model.bufferViews.emplace_back(); - size_t indexBufferViewIndex = model.bufferViews.size(); + const size_t indexBufferViewIndex = model.bufferViews.size(); model.bufferViews.emplace_back(); BufferView& vertexBufferView = model.bufferViews[vertexBufferViewIndex]; @@ -431,8 +431,8 @@ static void upsamplePrimitiveForRasterOverlays( const Buffer& buffer = parentModel.buffers[static_cast(bufferView.buffer)]; - int64_t accessorByteStride = accessor.computeByteStride(parentModel); - int64_t accessorComponentElements = accessor.computeNumberOfComponents(); + const int64_t accessorByteStride = accessor.computeByteStride(parentModel); + const int64_t accessorComponentElements = accessor.computeNumberOfComponents(); if (accessor.componentType != Accessor::ComponentType::FLOAT) { // Can only interpolate floating point vertex attributes return; @@ -474,15 +474,15 @@ static void upsamplePrimitiveForRasterOverlays( return; } - for (std::string& attribute : toRemove) { + for (const std::string& attribute : toRemove) { primitive.attributes.erase(attribute); } - bool keepAboveU = !isWestChild(childID); - bool keepAboveV = !isSouthChild(childID); + const bool keepAboveU = !isWestChild(childID); + const bool keepAboveV = !isSouthChild(childID); - AccessorView uvView(parentModel, uvAccessorIndex); - AccessorView indicesView(parentModel, primitive.indices); + const AccessorView uvView(parentModel, uvAccessorIndex); + const AccessorView indicesView(parentModel, primitive.indices); if (uvView.status() != AccessorViewStatus::Valid || indicesView.status() != AccessorViewStatus::Valid) { @@ -494,7 +494,7 @@ static void upsamplePrimitiveForRasterOverlays( int64_t indicesCount = indicesView.size(); std::optional parentSkirtMeshMetadata = SkirtMeshMetadata::parseFromGltfExtras(primitive.extras); - bool hasSkirt = (parentSkirtMeshMetadata != std::nullopt) && + const bool hasSkirt = (parentSkirtMeshMetadata != std::nullopt) && (positionAttributeIndex != -1); if (hasSkirt) { indicesBegin = parentSkirtMeshMetadata->noSkirtIndicesBegin; @@ -523,9 +523,9 @@ static void upsamplePrimitiveForRasterOverlays( TIndex i1 = indicesView[i + 1]; TIndex i2 = indicesView[i + 2]; - glm::vec2 uv0 = uvView[i0]; - glm::vec2 uv1 = uvView[i1]; - glm::vec2 uv2 = uvView[i2]; + const glm::vec2 uv0 = uvView[i0]; + const glm::vec2 uv1 = uvView[i1]; + const glm::vec2 uv2 = uvView[i2]; // Clip this triangle against the East-West boundary clippedA.clear(); @@ -642,7 +642,7 @@ static void upsamplePrimitiveForRasterOverlays( } // Update the accessor vertex counts and min/max values - int64_t numberOfVertices = int64_t(newVertexFloats.size()) / vertexSizeFloats; + const int64_t numberOfVertices = int64_t(newVertexFloats.size()) / vertexSizeFloats; for (const FloatVertexAttribute& attribute : attributes) { Accessor& accessor = model.accessors[static_cast(attribute.accessorIndex)]; @@ -652,7 +652,7 @@ static void upsamplePrimitiveForRasterOverlays( } // Add an accessor for the indices - size_t indexAccessorIndex = model.accessors.size(); + const size_t indexAccessorIndex = model.accessors.size(); model.accessors.emplace_back(); Accessor& newIndicesAccessor = model.accessors.back(); newIndicesAccessor.bufferView = static_cast(indexBufferViewIndex); @@ -756,13 +756,13 @@ static uint32_t getOrCreateVertex( complements[static_cast(~(*pIndex))]); } - uint32_t existingIndex = vertexMap[static_cast(*pIndex)]; + const uint32_t existingIndex = vertexMap[static_cast(*pIndex)]; if (existingIndex != std::numeric_limits::max()) { return existingIndex; } } - uint32_t beforeOutput = static_cast(output.size()); + const uint32_t beforeOutput = static_cast(output.size()); copyVertexAttributes(attributes, complements, clipVertex, output); uint32_t newIndex = beforeOutput / (static_cast(output.size()) - beforeOutput); @@ -786,19 +786,19 @@ static void addClippedPolygon( return; } - uint32_t i0 = getOrCreateVertex( + const uint32_t i0 = getOrCreateVertex( output, attributes, vertexMap, complements, clipResult[0]); - uint32_t i1 = getOrCreateVertex( + const uint32_t i1 = getOrCreateVertex( output, attributes, vertexMap, complements, clipResult[1]); - uint32_t i2 = getOrCreateVertex( + const uint32_t i2 = getOrCreateVertex( output, attributes, vertexMap, @@ -814,7 +814,7 @@ static void addClippedPolygon( clipVertexToIndices.push_back(i2); if (clipResult.size() > 3) { - uint32_t i3 = getOrCreateVertex( + const uint32_t i3 = getOrCreateVertex( output, attributes, vertexMap, @@ -840,7 +840,7 @@ static void addEdge( const std::vector& complements, const std::vector& clipResult) { for (uint32_t i = 0; i < clipVertexToIndices.size(); ++i) { - glm::vec2 uv = getVertexValue(uvs, complements, clipResult[i]); + const glm::vec2 uv = getVertexValue(uvs, complements, clipResult[i]); if (CesiumUtility::Math::equalsEpsilon( uv.x, @@ -908,11 +908,11 @@ static void addSkirt( uint32_t newEdgeIndex = uint32_t(output.size() / size_t(vertexSizeFloats)); for (size_t i = 0; i < edgeIndices.size(); ++i) { - uint32_t edgeIdx = edgeIndices[i]; + const uint32_t edgeIdx = edgeIndices[i]; uint32_t offset = 0; for (size_t j = 0; j < attributes.size(); ++j) { FloatVertexAttribute& attribute = attributes[j]; - uint32_t valueIndex = offset + uint32_t(vertexSizeFloats) * edgeIdx; + const uint32_t valueIndex = offset + uint32_t(vertexSizeFloats) * edgeIdx; if (int32_t(j) == positionAttributeIndex) { glm::dvec3 position{ @@ -952,7 +952,7 @@ static void addSkirt( } if (i < edgeIndices.size() - 1) { - uint32_t nextEdgeIdx = edgeIndices[i + 1]; + const uint32_t nextEdgeIdx = edgeIndices[i + 1]; indices.push_back(edgeIdx); indices.push_back(nextEdgeIdx); indices.push_back(newEdgeIndex); @@ -978,7 +978,7 @@ static void addSkirts( int32_t positionAttributeIndex) { CESIUM_TRACE("addSkirts"); - glm::dvec3 center = currentSkirt.meshCenter; + const glm::dvec3 center = currentSkirt.meshCenter; double shortestSkirtHeight = glm::min(parentSkirt.skirtWestHeight, parentSkirt.skirtEastHeight); shortestSkirtHeight = diff --git a/CesiumAsync/src/CachingAssetAccessor.cpp b/CesiumAsync/src/CachingAssetAccessor.cpp index 14e736460..78457cfc1 100644 --- a/CesiumAsync/src/CachingAssetAccessor.cpp +++ b/CesiumAsync/src/CachingAssetAccessor.cpp @@ -105,7 +105,7 @@ Future> CachingAssetAccessor::requestAsset( const AsyncSystem& asyncSystem, const std::string& url, const std::vector& headers) { - int32_t requestSinceLastPrune = ++this->_requestSinceLastPrune; + const int32_t requestSinceLastPrune = ++this->_requestSinceLastPrune; if (requestSinceLastPrune == this->_requestsPerCachePrune) { // More requests may have started and incremented _requestSinceLastPrune // beyond _requestsPerCachePrune before this next line. That's ok. @@ -119,7 +119,7 @@ Future> CachingAssetAccessor::requestAsset( CESIUM_TRACE_BEGIN_IN_TRACK("requestAsset (cached)"); - ThreadPool& threadPool = this->_cacheThreadPool; + const ThreadPool& threadPool = this->_cacheThreadPool; return asyncSystem .runInThreadPool( @@ -146,7 +146,7 @@ Future> CachingAssetAccessor::requestAsset( return std::move(pCompletedRequest); } - std::optional cacheControl = + const std::optional cacheControl = ResponseCacheControl::parseFromResponseHeaders( pResponse->headers()); @@ -212,7 +212,7 @@ Future> CachingAssetAccessor::requestAsset( const IAssetResponse* pResponseToStore = pRequestToStore->response(); - std::optional cacheControl = + const std::optional cacheControl = ResponseCacheControl::parseFromResponseHeaders( pResponseToStore->headers()); @@ -273,7 +273,7 @@ bool shouldRevalidateCache(const CacheItem& cacheItem) { } bool isCacheStale(const CacheItem& cacheItem) noexcept { - std::time_t currentTime = std::time(nullptr); + const std::time_t currentTime = std::time(nullptr); return std::difftime(cacheItem.expiryTime, currentTime) < 0.0; } @@ -292,7 +292,7 @@ bool shouldCacheRequest( } // check if response status code is cacheable - uint16_t statusCode = pResponse->statusCode(); + const uint16_t statusCode = pResponse->statusCode(); if (statusCode != 200 && // status OK statusCode != 201 && // status Created statusCode != 202 && // status Accepted diff --git a/CesiumAsync/src/InternalTimegm.cpp b/CesiumAsync/src/InternalTimegm.cpp index 4e356d8c8..9b39116c3 100644 --- a/CesiumAsync/src/InternalTimegm.cpp +++ b/CesiumAsync/src/InternalTimegm.cpp @@ -22,17 +22,17 @@ time_t internalTimegm(std::tm const* t) { year += month / 12; month %= 12; } else if (month < 0) { - int years_diff = (-month + 11) / 12; + const int years_diff = (-month + 11) / 12; year -= years_diff; month += 12 * years_diff; } month++; - int day = t->tm_mday; - int day_of_year = daysFrom1jan(year, month, day); - int days_since_epoch = daysFrom1970(year) + day_of_year; + const int day = t->tm_mday; + const int day_of_year = daysFrom1jan(year, month, day); + const int days_since_epoch = daysFrom1970(year) + day_of_year; - time_t seconds_in_day = 3600 * 24; - time_t result = seconds_in_day * days_since_epoch + 3600 * t->tm_hour + + const time_t seconds_in_day = 3600 * 24; + const time_t result = seconds_in_day * days_since_epoch + 3600 * t->tm_hour + 60 * t->tm_min + t->tm_sec; return result; @@ -66,4 +66,4 @@ int32_t daysFrom1jan(int32_t year, int32_t month, int32_t day) { return days[isLeap(year)][month - 1] + day - 1; } -} // namespace CesiumAsync \ No newline at end of file +} // namespace CesiumAsync diff --git a/CesiumAsync/src/ResponseCacheControl.cpp b/CesiumAsync/src/ResponseCacheControl.cpp index b62454115..053d728f7 100644 --- a/CesiumAsync/src/ResponseCacheControl.cpp +++ b/CesiumAsync/src/ResponseCacheControl.cpp @@ -41,7 +41,7 @@ ResponseCacheControl::parseFromResponseHeaders(const HttpHeaders& headers) { size_t next = 0; while ((next = headerValue.find(',', last)) != std::string::npos) { std::string directive = trimSpace(headerValue.substr(last, next - last)); - size_t equalSize = directive.find('='); + const size_t equalSize = directive.find('='); if (equalSize != std::string::npos) { parameterizedDirectives.insert( {trimSpace(directive.substr(0, equalSize)), @@ -54,7 +54,7 @@ ResponseCacheControl::parseFromResponseHeaders(const HttpHeaders& headers) { } std::string directive = trimSpace(headerValue.substr(last)); - size_t equalSize = directive.find('='); + const size_t equalSize = directive.find('='); if (equalSize != std::string::npos) { parameterizedDirectives.insert( {trimSpace(directive.substr(0, equalSize)), @@ -115,4 +115,4 @@ std::string trimSpace(const std::string& str) { return str.substr(begin, end - begin + 1); } -} // namespace CesiumAsync \ No newline at end of file +} // namespace CesiumAsync diff --git a/CesiumAsync/src/SqliteCache.cpp b/CesiumAsync/src/SqliteCache.cpp index 5b0887717..d46d2928f 100644 --- a/CesiumAsync/src/SqliteCache.cpp +++ b/CesiumAsync/src/SqliteCache.cpp @@ -141,7 +141,7 @@ SqliteStatementPtr prepareStatement( const SqliteConnectionPtr& pConnection, const std::string& sql) { CESIUM_SQLITE(sqlite3_stmt*) pStmt; - int status = CESIUM_SQLITE(sqlite3_prepare_v2)( + const int status = CESIUM_SQLITE(sqlite3_prepare_v2)( pConnection.get(), sql.c_str(), int(sql.size()), @@ -340,11 +340,11 @@ std::optional SqliteCache::getEntry(const std::string& key) const { } // Cache hit - unpack and return it. - int64_t itemIndex = CESIUM_SQLITE( + const int64_t itemIndex = CESIUM_SQLITE( sqlite3_column_int64)(this->_pImpl->_getEntryStmtWrapper.get(), 0); // parse cache item metadata - std::time_t expiryTime = CESIUM_SQLITE( + const std::time_t expiryTime = CESIUM_SQLITE( sqlite3_column_int64)(this->_pImpl->_getEntryStmtWrapper.get(), 1); // parse response cache @@ -354,13 +354,13 @@ std::optional SqliteCache::getEntry(const std::string& key) const { HttpHeaders responseHeaders = convertStringToHeaders(serializedResponseHeaders); - uint16_t statusCode = static_cast(CESIUM_SQLITE( + const uint16_t statusCode = static_cast(CESIUM_SQLITE( sqlite3_column_int)(this->_pImpl->_getEntryStmtWrapper.get(), 3)); const std::byte* rawResponseData = reinterpret_cast(CESIUM_SQLITE( sqlite3_column_blob)(this->_pImpl->_getEntryStmtWrapper.get(), 4)); - int responseDataSize = CESIUM_SQLITE( + const int responseDataSize = CESIUM_SQLITE( sqlite3_column_bytes)(this->_pImpl->_getEntryStmtWrapper.get(), 4); std::vector responseData( rawResponseData, @@ -666,7 +666,7 @@ bool SqliteCache::prune() { } // check if we should delete more - int deletedRows = + const int deletedRows = CESIUM_SQLITE(sqlite3_changes)(this->_pImpl->_pConnection.get()); if (totalItems - deletedRows < static_cast(this->_pImpl->_maxItems)) { return true; diff --git a/CesiumGeometry/src/BoundingSphere.cpp b/CesiumGeometry/src/BoundingSphere.cpp index 6344b2218..1da91438b 100644 --- a/CesiumGeometry/src/BoundingSphere.cpp +++ b/CesiumGeometry/src/BoundingSphere.cpp @@ -6,10 +6,10 @@ namespace CesiumGeometry { CullingResult BoundingSphere::intersectPlane(const Plane& plane) const noexcept { - double distanceToPlane = + const double distanceToPlane = glm::dot(plane.getNormal(), this->_center) + plane.getDistance(); - double radius = this->_radius; + const double radius = this->_radius; if (distanceToPlane < -radius) { // The center point is negative side of the plane normal return CullingResult::Outside; @@ -24,7 +24,7 @@ BoundingSphere::intersectPlane(const Plane& plane) const noexcept { double BoundingSphere::computeDistanceSquaredToPosition( const glm::dvec3& position) const noexcept { - glm::dvec3 diff = position - this->_center; + const glm::dvec3 diff = position - this->_center; return glm::dot(diff, diff) - this->_radius * this->_radius; } diff --git a/CesiumGeometry/src/CullingVolume.cpp b/CesiumGeometry/src/CullingVolume.cpp index 27fc569c5..b6d1c782a 100644 --- a/CesiumGeometry/src/CullingVolume.cpp +++ b/CesiumGeometry/src/CullingVolume.cpp @@ -12,17 +12,17 @@ CullingVolume createCullingVolume( const glm::dvec3& up, const double fovx, const double fovy) noexcept { - double t = glm::tan(0.5 * fovy); - double b = -t; - double r = glm::tan(0.5 * fovx); - double l = -r; + const double t = glm::tan(0.5 * fovy); + const double b = -t; + const double r = glm::tan(0.5 * fovx); + const double l = -r; - double n = 1.0; + const double n = 1.0; // TODO: this is all ported directly from CesiumJS, can probably be refactored // to be more efficient with GLM. - glm::dvec3 right = glm::cross(direction, up); + const glm::dvec3 right = glm::cross(direction, up); glm::dvec3 nearCenter = direction * n; nearCenter = position + nearCenter; @@ -35,7 +35,7 @@ CullingVolume createCullingVolume( normal = glm::cross(normal, up); normal = glm::normalize(normal); - CesiumGeometry::Plane leftPlane(normal, -glm::dot(normal, position)); + const CesiumGeometry::Plane leftPlane(normal, -glm::dot(normal, position)); // Right plane computation normal = right * r; @@ -44,7 +44,7 @@ CullingVolume createCullingVolume( normal = glm::cross(up, normal); normal = glm::normalize(normal); - CesiumGeometry::Plane rightPlane(normal, -glm::dot(normal, position)); + const CesiumGeometry::Plane rightPlane(normal, -glm::dot(normal, position)); // Bottom plane computation normal = up * b; @@ -53,7 +53,7 @@ CullingVolume createCullingVolume( normal = glm::cross(right, normal); normal = glm::normalize(normal); - CesiumGeometry::Plane bottomPlane(normal, -glm::dot(normal, position)); + const CesiumGeometry::Plane bottomPlane(normal, -glm::dot(normal, position)); // Top plane computation normal = up * t; @@ -62,7 +62,7 @@ CullingVolume createCullingVolume( normal = glm::cross(normal, right); normal = glm::normalize(normal); - CesiumGeometry::Plane topPlane(normal, -glm::dot(normal, position)); + const CesiumGeometry::Plane topPlane(normal, -glm::dot(normal, position)); return {leftPlane, rightPlane, topPlane, bottomPlane}; } diff --git a/CesiumGeometry/src/IntersectionTests.cpp b/CesiumGeometry/src/IntersectionTests.cpp index fac066b93..ce438f738 100644 --- a/CesiumGeometry/src/IntersectionTests.cpp +++ b/CesiumGeometry/src/IntersectionTests.cpp @@ -10,14 +10,14 @@ namespace CesiumGeometry { /*static*/ std::optional IntersectionTests::rayPlane(const Ray& ray, const Plane& plane) noexcept { - double denominator = glm::dot(plane.getNormal(), ray.getDirection()); + const double denominator = glm::dot(plane.getNormal(), ray.getDirection()); if (glm::abs(denominator) < Math::EPSILON15) { // Ray is parallel to plane. The ray may be in the polygon's plane. return std::optional(); } - double t = + const double t = (-plane.getDistance() - glm::dot(plane.getNormal(), ray.getOrigin())) / denominator; diff --git a/CesiumGeometry/src/OrientedBoundingBox.cpp b/CesiumGeometry/src/OrientedBoundingBox.cpp index 18ce5958c..85da1cd64 100644 --- a/CesiumGeometry/src/OrientedBoundingBox.cpp +++ b/CesiumGeometry/src/OrientedBoundingBox.cpp @@ -8,7 +8,7 @@ namespace CesiumGeometry { CullingResult OrientedBoundingBox::intersectPlane(const Plane& plane) const noexcept { - glm::dvec3 normal = plane.getNormal(); + const glm::dvec3 normal = plane.getNormal(); const glm::dmat3& halfAxes = this->getHalfAxes(); const glm::dvec3& xAxisDirectionAndHalfLength = halfAxes[0]; @@ -17,7 +17,7 @@ OrientedBoundingBox::intersectPlane(const Plane& plane) const noexcept { // plane is used as if it is its normal; the first three components are // assumed to be normalized - double radEffective = glm::abs( + const double radEffective = glm::abs( normal.x * xAxisDirectionAndHalfLength.x + normal.y * xAxisDirectionAndHalfLength.y + normal.z * xAxisDirectionAndHalfLength.z) + @@ -30,7 +30,7 @@ OrientedBoundingBox::intersectPlane(const Plane& plane) const noexcept { normal.y * zAxisDirectionAndHalfLength.y + normal.z * zAxisDirectionAndHalfLength.z); - double distanceToPlane = + const double distanceToPlane = ::glm::dot(normal, this->getCenter()) + plane.getDistance(); if (distanceToPlane <= -radEffective) { @@ -46,22 +46,22 @@ OrientedBoundingBox::intersectPlane(const Plane& plane) const noexcept { double OrientedBoundingBox::computeDistanceSquaredToPosition( const glm::dvec3& position) const noexcept { - glm::dvec3 offset = position - this->getCenter(); + const glm::dvec3 offset = position - this->getCenter(); const glm::dmat3& halfAxes = this->getHalfAxes(); glm::dvec3 u = halfAxes[0]; glm::dvec3 v = halfAxes[1]; glm::dvec3 w = halfAxes[2]; - double uHalf = glm::length(u); - double vHalf = glm::length(v); - double wHalf = glm::length(w); + const double uHalf = glm::length(u); + const double vHalf = glm::length(v); + const double wHalf = glm::length(w); u /= uHalf; v /= vHalf; w /= wHalf; - glm::dvec3 pPrime( + const glm::dvec3 pPrime( glm::dot(offset, u), glm::dot(offset, v), glm::dot(offset, w)); diff --git a/CesiumGeometry/src/Plane.cpp b/CesiumGeometry/src/Plane.cpp index cb131785d..ce3cf460a 100644 --- a/CesiumGeometry/src/Plane.cpp +++ b/CesiumGeometry/src/Plane.cpp @@ -26,8 +26,8 @@ double Plane::getPointDistance(const glm::dvec3& point) const noexcept { glm::dvec3 Plane::projectPointOntoPlane(const glm::dvec3& point) const noexcept { // projectedPoint = point - (normal.point + scale) * normal - double pointDistance = this->getPointDistance(point); - glm::dvec3 scaledNormal = this->_normal * pointDistance; + const double pointDistance = this->getPointDistance(point); + const glm::dvec3 scaledNormal = this->_normal * pointDistance; return point - scaledNormal; } diff --git a/CesiumGeometry/src/QuadtreeTileAvailability.cpp b/CesiumGeometry/src/QuadtreeTileAvailability.cpp index ab1c6e0f5..7ad61ec61 100644 --- a/CesiumGeometry/src/QuadtreeTileAvailability.cpp +++ b/CesiumGeometry/src/QuadtreeTileAvailability.cpp @@ -13,7 +13,7 @@ QuadtreeTileAvailability::QuadtreeTileAvailability( this->_tilingScheme.getRootTilesX() * this->_tilingScheme.getRootTilesY()) { for (uint32_t j = 0; j < this->_tilingScheme.getRootTilesY(); ++j) { - uint32_t rowStart = j * this->_tilingScheme.getRootTilesX(); + const uint32_t rowStart = j * this->_tilingScheme.getRootTilesX(); for (uint32_t i = 0; i < this->_tilingScheme.getRootTilesX(); ++i) { QuadtreeTileID id(0, i, j); Rectangle extent = tilingScheme.tileToRectangle(id); @@ -25,16 +25,16 @@ QuadtreeTileAvailability::QuadtreeTileAvailability( void QuadtreeTileAvailability::addAvailableTileRange( const QuadtreeTileRectangularRange& range) noexcept { - Rectangle ll = this->_tilingScheme.tileToRectangle( + const Rectangle ll = this->_tilingScheme.tileToRectangle( QuadtreeTileID(range.level, range.minimumX, range.minimumY)); - Rectangle ur = this->_tilingScheme.tileToRectangle( + const Rectangle ur = this->_tilingScheme.tileToRectangle( QuadtreeTileID(range.level, range.maximumX, range.maximumY)); RectangleWithLevel rectangleWithLevel{ range.level, Rectangle(ll.minimumX, ll.minimumY, ur.maximumX, ur.maximumY)}; - for (std::unique_ptr& pNode : this->_rootNodes) { + for (const std::unique_ptr& pNode : this->_rootNodes) { if (pNode->extent.overlaps(rectangleWithLevel.rectangle)) { putRectangleInQuadtree( this->_tilingScheme, @@ -65,8 +65,8 @@ bool QuadtreeTileAvailability::isTileAvailable( // level n exists, then all its parent tiles back to level 0 exist too. This // isn't really enforced anywhere, but Cesium would never load a tile for // which this is not true. - CesiumGeometry::Rectangle rectangle = this->_tilingScheme.tileToRectangle(id); - glm::dvec2 center = rectangle.getCenter(); + const CesiumGeometry::Rectangle rectangle = this->_tilingScheme.tileToRectangle(id); + const glm::dvec2 center = rectangle.getCenter(); return this->computeMaximumLevelAtPosition(center) >= id.level; } @@ -123,10 +123,10 @@ bool QuadtreeTileAvailability::isTileAvailable( // Find the deepest quadtree node containing this point. bool found = false; while (!found) { - uint32_t ll = pNode->ll && pNode->ll->extent.contains(position) ? 1 : 0; - uint32_t lr = pNode->lr && pNode->lr->extent.contains(position) ? 1 : 0; - uint32_t ul = pNode->ul && pNode->ul->extent.contains(position) ? 1 : 0; - uint32_t ur = pNode->ur && pNode->ur->extent.contains(position) ? 1 : 0; + const uint32_t ll = pNode->ll && pNode->ll->extent.contains(position) ? 1 : 0; + const uint32_t lr = pNode->lr && pNode->lr->extent.contains(position) ? 1 : 0; + const uint32_t ul = pNode->ul && pNode->ul->extent.contains(position) ? 1 : 0; + const uint32_t ur = pNode->ur && pNode->ur->extent.contains(position) ? 1 : 0; // The common scenario is that the point is in only one quadrant and we can // simply iterate down the tree. But if the point is on a boundary between diff --git a/CesiumGeometry/src/QuadtreeTileID.cpp b/CesiumGeometry/src/QuadtreeTileID.cpp index f4aea65a1..908b86879 100644 --- a/CesiumGeometry/src/QuadtreeTileID.cpp +++ b/CesiumGeometry/src/QuadtreeTileID.cpp @@ -4,7 +4,7 @@ namespace CesiumGeometry { uint32_t QuadtreeTileID::computeInvertedY( const QuadtreeTilingScheme& tilingScheme) const noexcept { - uint32_t yTiles = tilingScheme.getNumberOfYTilesAtLevel(this->level); + const uint32_t yTiles = tilingScheme.getNumberOfYTilesAtLevel(this->level); return yTiles - this->y - 1; } diff --git a/CesiumGeometry/src/QuadtreeTilingScheme.cpp b/CesiumGeometry/src/QuadtreeTilingScheme.cpp index e1d99c826..e4a465ec1 100644 --- a/CesiumGeometry/src/QuadtreeTilingScheme.cpp +++ b/CesiumGeometry/src/QuadtreeTilingScheme.cpp @@ -26,16 +26,16 @@ QuadtreeTilingScheme::positionToTile(const glm::dvec2& position, uint32_t level) return std::nullopt; } - uint32_t xTiles = this->getNumberOfXTilesAtLevel(level); - uint32_t yTiles = this->getNumberOfYTilesAtLevel(level); + const uint32_t xTiles = this->getNumberOfXTilesAtLevel(level); + const uint32_t yTiles = this->getNumberOfYTilesAtLevel(level); - double overallWidth = this->getRectangle().computeWidth(); - double xTileWidth = overallWidth / xTiles; - double overallHeight = this->getRectangle().computeHeight(); - double yTileHeight = overallHeight / yTiles; + const double overallWidth = this->getRectangle().computeWidth(); + const double xTileWidth = overallWidth / xTiles; + const double overallHeight = this->getRectangle().computeHeight(); + const double yTileHeight = overallHeight / yTiles; - double distanceFromWest = position.x - this->getRectangle().minimumX; - double distanceFromSouth = position.y - this->getRectangle().minimumY; + const double distanceFromWest = position.x - this->getRectangle().minimumX; + const double distanceFromSouth = position.y - this->getRectangle().minimumY; uint32_t xTileCoordinate = static_cast(distanceFromWest / xTileWidth); @@ -56,16 +56,16 @@ QuadtreeTilingScheme::positionToTile(const glm::dvec2& position, uint32_t level) CesiumGeometry::Rectangle QuadtreeTilingScheme::tileToRectangle( const CesiumGeometry::QuadtreeTileID& tileID) const noexcept { - uint32_t xTiles = this->getNumberOfXTilesAtLevel(tileID.level); - uint32_t yTiles = this->getNumberOfYTilesAtLevel(tileID.level); + const uint32_t xTiles = this->getNumberOfXTilesAtLevel(tileID.level); + const uint32_t yTiles = this->getNumberOfYTilesAtLevel(tileID.level); - double xTileWidth = this->_rectangle.computeWidth() / xTiles; - double left = this->_rectangle.minimumX + tileID.x * xTileWidth; - double right = this->_rectangle.minimumX + (tileID.x + 1) * xTileWidth; + const double xTileWidth = this->_rectangle.computeWidth() / xTiles; + const double left = this->_rectangle.minimumX + tileID.x * xTileWidth; + const double right = this->_rectangle.minimumX + (tileID.x + 1) * xTileWidth; - double yTileHeight = this->_rectangle.computeHeight() / yTiles; - double bottom = this->_rectangle.minimumY + tileID.y * yTileHeight; - double top = this->_rectangle.minimumY + (tileID.y + 1) * yTileHeight; + const double yTileHeight = this->_rectangle.computeHeight() / yTiles; + const double bottom = this->_rectangle.minimumY + tileID.y * yTileHeight; + const double top = this->_rectangle.minimumY + (tileID.y + 1) * yTileHeight; return Rectangle(left, bottom, right, top); } diff --git a/CesiumGeometry/src/Rectangle.cpp b/CesiumGeometry/src/Rectangle.cpp index 7de88051a..079cef6a0 100644 --- a/CesiumGeometry/src/Rectangle.cpp +++ b/CesiumGeometry/src/Rectangle.cpp @@ -10,10 +10,10 @@ bool Rectangle::contains(const glm::dvec2& position) const noexcept { } bool Rectangle::overlaps(const Rectangle& other) const noexcept { - double left = glm::max(this->minimumX, other.minimumX); - double bottom = glm::max(this->minimumY, other.minimumY); - double right = glm::min(this->maximumX, other.maximumX); - double top = glm::min(this->maximumY, other.maximumY); + const double left = glm::max(this->minimumX, other.minimumX); + const double bottom = glm::max(this->minimumY, other.minimumY); + const double right = glm::min(this->maximumX, other.maximumX); + const double top = glm::min(this->maximumY, other.maximumY); return bottom < top && left < right; } @@ -25,9 +25,9 @@ bool Rectangle::fullyContains(const Rectangle& other) const noexcept { double Rectangle::computeSignedDistance(const glm::dvec2& position) const noexcept { - glm::dvec2 bottomLeftDistance = glm::dvec2(minimumX, minimumY) - position; - glm::dvec2 topRightDistance = position - glm::dvec2(maximumX, maximumY); - glm::dvec2 maxDistance = glm::max(bottomLeftDistance, topRightDistance); + const glm::dvec2 bottomLeftDistance = glm::dvec2(minimumX, minimumY) - position; + const glm::dvec2 topRightDistance = position - glm::dvec2(maximumX, maximumY); + const glm::dvec2 maxDistance = glm::max(bottomLeftDistance, topRightDistance); if (maxDistance.x <= 0.0 && maxDistance.y <= 0.0) { // Inside, report closest edge. @@ -43,10 +43,10 @@ Rectangle::computeSignedDistance(const glm::dvec2& position) const noexcept { std::optional Rectangle::computeIntersection(const Rectangle& other) const noexcept { - double left = glm::max(this->minimumX, other.minimumX); - double bottom = glm::max(this->minimumY, other.minimumY); - double right = glm::min(this->maximumX, other.maximumX); - double top = glm::min(this->maximumY, other.maximumY); + const double left = glm::max(this->minimumX, other.minimumX); + const double bottom = glm::max(this->minimumY, other.minimumY); + const double right = glm::min(this->maximumX, other.maximumX); + const double top = glm::min(this->maximumY, other.maximumY); if (bottom >= top || left >= right) { return std::nullopt; diff --git a/CesiumGeospatial/include/CesiumGeospatial/GeographicProjection.h b/CesiumGeospatial/include/CesiumGeospatial/GeographicProjection.h index 49c269c36..eac279605 100644 --- a/CesiumGeospatial/include/CesiumGeospatial/GeographicProjection.h +++ b/CesiumGeospatial/include/CesiumGeospatial/GeographicProjection.h @@ -45,9 +45,9 @@ class CESIUMGEOSPATIAL_API GeographicProjection final { */ static constexpr CesiumGeometry::Rectangle computeMaximumProjectedRectangle( const Ellipsoid& ellipsoid = Ellipsoid::WGS84) noexcept { - double longitudeValue = + const double longitudeValue = ellipsoid.getMaximumRadius() * CesiumUtility::Math::ONE_PI; - double latitudeValue = + const double latitudeValue = ellipsoid.getMaximumRadius() * CesiumUtility::Math::PI_OVER_TWO; return CesiumGeometry::Rectangle( -longitudeValue, diff --git a/CesiumGeospatial/include/CesiumGeospatial/GlobeRectangle.h b/CesiumGeospatial/include/CesiumGeospatial/GlobeRectangle.h index b117d8dd1..21bf87839 100644 --- a/CesiumGeospatial/include/CesiumGeospatial/GlobeRectangle.h +++ b/CesiumGeospatial/include/CesiumGeospatial/GlobeRectangle.h @@ -129,7 +129,7 @@ class CESIUMGEOSPATIAL_API GlobeRectangle final { */ constexpr double computeWidth() const noexcept { double east = this->_east; - double west = this->_west; + const double west = this->_west; if (east < west) { east += CesiumUtility::Math::TWO_PI; } diff --git a/CesiumGeospatial/include/CesiumGeospatial/WebMercatorProjection.h b/CesiumGeospatial/include/CesiumGeospatial/WebMercatorProjection.h index 885a56535..1f3acf9d5 100644 --- a/CesiumGeospatial/include/CesiumGeospatial/WebMercatorProjection.h +++ b/CesiumGeospatial/include/CesiumGeospatial/WebMercatorProjection.h @@ -55,7 +55,7 @@ class CESIUMGEOSPATIAL_API WebMercatorProjection final { */ static constexpr CesiumGeometry::Rectangle computeMaximumProjectedRectangle( const Ellipsoid& ellipsoid = Ellipsoid::WGS84) noexcept { - double value = ellipsoid.getMaximumRadius() * CesiumUtility::Math::ONE_PI; + const double value = ellipsoid.getMaximumRadius() * CesiumUtility::Math::ONE_PI; return CesiumGeometry::Rectangle(-value, -value, value, value); } diff --git a/CesiumGeospatial/src/BoundingRegion.cpp b/CesiumGeospatial/src/BoundingRegion.cpp index 575136575..e7b1f2d62 100644 --- a/CesiumGeospatial/src/BoundingRegion.cpp +++ b/CesiumGeospatial/src/BoundingRegion.cpp @@ -33,7 +33,7 @@ BoundingRegion::BoundingRegion( _northNormal(), _planesAreInvalid(false) { // The middle latitude on the western edge. - glm::dvec3 westernMidpointCartesian = + const glm::dvec3 westernMidpointCartesian = ellipsoid.cartographicToCartesian(Cartographic( rectangle.getWest(), (rectangle.getSouth() + rectangle.getNorth()) * 0.5, @@ -44,7 +44,7 @@ BoundingRegion::BoundingRegion( glm::cross(westernMidpointCartesian, glm::dvec3(0.0, 0.0, 1.0))); // The middle latitude on the eastern edge. - glm::dvec3 easternMidpointCartesian = + const glm::dvec3 easternMidpointCartesian = ellipsoid.cartographicToCartesian(Cartographic( rectangle.getEast(), (rectangle.getSouth() + rectangle.getNorth()) * 0.5, @@ -55,25 +55,25 @@ BoundingRegion::BoundingRegion( glm::cross(glm::dvec3(0.0, 0.0, 1.0), easternMidpointCartesian)); // Compute the normal of the plane bounding the southern edge of the tile. - glm::dvec3 westVector = westernMidpointCartesian - easternMidpointCartesian; - glm::dvec3 eastWestNormal = glm::normalize(westVector); + const glm::dvec3 westVector = westernMidpointCartesian - easternMidpointCartesian; + const glm::dvec3 eastWestNormal = glm::normalize(westVector); if (!Math::equalsEpsilon(glm::length(eastWestNormal), 1.0, Math::EPSILON6)) { this->_planesAreInvalid = true; return; } - double south = rectangle.getSouth(); + const double south = rectangle.getSouth(); glm::dvec3 southSurfaceNormal; if (south > 0.0) { // Compute a plane that doesn't cut through the tile. - glm::dvec3 southCenterCartesian = + const glm::dvec3 southCenterCartesian = ellipsoid.cartographicToCartesian(Cartographic( (rectangle.getWest() + rectangle.getEast()) * 0.5, south, 0.0)); - Plane westPlane(this->_southwestCornerCartesian, this->_westNormal); + const Plane westPlane(this->_southwestCornerCartesian, this->_westNormal); // Find a point that is on the west and the south planes std::optional intersection = IntersectionTests::rayPlane( @@ -95,17 +95,17 @@ BoundingRegion::BoundingRegion( glm::normalize(glm::cross(southSurfaceNormal, westVector)); // Compute the normal of the plane bounding the northern edge of the tile. - double north = rectangle.getNorth(); + const double north = rectangle.getNorth(); glm::dvec3 northSurfaceNormal; if (north < 0.0) { // Compute a plane that doesn't cut through the tile. - glm::dvec3 northCenterCartesian = + const glm::dvec3 northCenterCartesian = ellipsoid.cartographicToCartesian(Cartographic( (rectangle.getWest() + rectangle.getEast()) * 0.5, north, 0.0)); - Plane eastPlane(this->_northeastCornerCartesian, this->_eastNormal); + const Plane eastPlane(this->_northeastCornerCartesian, this->_eastNormal); // Find a point that is on the east and the north planes std::optional intersection = IntersectionTests::rayPlane( @@ -168,18 +168,18 @@ double BoundingRegion::computeDistanceSquaredToPosition( const glm::dvec3& eastNormal = this->_eastNormal; const glm::dvec3& northNormal = this->_northNormal; - glm::dvec3 vectorFromSouthwestCorner = + const glm::dvec3 vectorFromSouthwestCorner = cartesianPosition - southwestCornerCartesian; - double distanceToWestPlane = + const double distanceToWestPlane = glm::dot(vectorFromSouthwestCorner, westNormal); - double distanceToSouthPlane = + const double distanceToSouthPlane = glm::dot(vectorFromSouthwestCorner, southNormal); - glm::dvec3 vectorFromNortheastCorner = + const glm::dvec3 vectorFromNortheastCorner = cartesianPosition - northeastCornerCartesian; - double distanceToEastPlane = + const double distanceToEastPlane = glm::dot(vectorFromNortheastCorner, eastNormal); - double distanceToNorthPlane = + const double distanceToNorthPlane = glm::dot(vectorFromNortheastCorner, northNormal); if (distanceToWestPlane > 0.0) { @@ -195,20 +195,20 @@ double BoundingRegion::computeDistanceSquaredToPosition( } } - double cameraHeight = cartographicPosition.height; - double minimumHeight = this->_minimumHeight; - double maximumHeight = this->_maximumHeight; + const double cameraHeight = cartographicPosition.height; + const double minimumHeight = this->_minimumHeight; + const double maximumHeight = this->_maximumHeight; if (cameraHeight > maximumHeight) { - double distanceAboveTop = cameraHeight - maximumHeight; + const double distanceAboveTop = cameraHeight - maximumHeight; result += distanceAboveTop * distanceAboveTop; } else if (cameraHeight < minimumHeight) { - double distanceBelowBottom = minimumHeight - cameraHeight; + const double distanceBelowBottom = minimumHeight - cameraHeight; result += distanceBelowBottom * distanceBelowBottom; } } - double bboxDistanceSquared = + const double bboxDistanceSquared = this->getBoundingBox().computeDistanceSquaredToPosition( cartesianPosition); return glm::max(bboxDistanceSquared, result); @@ -235,17 +235,17 @@ static OrientedBoundingBox fromPlaneExtents( double maximumZ) noexcept { glm::dmat3 halfAxes(planeXAxis, planeYAxis, planeZAxis); - glm::dvec3 centerOffset( + const glm::dvec3 centerOffset( (minimumX + maximumX) / 2.0, (minimumY + maximumY) / 2.0, (minimumZ + maximumZ) / 2.0); - glm::dvec3 scale( + const glm::dvec3 scale( (maximumX - minimumX) / 2.0, (maximumY - minimumY) / 2.0, (maximumZ - minimumZ) / 2.0); - glm::dmat3 scaledHalfAxes( + const glm::dmat3 scaledHalfAxes( halfAxes[0] * scale.x, halfAxes[1] * scale.y, halfAxes[2] * scale.z); @@ -276,21 +276,21 @@ static OrientedBoundingBox fromPlaneExtents( if (rectangle.computeWidth() <= Math::ONE_PI) { // The bounding box will be aligned with the tangent plane at the center of // the rectangle. - Cartographic tangentPointCartographic = rectangle.computeCenter(); - glm::dvec3 tangentPoint = + const Cartographic tangentPointCartographic = rectangle.computeCenter(); + const glm::dvec3 tangentPoint = ellipsoid.cartographicToCartesian(tangentPointCartographic); - EllipsoidTangentPlane tangentPlane(tangentPoint, ellipsoid); + const EllipsoidTangentPlane tangentPlane(tangentPoint, ellipsoid); plane = tangentPlane.getPlane(); // If the rectangle spans the equator, CW is instead aligned with the // equator (because it sticks out the farthest at the equator). - double lonCenter = tangentPointCartographic.longitude; - double latCenter = rectangle.getSouth() < 0.0 && rectangle.getNorth() > 0.0 + const double lonCenter = tangentPointCartographic.longitude; + const double latCenter = rectangle.getSouth() < 0.0 && rectangle.getNorth() > 0.0 ? 0.0 : tangentPointCartographic.latitude; // Compute XY extents using the rectangle at maximum height - Cartographic perimeterCartographicNC( + const Cartographic perimeterCartographicNC( lonCenter, rectangle.getNorth(), maximumHeight); @@ -298,7 +298,7 @@ static OrientedBoundingBox fromPlaneExtents( rectangle.getWest(), rectangle.getNorth(), maximumHeight); - Cartographic perimeterCartographicCW( + const Cartographic perimeterCartographicCW( rectangle.getWest(), latCenter, maximumHeight); @@ -306,31 +306,31 @@ static OrientedBoundingBox fromPlaneExtents( rectangle.getWest(), rectangle.getSouth(), maximumHeight); - Cartographic perimeterCartographicSC( + const Cartographic perimeterCartographicSC( lonCenter, rectangle.getSouth(), maximumHeight); - glm::dvec3 perimeterCartesianNC = + const glm::dvec3 perimeterCartesianNC = ellipsoid.cartographicToCartesian(perimeterCartographicNC); glm::dvec3 perimeterCartesianNW = ellipsoid.cartographicToCartesian(perimeterCartographicNW); - glm::dvec3 perimeterCartesianCW = + const glm::dvec3 perimeterCartesianCW = ellipsoid.cartographicToCartesian(perimeterCartographicCW); glm::dvec3 perimeterCartesianSW = ellipsoid.cartographicToCartesian(perimeterCartographicSW); - glm::dvec3 perimeterCartesianSC = + const glm::dvec3 perimeterCartesianSC = ellipsoid.cartographicToCartesian(perimeterCartographicSC); - glm::dvec2 perimeterProjectedNC = + const glm::dvec2 perimeterProjectedNC = tangentPlane.projectPointToNearestOnPlane(perimeterCartesianNC); - glm::dvec2 perimeterProjectedNW = + const glm::dvec2 perimeterProjectedNW = tangentPlane.projectPointToNearestOnPlane(perimeterCartesianNW); - glm::dvec2 perimeterProjectedCW = + const glm::dvec2 perimeterProjectedCW = tangentPlane.projectPointToNearestOnPlane(perimeterCartesianCW); - glm::dvec2 perimeterProjectedSW = + const glm::dvec2 perimeterProjectedSW = tangentPlane.projectPointToNearestOnPlane(perimeterCartesianSW); - glm::dvec2 perimeterProjectedSC = + const glm::dvec2 perimeterProjectedSC = tangentPlane.projectPointToNearestOnPlane(perimeterCartesianSC); minX = glm::min( @@ -372,12 +372,12 @@ static OrientedBoundingBox fromPlaneExtents( // Handle the case where rectangle width is greater than PI (wraps around more // than half the ellipsoid). - bool fullyAboveEquator = rectangle.getSouth() > 0.0; - bool fullyBelowEquator = rectangle.getNorth() < 0.0; - double latitudeNearestToEquator = + const bool fullyAboveEquator = rectangle.getSouth() > 0.0; + const bool fullyBelowEquator = rectangle.getNorth() < 0.0; + const double latitudeNearestToEquator = fullyAboveEquator ? rectangle.getSouth() : fullyBelowEquator ? rectangle.getNorth() : 0.0; - double centerLongitude = rectangle.computeCenter().longitude; + const double centerLongitude = rectangle.computeCenter().longitude; // Plane is located at the rectangle's center longitude and the rectangle's // latitude that is closest to the equator. It rotates around the Z axis. This @@ -387,17 +387,17 @@ static OrientedBoundingBox fromPlaneExtents( Cartographic(centerLongitude, latitudeNearestToEquator, maximumHeight)); planeOrigin.z = 0.0; // center the plane on the equator to simpify plane // normal calculation - bool isPole = glm::abs(planeOrigin.x) < Math::EPSILON10 && + const bool isPole = glm::abs(planeOrigin.x) < Math::EPSILON10 && glm::abs(planeOrigin.y) < Math::EPSILON10; - glm::dvec3 planeNormal = + const glm::dvec3 planeNormal = !isPole ? glm::normalize(planeOrigin) : glm::dvec3(1.0, 0.0, 0.0); - glm::dvec3 planeYAxis(0.0, 0.0, 1.0); - glm::dvec3 planeXAxis = glm::cross(planeNormal, planeYAxis); + const glm::dvec3 planeYAxis(0.0, 0.0, 1.0); + const glm::dvec3 planeXAxis = glm::cross(planeNormal, planeYAxis); plane = Plane(planeOrigin, planeNormal); // Get the horizon point relative to the center. This will be the farthest // extent in the plane's X dimension. - glm::dvec3 horizonCartesian = ellipsoid.cartographicToCartesian(Cartographic( + const glm::dvec3 horizonCartesian = ellipsoid.cartographicToCartesian(Cartographic( centerLongitude + Math::PI_OVER_TWO, latitudeNearestToEquator, maximumHeight)); @@ -417,7 +417,7 @@ static OrientedBoundingBox fromPlaneExtents( rectangle.getSouth(), fullyAboveEquator ? minimumHeight : maximumHeight)) .z; - glm::dvec3 farZ = ellipsoid.cartographicToCartesian(Cartographic( + const glm::dvec3 farZ = ellipsoid.cartographicToCartesian(Cartographic( rectangle.getEast(), latitudeNearestToEquator, maximumHeight)); diff --git a/CesiumGeospatial/src/CartographicPolygon.cpp b/CesiumGeospatial/src/CartographicPolygon.cpp index 39f6b053a..ab6db35af 100644 --- a/CesiumGeospatial/src/CartographicPolygon.cpp +++ b/CesiumGeospatial/src/CartographicPolygon.cpp @@ -8,7 +8,7 @@ namespace CesiumGeospatial { static std::vector triangulatePolygon(const std::vector& polygon) { std::vector indices; - size_t vertexCount = polygon.size(); + const size_t vertexCount = polygon.size(); if (vertexCount < 3) { return indices; @@ -47,7 +47,7 @@ triangulatePolygon(const std::vector& polygon) { static std::optional computeBoundingRectangle(const std::vector& polygon) { - size_t vertexCount = polygon.size(); + const size_t vertexCount = polygon.size(); if (vertexCount < 3) { return std::nullopt; @@ -70,7 +70,7 @@ computeBoundingRectangle(const std::vector& polygon) { south = point1.y; } - double dif_west = point1.x - west; + const double dif_west = point1.x - west; // check if the difference crosses the antipole if (glm::abs(dif_west) > CesiumUtility::Math::ONE_PI) { // east wrapping past the antipole to the west @@ -83,7 +83,7 @@ computeBoundingRectangle(const std::vector& polygon) { } } - double dif_east = point1.x - east; + const double dif_east = point1.x - east; // check if the difference crosses the antipole if (glm::abs(dif_east) > CesiumUtility::Math::ONE_PI) { // west wrapping past the antipole to the east diff --git a/CesiumGeospatial/src/Ellipsoid.cpp b/CesiumGeospatial/src/Ellipsoid.cpp index cae7e0ea5..375314fff 100644 --- a/CesiumGeospatial/src/Ellipsoid.cpp +++ b/CesiumGeospatial/src/Ellipsoid.cpp @@ -16,9 +16,9 @@ Ellipsoid::geodeticSurfaceNormal(const glm::dvec3& position) const noexcept { glm::dvec3 Ellipsoid::geodeticSurfaceNormal( const Cartographic& cartographic) const noexcept { - double longitude = cartographic.longitude; - double latitude = cartographic.latitude; - double cosLatitude = glm::cos(latitude); + const double longitude = cartographic.longitude; + const double latitude = cartographic.latitude; + const double cosLatitude = glm::cos(latitude); return glm::normalize(glm::dvec3( cosLatitude * glm::cos(longitude), @@ -30,7 +30,7 @@ glm::dvec3 Ellipsoid::cartographicToCartesian( const Cartographic& cartographic) const noexcept { glm::dvec3 n = this->geodeticSurfaceNormal(cartographic); glm::dvec3 k = this->_radiiSquared * n; - double gamma = sqrt(glm::dot(n, k)); + const double gamma = sqrt(glm::dot(n, k)); k /= gamma; n *= cartographic.height; return k + n; @@ -44,33 +44,33 @@ Ellipsoid::cartesianToCartographic(const glm::dvec3& cartesian) const noexcept { return std::optional(); } - glm::dvec3 n = this->geodeticSurfaceNormal(p.value()); - glm::dvec3 h = cartesian - p.value(); + const glm::dvec3 n = this->geodeticSurfaceNormal(p.value()); + const glm::dvec3 h = cartesian - p.value(); - double longitude = glm::atan(n.y, n.x); - double latitude = glm::asin(n.z); - double height = Math::sign(glm::dot(h, cartesian)) * glm::length(h); + const double longitude = glm::atan(n.y, n.x); + const double latitude = glm::asin(n.z); + const double height = Math::sign(glm::dot(h, cartesian)) * glm::length(h); return Cartographic(longitude, latitude, height); } std::optional Ellipsoid::scaleToGeodeticSurface(const glm::dvec3& cartesian) const noexcept { - double positionX = cartesian.x; - double positionY = cartesian.y; - double positionZ = cartesian.z; + const double positionX = cartesian.x; + const double positionY = cartesian.y; + const double positionZ = cartesian.z; - double oneOverRadiiX = this->_oneOverRadii.x; - double oneOverRadiiY = this->_oneOverRadii.y; - double oneOverRadiiZ = this->_oneOverRadii.z; + const double oneOverRadiiX = this->_oneOverRadii.x; + const double oneOverRadiiY = this->_oneOverRadii.y; + const double oneOverRadiiZ = this->_oneOverRadii.z; - double x2 = positionX * positionX * oneOverRadiiX * oneOverRadiiX; - double y2 = positionY * positionY * oneOverRadiiY * oneOverRadiiY; - double z2 = positionZ * positionZ * oneOverRadiiZ * oneOverRadiiZ; + const double x2 = positionX * positionX * oneOverRadiiX * oneOverRadiiX; + const double y2 = positionY * positionY * oneOverRadiiY * oneOverRadiiY; + const double z2 = positionZ * positionZ * oneOverRadiiZ * oneOverRadiiZ; // Compute the squared ellipsoid norm. - double squaredNorm = x2 + y2 + z2; - double ratio = sqrt(1.0 / squaredNorm); + const double squaredNorm = x2 + y2 + z2; + const double ratio = sqrt(1.0 / squaredNorm); // As an initial approximation, assume that the radial intersection is the // projection point. @@ -81,13 +81,13 @@ Ellipsoid::scaleToGeodeticSurface(const glm::dvec3& cartesian) const noexcept { return !std::isfinite(ratio) ? std::optional() : intersection; } - double oneOverRadiiSquaredX = this->_oneOverRadiiSquared.x; - double oneOverRadiiSquaredY = this->_oneOverRadiiSquared.y; - double oneOverRadiiSquaredZ = this->_oneOverRadiiSquared.z; + const double oneOverRadiiSquaredX = this->_oneOverRadiiSquared.x; + const double oneOverRadiiSquaredY = this->_oneOverRadiiSquared.y; + const double oneOverRadiiSquaredZ = this->_oneOverRadiiSquared.z; // Use the gradient at the intersection point in place of the true unit // normal. The difference in magnitude will be absorbed in the multiplier. - glm::dvec3 gradient( + const glm::dvec3 gradient( intersection.x * oneOverRadiiSquaredX * 2.0, intersection.y * oneOverRadiiSquaredY * 2.0, intersection.z * oneOverRadiiSquaredZ * 2.0); @@ -132,7 +132,7 @@ Ellipsoid::scaleToGeodeticSurface(const glm::dvec3& cartesian) const noexcept { y2 * yMultiplier3 * oneOverRadiiSquaredY + z2 * zMultiplier3 * oneOverRadiiSquaredZ; - double derivative = -2.0 * denominator; + const double derivative = -2.0 * denominator; correction = func / derivative; } while (glm::abs(func) > Math::EPSILON12); diff --git a/CesiumGeospatial/src/EllipsoidTangentPlane.cpp b/CesiumGeospatial/src/EllipsoidTangentPlane.cpp index 6947babee..e6a1f0ba0 100644 --- a/CesiumGeospatial/src/EllipsoidTangentPlane.cpp +++ b/CesiumGeospatial/src/EllipsoidTangentPlane.cpp @@ -28,7 +28,7 @@ EllipsoidTangentPlane::EllipsoidTangentPlane( glm::dvec2 EllipsoidTangentPlane::projectPointToNearestOnPlane( const glm::dvec3& cartesian) const noexcept { - Ray ray(cartesian, this->_plane.getNormal()); + const Ray ray(cartesian, this->_plane.getNormal()); std::optional intersectionPoint = IntersectionTests::rayPlane(ray, this->_plane); @@ -39,7 +39,7 @@ glm::dvec2 EllipsoidTangentPlane::projectPointToNearestOnPlane( } } - glm::dvec3 v = intersectionPoint.value() - this->_origin; + const glm::dvec3 v = intersectionPoint.value() - this->_origin; return glm::dvec2(glm::dot(this->_xAxis, v), glm::dot(this->_yAxis, v)); } diff --git a/CesiumGeospatial/src/GeographicProjection.cpp b/CesiumGeospatial/src/GeographicProjection.cpp index ae2c1a16f..4ec6ad563 100644 --- a/CesiumGeospatial/src/GeographicProjection.cpp +++ b/CesiumGeospatial/src/GeographicProjection.cpp @@ -11,7 +11,7 @@ GeographicProjection::GeographicProjection(const Ellipsoid& ellipsoid) noexcept glm::dvec3 GeographicProjection::project(const Cartographic& cartographic) const noexcept { - double semimajorAxis = this->_semimajorAxis; + const double semimajorAxis = this->_semimajorAxis; return glm::dvec3( cartographic.longitude * semimajorAxis, cartographic.latitude * semimajorAxis, @@ -20,14 +20,14 @@ GeographicProjection::project(const Cartographic& cartographic) const noexcept { CesiumGeometry::Rectangle GeographicProjection::project( const CesiumGeospatial::GlobeRectangle& rectangle) const noexcept { - glm::dvec3 sw = this->project(rectangle.getSouthwest()); - glm::dvec3 ne = this->project(rectangle.getNortheast()); + const glm::dvec3 sw = this->project(rectangle.getSouthwest()); + const glm::dvec3 ne = this->project(rectangle.getNortheast()); return CesiumGeometry::Rectangle(sw.x, sw.y, ne.x, ne.y); } Cartographic GeographicProjection::unproject( const glm::dvec2& projectedCoordinates) const noexcept { - double oneOverEarthSemimajorAxis = this->_oneOverSemimajorAxis; + const double oneOverEarthSemimajorAxis = this->_oneOverSemimajorAxis; return Cartographic( projectedCoordinates.x * oneOverEarthSemimajorAxis, @@ -44,8 +44,8 @@ Cartographic GeographicProjection::unproject( CesiumGeospatial::GlobeRectangle GeographicProjection::unproject( const CesiumGeometry::Rectangle& rectangle) const noexcept { - Cartographic sw = this->unproject(rectangle.getLowerLeft()); - Cartographic ne = this->unproject(rectangle.getUpperRight()); + const Cartographic sw = this->unproject(rectangle.getLowerLeft()); + const Cartographic ne = this->unproject(rectangle.getUpperRight()); return GlobeRectangle(sw.longitude, sw.latitude, ne.longitude, ne.latitude); } diff --git a/CesiumGeospatial/src/GlobeRectangle.cpp b/CesiumGeospatial/src/GlobeRectangle.cpp index 6505ab022..8aede9a1c 100644 --- a/CesiumGeospatial/src/GlobeRectangle.cpp +++ b/CesiumGeospatial/src/GlobeRectangle.cpp @@ -7,23 +7,23 @@ namespace CesiumGeospatial { Cartographic GlobeRectangle::computeCenter() const noexcept { double east = this->_east; - double west = this->_west; + const double west = this->_west; if (east < west) { east += Math::TWO_PI; } - double longitude = Math::negativePiToPi((west + east) * 0.5); - double latitude = (this->_south + this->_north) * 0.5; + const double longitude = Math::negativePiToPi((west + east) * 0.5); + const double latitude = (this->_south + this->_north) * 0.5; return Cartographic(longitude, latitude, 0.0); } bool GlobeRectangle::contains(const Cartographic& cartographic) const noexcept { double longitude = cartographic.longitude; - double latitude = cartographic.latitude; + const double latitude = cartographic.latitude; - double west = this->_west; + const double west = this->_west; double east = this->_east; if (east < west) { @@ -60,9 +60,9 @@ std::optional GlobeRectangle::computeIntersection( rectangleWest += CesiumUtility::Math::TWO_PI; } - double west = CesiumUtility::Math::negativePiToPi( + const double west = CesiumUtility::Math::negativePiToPi( glm::max(rectangleWest, otherRectangleWest)); - double east = CesiumUtility::Math::negativePiToPi( + const double east = CesiumUtility::Math::negativePiToPi( glm::min(rectangleEast, otherRectangleEast)); if ((this->_west < this->_east || other._west < other._east) && @@ -70,8 +70,8 @@ std::optional GlobeRectangle::computeIntersection( return std::nullopt; } - double south = glm::max(this->_south, other._south); - double north = glm::min(this->_north, other._north); + const double south = glm::max(this->_south, other._south); + const double north = glm::min(this->_north, other._north); if (south >= north) { return std::nullopt; @@ -100,9 +100,9 @@ GlobeRectangle::computeUnion(const GlobeRectangle& other) const noexcept { rectangleWest += CesiumUtility::Math::TWO_PI; } - double west = CesiumUtility::Math::convertLongitudeRange( + const double west = CesiumUtility::Math::convertLongitudeRange( glm::min(rectangleWest, otherRectangleWest)); - double east = CesiumUtility::Math::convertLongitudeRange( + const double east = CesiumUtility::Math::convertLongitudeRange( glm::max(rectangleEast, otherRectangleEast)); return GlobeRectangle( diff --git a/CesiumGeospatial/src/Transforms.cpp b/CesiumGeospatial/src/Transforms.cpp index 379f3fe5d..78e49936c 100644 --- a/CesiumGeospatial/src/Transforms.cpp +++ b/CesiumGeospatial/src/Transforms.cpp @@ -21,7 +21,7 @@ namespace CesiumGeospatial { if (Math::equalsEpsilon(origin.x, 0.0, Math::EPSILON14) && Math::equalsEpsilon(origin.y, 0.0, Math::EPSILON14)) { // If x and y are zero, assume origin is at a pole, which is a special case. - double sign = Math::sign(origin.z); + const double sign = Math::sign(origin.z); return glm::dmat4x4( glm::dvec4(0.0, 1.0, 0.0, 0.0), glm::dvec4(-1.0 * sign, 0.0, 0.0, 0.0), @@ -29,9 +29,9 @@ namespace CesiumGeospatial { glm::dvec4(origin, 1.0)); } - glm::dvec3 up = ellipsoid.geodeticSurfaceNormal(origin); - glm::dvec3 east = glm::normalize(glm::dvec3(-origin.y, origin.x, 0.0)); - glm::dvec3 north = glm::cross(up, east); + const glm::dvec3 up = ellipsoid.geodeticSurfaceNormal(origin); + const glm::dvec3 east = glm::normalize(glm::dvec3(-origin.y, origin.x, 0.0)); + const glm::dvec3 north = glm::cross(up, east); return glm::dmat4x4( glm::dvec4(east, 0.0), diff --git a/CesiumGeospatial/src/WebMercatorProjection.cpp b/CesiumGeospatial/src/WebMercatorProjection.cpp index ef299240d..4827280b3 100644 --- a/CesiumGeospatial/src/WebMercatorProjection.cpp +++ b/CesiumGeospatial/src/WebMercatorProjection.cpp @@ -25,7 +25,7 @@ WebMercatorProjection::WebMercatorProjection( glm::dvec3 WebMercatorProjection::project( const Cartographic& cartographic) const noexcept { - double semimajorAxis = this->_semimajorAxis; + const double semimajorAxis = this->_semimajorAxis; return glm::dvec3( cartographic.longitude * semimajorAxis, WebMercatorProjection::geodeticLatitudeToMercatorAngle( @@ -36,14 +36,14 @@ glm::dvec3 WebMercatorProjection::project( CesiumGeometry::Rectangle WebMercatorProjection::project( const CesiumGeospatial::GlobeRectangle& rectangle) const noexcept { - glm::dvec3 sw = this->project(rectangle.getSouthwest()); - glm::dvec3 ne = this->project(rectangle.getNortheast()); + const glm::dvec3 sw = this->project(rectangle.getSouthwest()); + const glm::dvec3 ne = this->project(rectangle.getNortheast()); return CesiumGeometry::Rectangle(sw.x, sw.y, ne.x, ne.y); } Cartographic WebMercatorProjection::unproject( const glm::dvec2& projectedCoordinates) const noexcept { - double oneOverEarthSemimajorAxis = this->_oneOverSemimajorAxis; + const double oneOverEarthSemimajorAxis = this->_oneOverSemimajorAxis; return Cartographic( projectedCoordinates.x * oneOverEarthSemimajorAxis, @@ -61,8 +61,8 @@ Cartographic WebMercatorProjection::unproject( CesiumGeospatial::GlobeRectangle WebMercatorProjection::unproject( const CesiumGeometry::Rectangle& rectangle) const noexcept { - Cartographic sw = this->unproject(rectangle.getLowerLeft()); - Cartographic ne = this->unproject(rectangle.getUpperRight()); + const Cartographic sw = this->unproject(rectangle.getLowerLeft()); + const Cartographic ne = this->unproject(rectangle.getUpperRight()); return GlobeRectangle(sw.longitude, sw.latitude, ne.longitude, ne.latitude); } @@ -80,7 +80,7 @@ CesiumGeospatial::GlobeRectangle WebMercatorProjection::unproject( -WebMercatorProjection::MAXIMUM_LATITUDE, WebMercatorProjection::MAXIMUM_LATITUDE); - double sinLatitude = glm::sin(latitude); + const double sinLatitude = glm::sin(latitude); return 0.5 * glm::log((1.0 + sinLatitude) / (1.0 - sinLatitude)); } diff --git a/CesiumGltf/include/CesiumGltf/AccessorView.h b/CesiumGltf/include/CesiumGltf/AccessorView.h index df9b8e1f9..5dcfeb0b0 100644 --- a/CesiumGltf/include/CesiumGltf/AccessorView.h +++ b/CesiumGltf/include/CesiumGltf/AccessorView.h @@ -215,16 +215,16 @@ template class AccessorView final { } const std::vector& data = pBuffer->cesium.data; - int64_t bufferBytes = int64_t(data.size()); + const int64_t bufferBytes = int64_t(data.size()); if (pBufferView->byteOffset + pBufferView->byteLength > bufferBytes) { this->_status = AccessorViewStatus::BufferTooSmall; return; } - int64_t accessorByteStride = accessor.computeByteStride(model); - int64_t accessorComponentElements = accessor.computeNumberOfComponents(); - int64_t accessorComponentBytes = accessor.computeByteSizeOfComponent(); - int64_t accessorBytesPerStride = + const int64_t accessorByteStride = accessor.computeByteStride(model); + const int64_t accessorComponentElements = accessor.computeNumberOfComponents(); + const int64_t accessorComponentBytes = accessor.computeByteSizeOfComponent(); + const int64_t accessorBytesPerStride = accessorComponentElements * accessorComponentBytes; if (sizeof(T) != accessorBytesPerStride) { @@ -232,8 +232,8 @@ template class AccessorView final { return; } - int64_t accessorBytes = accessorByteStride * accessor.count; - int64_t bytesRemainingInBufferView = + const int64_t accessorBytes = accessorByteStride * accessor.count; + const int64_t bytesRemainingInBufferView = pBufferView->byteLength - (accessor.byteOffset + accessorByteStride * (accessor.count - 1) + accessorBytesPerStride); diff --git a/CesiumGltf/include/CesiumGltf/MetadataArrayView.h b/CesiumGltf/include/CesiumGltf/MetadataArrayView.h index 6f5f00e47..1a1caa63d 100644 --- a/CesiumGltf/include/CesiumGltf/MetadataArrayView.h +++ b/CesiumGltf/include/CesiumGltf/MetadataArrayView.h @@ -39,9 +39,9 @@ template <> class MetadataArrayView { bool operator[](int64_t index) const { index += _bitOffset; - int64_t byteIndex = index / 8; - int64_t bitIndex = index % 8; - int bitValue = static_cast(_valueBuffer[byteIndex] >> bitIndex) & 1; + const int64_t byteIndex = index / 8; + const int64_t bitIndex = index % 8; + const int bitValue = static_cast(_valueBuffer[byteIndex] >> bitIndex) & 1; return bitValue == 1; } @@ -69,9 +69,9 @@ template <> class MetadataArrayView { _size{size} {} std::string_view operator[](int64_t index) const { - size_t currentOffset = + const size_t currentOffset = getOffsetFromOffsetBuffer(index, _offsetBuffer, _offsetType); - size_t nextOffset = + const size_t nextOffset = getOffsetFromOffsetBuffer(index + 1, _offsetBuffer, _offsetType); return std::string_view( reinterpret_cast(_valueBuffer.data() + currentOffset), @@ -88,25 +88,25 @@ template <> class MetadataArrayView { switch (offsetType) { case PropertyType::Uint8: { assert(instance < offsetBuffer.size() / sizeof(uint8_t)); - uint8_t offset = *reinterpret_cast( + const uint8_t offset = *reinterpret_cast( offsetBuffer.data() + instance * sizeof(uint8_t)); return static_cast(offset); } case PropertyType::Uint16: { assert(instance < offsetBuffer.size() / sizeof(uint16_t)); - uint16_t offset = *reinterpret_cast( + const uint16_t offset = *reinterpret_cast( offsetBuffer.data() + instance * sizeof(uint16_t)); return static_cast(offset); } case PropertyType::Uint32: { assert(instance < offsetBuffer.size() / sizeof(uint32_t)); - uint32_t offset = *reinterpret_cast( + const uint32_t offset = *reinterpret_cast( offsetBuffer.data() + instance * sizeof(uint32_t)); return static_cast(offset); } case PropertyType::Uint64: { assert(instance < offsetBuffer.size() / sizeof(uint64_t)); - uint64_t offset = *reinterpret_cast( + const uint64_t offset = *reinterpret_cast( offsetBuffer.data() + instance * sizeof(uint64_t)); return static_cast(offset); } diff --git a/CesiumGltf/include/CesiumGltf/MetadataFeatureTableView.h b/CesiumGltf/include/CesiumGltf/MetadataFeatureTableView.h index 5cccb1b54..0921f6575 100644 --- a/CesiumGltf/include/CesiumGltf/MetadataFeatureTableView.h +++ b/CesiumGltf/include/CesiumGltf/MetadataFeatureTableView.h @@ -343,14 +343,14 @@ class MetadataFeatureTableView { MetadataPropertyView getPrimitivePropertyValues( const ClassProperty& classProperty, const FeatureTableProperty& featureTableProperty) const { - PropertyType type = convertStringToPropertyType(classProperty.type); + const PropertyType type = convertStringToPropertyType(classProperty.type); if (TypeToPropertyType::value != type) { return createInvalidPropertyView( MetadataPropertyViewStatus::InvalidTypeMismatch); } gsl::span valueBuffer; - auto status = getBufferSafe(featureTableProperty.bufferView, valueBuffer); + const auto status = getBufferSafe(featureTableProperty.bufferView, valueBuffer); if (status != MetadataPropertyViewStatus::Valid) { return createInvalidPropertyView(status); } @@ -402,7 +402,7 @@ class MetadataFeatureTableView { MetadataPropertyViewStatus::InvalidTypeMismatch); } - PropertyType componentType = + const PropertyType componentType = convertStringToPropertyType(classProperty.componentType.getString()); if (TypeToPropertyType::value != componentType) { return createInvalidPropertyView>( @@ -421,7 +421,7 @@ class MetadataFeatureTableView { InvalidBufferViewSizeNotDivisibleByTypeSize); } - int64_t componentCount = classProperty.componentCount.value_or(0); + const int64_t componentCount = classProperty.componentCount.value_or(0); if (componentCount > 0 && featureTableProperty.arrayOffsetBufferView >= 0) { return createInvalidPropertyView>( MetadataPropertyViewStatus:: @@ -462,7 +462,7 @@ class MetadataFeatureTableView { } // dynamic array - PropertyType offsetType = + const PropertyType offsetType = convertOffsetStringToPropertyType(featureTableProperty.offsetType); if (offsetType == PropertyType::None) { return createInvalidPropertyView>( diff --git a/CesiumGltf/include/CesiumGltf/MetadataPropertyView.h b/CesiumGltf/include/CesiumGltf/MetadataPropertyView.h index 519379a0e..fabd11470 100644 --- a/CesiumGltf/include/CesiumGltf/MetadataPropertyView.h +++ b/CesiumGltf/include/CesiumGltf/MetadataPropertyView.h @@ -234,16 +234,16 @@ template class MetadataPropertyView { } bool getBoolean(int64_t instance) const { - int64_t byteIndex = instance / 8; - int64_t bitIndex = instance % 8; - int bitValue = static_cast(_valueBuffer[byteIndex] >> bitIndex) & 1; + const int64_t byteIndex = instance / 8; + const int64_t bitIndex = instance % 8; + const int bitValue = static_cast(_valueBuffer[byteIndex] >> bitIndex) & 1; return bitValue == 1; } std::string_view getString(int64_t instance) const { - size_t currentOffset = + const size_t currentOffset = getOffsetFromOffsetBuffer(instance, _stringOffsetBuffer, _offsetType); - size_t nextOffset = getOffsetFromOffsetBuffer( + const size_t nextOffset = getOffsetFromOffsetBuffer( instance + 1, _stringOffsetBuffer, _offsetType); @@ -255,19 +255,19 @@ template class MetadataPropertyView { template MetadataArrayView getNumericArray(int64_t instance) const { if (_componentCount > 0) { - gsl::span vals( + const gsl::span vals( _valueBuffer.data() + instance * _componentCount * sizeof(T), _componentCount * sizeof(T)); return MetadataArrayView{vals}; } - size_t currentOffset = + const size_t currentOffset = getOffsetFromOffsetBuffer(instance, _arrayOffsetBuffer, _offsetType); - size_t nextOffset = getOffsetFromOffsetBuffer( + const size_t nextOffset = getOffsetFromOffsetBuffer( instance + 1, _arrayOffsetBuffer, _offsetType); - gsl::span vals( + const gsl::span vals( _valueBuffer.data() + currentOffset, (nextOffset - currentOffset)); return MetadataArrayView{vals}; @@ -275,7 +275,7 @@ template class MetadataPropertyView { MetadataArrayView getStringArray(int64_t instance) const { if (_componentCount > 0) { - gsl::span offsetVals( + const gsl::span offsetVals( _stringOffsetBuffer.data() + instance * _componentCount * _offsetSize, (_componentCount + 1) * _offsetSize); return MetadataArrayView( @@ -285,13 +285,13 @@ template class MetadataPropertyView { _componentCount); } - size_t currentOffset = + const size_t currentOffset = getOffsetFromOffsetBuffer(instance, _arrayOffsetBuffer, _offsetType); - size_t nextOffset = getOffsetFromOffsetBuffer( + const size_t nextOffset = getOffsetFromOffsetBuffer( instance + 1, _arrayOffsetBuffer, _offsetType); - gsl::span offsetVals( + const gsl::span offsetVals( _stringOffsetBuffer.data() + currentOffset, (nextOffset - currentOffset + _offsetSize)); return MetadataArrayView( @@ -303,23 +303,23 @@ template class MetadataPropertyView { MetadataArrayView getBooleanArray(int64_t instance) const { if (_componentCount > 0) { - size_t offsetBits = _componentCount * instance; - size_t nextOffsetBits = _componentCount * (instance + 1); - gsl::span buffer( + const size_t offsetBits = _componentCount * instance; + const size_t nextOffsetBits = _componentCount * (instance + 1); + const gsl::span buffer( _valueBuffer.data() + offsetBits / 8, (nextOffsetBits / 8 - offsetBits / 8 + 1)); return MetadataArrayView(buffer, offsetBits % 8, _componentCount); } - size_t currentOffset = + const size_t currentOffset = getOffsetFromOffsetBuffer(instance, _arrayOffsetBuffer, _offsetType); - size_t nextOffset = getOffsetFromOffsetBuffer( + const size_t nextOffset = getOffsetFromOffsetBuffer( instance + 1, _arrayOffsetBuffer, _offsetType); - size_t totalBits = nextOffset - currentOffset; - gsl::span buffer( + const size_t totalBits = nextOffset - currentOffset; + const gsl::span buffer( _valueBuffer.data() + currentOffset / 8, (nextOffset / 8 - currentOffset / 8 + 1)); return MetadataArrayView(buffer, currentOffset % 8, totalBits); @@ -347,25 +347,25 @@ template class MetadataPropertyView { switch (offsetType) { case PropertyType::Uint8: { assert(instance < offsetBuffer.size() / sizeof(uint8_t)); - uint8_t offset = *reinterpret_cast( + const uint8_t offset = *reinterpret_cast( offsetBuffer.data() + instance * sizeof(uint8_t)); return static_cast(offset); } case PropertyType::Uint16: { assert(instance < offsetBuffer.size() / sizeof(uint16_t)); - uint16_t offset = *reinterpret_cast( + const uint16_t offset = *reinterpret_cast( offsetBuffer.data() + instance * sizeof(uint16_t)); return static_cast(offset); } case PropertyType::Uint32: { assert(instance < offsetBuffer.size() / sizeof(uint32_t)); - uint32_t offset = *reinterpret_cast( + const uint32_t offset = *reinterpret_cast( offsetBuffer.data() + instance * sizeof(uint32_t)); return static_cast(offset); } case PropertyType::Uint64: { assert(instance < offsetBuffer.size() / sizeof(uint64_t)); - uint64_t offset = *reinterpret_cast( + const uint64_t offset = *reinterpret_cast( offsetBuffer.data() + instance * sizeof(uint64_t)); return static_cast(offset); } diff --git a/CesiumGltf/src/MetadataFeatureTableView.cpp b/CesiumGltf/src/MetadataFeatureTableView.cpp index f96ed73e1..cc25bd738 100644 --- a/CesiumGltf/src/MetadataFeatureTableView.cpp +++ b/CesiumGltf/src/MetadataFeatureTableView.cpp @@ -12,12 +12,12 @@ static MetadataPropertyViewStatus checkOffsetBuffer( InvalidBufferViewSizeNotDivisibleByTypeSize; } - size_t size = offsetBuffer.size() / sizeof(T); + const size_t size = offsetBuffer.size() / sizeof(T); if (size != instanceCount + 1) { return MetadataPropertyViewStatus::InvalidBufferViewSizeNotFitInstanceCount; } - gsl::span offsetValues( + const gsl::span offsetValues( reinterpret_cast(offsetBuffer.data()), size); @@ -50,7 +50,7 @@ static MetadataPropertyViewStatus checkStringArrayOffsetBuffer( const gsl::span& stringOffsetBuffer, size_t valueBufferSize, size_t instanceCount) noexcept { - auto status = checkOffsetBuffer( + const auto status = checkOffsetBuffer( arrayOffsetBuffer, stringOffsetBuffer.size(), instanceCount, @@ -202,7 +202,7 @@ MetadataFeatureTableView::getStringPropertyValues( return createInvalidPropertyView(status); } - PropertyType offsetType = + const PropertyType offsetType = convertOffsetStringToPropertyType(featureTableProperty.offsetType); if (offsetType == PropertyType::None) { return createInvalidPropertyView( @@ -255,7 +255,7 @@ MetadataFeatureTableView::getStringArrayPropertyValues( } // check fixed or dynamic array - int64_t componentCount = classProperty.componentCount.value_or(0); + const int64_t componentCount = classProperty.componentCount.value_or(0); if (componentCount > 0 && featureTableProperty.arrayOffsetBufferView >= 0) { return createInvalidPropertyView>( MetadataPropertyViewStatus:: @@ -269,7 +269,7 @@ MetadataFeatureTableView::getStringArrayPropertyValues( } // get offset type - PropertyType offsetType = + const PropertyType offsetType = convertOffsetStringToPropertyType(featureTableProperty.offsetType); if (offsetType == PropertyType::None) { return createInvalidPropertyView>( diff --git a/CesiumGltf/src/Model.cpp b/CesiumGltf/src/Model.cpp index a72f956d2..28d3ed346 100644 --- a/CesiumGltf/src/Model.cpp +++ b/CesiumGltf/src/Model.cpp @@ -12,7 +12,7 @@ using namespace CesiumGltf; namespace { template size_t copyElements(std::vector& to, std::vector& from) { - size_t out = to.size(); + const size_t out = to.size(); to.resize(out + from.size()); for (size_t i = 0; i < from.size(); ++i) { to[out + i] = std::move(from[i]); @@ -48,19 +48,19 @@ void Model::merge(Model&& rhs) { this->extensionsRequired.end()), this->extensionsRequired.end()); - size_t firstAccessor = copyElements(this->accessors, rhs.accessors); - size_t firstAnimation = copyElements(this->animations, rhs.animations); - size_t firstBuffer = copyElements(this->buffers, rhs.buffers); - size_t firstBufferView = copyElements(this->bufferViews, rhs.bufferViews); - size_t firstCamera = copyElements(this->cameras, rhs.cameras); - size_t firstImage = copyElements(this->images, rhs.images); - size_t firstMaterial = copyElements(this->materials, rhs.materials); - size_t firstMesh = copyElements(this->meshes, rhs.meshes); - size_t firstNode = copyElements(this->nodes, rhs.nodes); - size_t firstSampler = copyElements(this->samplers, rhs.samplers); - size_t firstScene = copyElements(this->scenes, rhs.scenes); - size_t firstSkin = copyElements(this->skins, rhs.skins); - size_t firstTexture = copyElements(this->textures, rhs.textures); + const size_t firstAccessor = copyElements(this->accessors, rhs.accessors); + const size_t firstAnimation = copyElements(this->animations, rhs.animations); + const size_t firstBuffer = copyElements(this->buffers, rhs.buffers); + const size_t firstBufferView = copyElements(this->bufferViews, rhs.bufferViews); + const size_t firstCamera = copyElements(this->cameras, rhs.cameras); + const size_t firstImage = copyElements(this->images, rhs.images); + const size_t firstMaterial = copyElements(this->materials, rhs.materials); + const size_t firstMesh = copyElements(this->meshes, rhs.meshes); + const size_t firstNode = copyElements(this->nodes, rhs.nodes); + const size_t firstSampler = copyElements(this->samplers, rhs.samplers); + const size_t firstScene = copyElements(this->scenes, rhs.scenes); + const size_t firstSkin = copyElements(this->skins, rhs.skins); + const size_t firstTexture = copyElements(this->textures, rhs.textures); // Update the copied indices for (size_t i = firstAccessor; i < this->accessors.size(); ++i) { @@ -200,7 +200,7 @@ void Model::merge(Model&& rhs) { Model::getSafe(&this->scenes, rhs.scene + int32_t(firstScene)); newScene.nodes = pThisDefaultScene->nodes; - size_t originalNodeCount = newScene.nodes.size(); + const size_t originalNodeCount = newScene.nodes.size(); newScene.nodes.resize(originalNodeCount + pRhsDefaultScene->nodes.size()); std::copy( pRhsDefaultScene->nodes.begin(), @@ -293,13 +293,13 @@ void forEachPrimitiveInNodeObject( nodeTransform * translation * glm::dmat4(rotationQuat) * scale; } - int meshId = node.mesh; + const int meshId = node.mesh; if (meshId >= 0 && meshId < static_cast(model.meshes.size())) { const Mesh& mesh = model.meshes[static_cast(meshId)]; forEachPrimitiveInMeshObject(nodeTransform, model, node, mesh, callback); } - for (int childNodeId : node.children) { + for (const int childNodeId : node.children) { if (childNodeId >= 0 && childNodeId < static_cast(model.nodes.size())) { forEachPrimitiveInNodeObject( @@ -317,7 +317,7 @@ void forEachPrimitiveInSceneObject( const Model& model, const Scene& scene, TCallback& callback) { - for (int nodeID : scene.nodes) { + for (const int nodeID : scene.nodes) { if (nodeID >= 0 && nodeID < static_cast(model.nodes.size())) { forEachPrimitiveInNodeObject( transform, @@ -352,7 +352,7 @@ void Model::forEachPrimitiveInScene( void Model::forEachPrimitiveInScene( int sceneID, std::function&& callback) const { - glm::dmat4x4 rootTransform(1.0); + const glm::dmat4x4 rootTransform(1.0); if (sceneID >= 0) { // Use the user-specified scene if it exists. @@ -407,15 +407,15 @@ void addTriangleNormalToVertexNormals( // Add the triangle's normal to each vertex's accumulated normal. - uint32_t index0 = static_cast(tIndex0); - uint32_t index1 = static_cast(tIndex1); - uint32_t index2 = static_cast(tIndex2); + const uint32_t index0 = static_cast(tIndex0); + const uint32_t index1 = static_cast(tIndex1); + const uint32_t index2 = static_cast(tIndex2); const glm::vec3& vertex0 = positionView[index0]; const glm::vec3& vertex1 = positionView[index1]; const glm::vec3& vertex2 = positionView[index2]; - glm::vec3 triangleNormal = glm::cross(vertex1 - vertex0, vertex2 - vertex0); + const glm::vec3 triangleNormal = glm::cross(vertex1 - vertex0, vertex2 - vertex0); // Add the triangle normal to each vertex's accumulated normal. At the end // we will normalize the accumulated vertex normals to average. @@ -508,9 +508,9 @@ void generateSmoothNormals( const AccessorView& positionView, const std::optional& indexAccessor) { - size_t count = static_cast(positionView.size()); - size_t normalBufferStride = sizeof(glm::vec3); - size_t normalBufferSize = count * normalBufferStride; + const size_t count = static_cast(positionView.size()); + const size_t normalBufferStride = sizeof(glm::vec3); + const size_t normalBufferSize = count * normalBufferStride; std::vector normalByteBuffer(normalBufferSize); gsl::span normals( @@ -549,7 +549,7 @@ void generateSmoothNormals( // normalizes the accumulated vertex normals for (size_t i = 0; i < count; ++i) { - float lengthSquared = glm::length2(normals[i]); + const float lengthSquared = glm::length2(normals[i]); if (lengthSquared < 1e-8f) { normals[i] = glm::vec3(0.0f); } else { @@ -557,12 +557,12 @@ void generateSmoothNormals( } } - size_t normalBufferId = gltf.buffers.size(); + const size_t normalBufferId = gltf.buffers.size(); Buffer& normalBuffer = gltf.buffers.emplace_back(); normalBuffer.byteLength = static_cast(normalBufferSize); normalBuffer.cesium.data = std::move(normalByteBuffer); - size_t normalBufferViewId = gltf.bufferViews.size(); + const size_t normalBufferViewId = gltf.bufferViews.size(); BufferView& normalBufferView = gltf.bufferViews.emplace_back(); normalBufferView.buffer = static_cast(normalBufferId); normalBufferView.byteLength = static_cast(normalBufferSize); @@ -570,7 +570,7 @@ void generateSmoothNormals( normalBufferView.byteStride = static_cast(normalBufferStride); normalBufferView.target = BufferView::Target::ARRAY_BUFFER; - size_t normalAccessorId = gltf.accessors.size(); + const size_t normalAccessorId = gltf.accessors.size(); Accessor& normalAccessor = gltf.accessors.emplace_back(); normalAccessor.byteOffset = 0; normalAccessor.bufferView = static_cast(normalBufferViewId); @@ -644,8 +644,8 @@ void Model::generateMissingNormalsSmooth() { return; } - int positionAccessorId = positionIt->second; - AccessorView positionView(gltf_, positionAccessorId); + const int positionAccessorId = positionIt->second; + const AccessorView positionView(gltf_, positionAccessorId); if (positionView.status() != AccessorViewStatus::Valid) { return; } diff --git a/CesiumGltfReader/src/GltfReader.cpp b/CesiumGltfReader/src/GltfReader.cpp index 6382f4ed1..18b0f171c 100644 --- a/CesiumGltfReader/src/GltfReader.cpp +++ b/CesiumGltfReader/src/GltfReader.cpp @@ -75,10 +75,10 @@ namespace { * @return The string */ std::string toMagicString(uint32_t i) { - unsigned char c0 = static_cast(i & 0xFF); - unsigned char c1 = static_cast((i >> 8) & 0xFF); - unsigned char c2 = static_cast((i >> 16) & 0xFF); - unsigned char c3 = static_cast((i >> 24) & 0xFF); + const unsigned char c0 = static_cast(i & 0xFF); + const unsigned char c1 = static_cast((i >> 8) & 0xFF); + const unsigned char c2 = static_cast((i >> 16) & 0xFF); + const unsigned char c3 = static_cast((i >> 24) & 0xFF); std::stringstream stream; stream << c0 << c1 << c2 << c3 << " (0x" << std::hex << i << ")"; return stream.str(); @@ -120,7 +120,7 @@ ModelReaderResult readBinaryModel( {}}; } - gsl::span glbData = data.subspan(0, pHeader->length); + const gsl::span glbData = data.subspan(0, pHeader->length); const ChunkHeader* pJsonChunkHeader = reinterpret_cast(glbData.data() + sizeof(GlbHeader)); @@ -132,8 +132,8 @@ ModelReaderResult readBinaryModel( {}}; } - size_t jsonStart = sizeof(GlbHeader) + sizeof(ChunkHeader); - size_t jsonEnd = jsonStart + pJsonChunkHeader->chunkLength; + const size_t jsonStart = sizeof(GlbHeader) + sizeof(ChunkHeader); + const size_t jsonEnd = jsonStart + pJsonChunkHeader->chunkLength; if (jsonEnd > glbData.size()) { return { @@ -144,7 +144,7 @@ ModelReaderResult readBinaryModel( {}}; } - gsl::span jsonChunk = + const gsl::span jsonChunk = glbData.subspan(jsonStart, pJsonChunkHeader->chunkLength); gsl::span binaryChunk; @@ -159,8 +159,8 @@ ModelReaderResult readBinaryModel( {}}; } - size_t binaryStart = jsonEnd + sizeof(ChunkHeader); - size_t binaryEnd = binaryStart + pBinaryChunkHeader->chunkLength; + const size_t binaryStart = jsonEnd + sizeof(ChunkHeader); + const size_t binaryEnd = binaryStart + pBinaryChunkHeader->chunkLength; if (binaryEnd > glbData.size()) { return { @@ -193,7 +193,7 @@ ModelReaderResult readBinaryModel( return result; } - int64_t binaryChunkSize = static_cast(binaryChunk.size()); + const int64_t binaryChunkSize = static_cast(binaryChunk.size()); if (buffer.byteLength > binaryChunkSize || buffer.byteLength + 3 < binaryChunkSize) { result.errors.emplace_back("GLB binary chunk size does not match the " @@ -238,8 +238,8 @@ void postprocess( continue; } - gsl::span bufferSpan(buffer.cesium.data); - gsl::span bufferViewSpan = bufferSpan.subspan( + const gsl::span bufferSpan(buffer.cesium.data); + const gsl::span bufferViewSpan = bufferSpan.subspan( static_cast(bufferView.byteOffset), static_cast(bufferView.byteLength)); ImageReaderResult imageResult = context.reader.readImage(bufferViewSpan); diff --git a/CesiumGltfReader/src/ImageManipulation.cpp b/CesiumGltfReader/src/ImageManipulation.cpp index 8fbbc2566..082af21a6 100644 --- a/CesiumGltfReader/src/ImageManipulation.cpp +++ b/CesiumGltfReader/src/ImageManipulation.cpp @@ -16,7 +16,7 @@ void ImageManipulation::unsafeBlitImage( size_t sourceWidth, size_t sourceHeight, size_t bytesPerPixel) { - size_t bytesToCopyPerRow = bytesPerPixel * sourceWidth; + const size_t bytesToCopyPerRow = bytesPerPixel * sourceWidth; if (bytesToCopyPerRow == targetRowStride && targetRowStride == sourceRowStride) { @@ -60,11 +60,11 @@ bool ImageManipulation::blitImage( } size_t bytesPerPixel = size_t(target.bytesPerChannel * target.channels); - size_t bytesPerSourceRow = bytesPerPixel * size_t(source.width); + const size_t bytesPerSourceRow = bytesPerPixel * size_t(source.width); size_t bytesPerTargetRow = bytesPerPixel * size_t(target.width); - size_t requiredTargetSize = size_t(targetPixels.height) * bytesPerTargetRow; - size_t requiredSourceSize = size_t(sourcePixels.height) * bytesPerSourceRow; + const size_t requiredTargetSize = size_t(targetPixels.height) * bytesPerTargetRow; + const size_t requiredSourceSize = size_t(sourcePixels.height) * bytesPerSourceRow; if (target.pixelData.size() < requiredTargetSize || source.pixelData.size() < requiredSourceSize) { return false; diff --git a/CesiumGltfReader/src/decodeDataUrls.cpp b/CesiumGltfReader/src/decodeDataUrls.cpp index 05e3f6fba..5bb25e0c6 100644 --- a/CesiumGltfReader/src/decodeDataUrls.cpp +++ b/CesiumGltfReader/src/decodeDataUrls.cpp @@ -12,7 +12,7 @@ std::vector decodeBase64(gsl::span data) { CESIUM_TRACE("CesiumGltf::decodeBase64"); std::vector result(modp_b64_decode_len(data.size())); - size_t resultLength = modp_b64_decode( + const size_t resultLength = modp_b64_decode( reinterpret_cast(result.data()), reinterpret_cast(data.data()), data.size()); @@ -42,7 +42,7 @@ std::optional tryDecode(const std::string& uri) { return std::nullopt; } - size_t dataDelimeter = uri.find(',', dataPrefixLength); + const size_t dataDelimeter = uri.find(',', dataPrefixLength); if (dataDelimeter == std::string::npos) { return std::nullopt; } @@ -63,7 +63,7 @@ std::optional tryDecode(const std::string& uri) { result.mimeType.size() - base64IndicatorLength); } - gsl::span data( + const gsl::span data( reinterpret_cast(uri.data()) + dataDelimeter + 1, uri.size() - dataDelimeter - 1); diff --git a/CesiumGltfReader/src/decodeDraco.cpp b/CesiumGltfReader/src/decodeDraco.cpp index fad95563e..5a359df76 100644 --- a/CesiumGltfReader/src/decodeDraco.cpp +++ b/CesiumGltfReader/src/decodeDraco.cpp @@ -35,7 +35,7 @@ std::unique_ptr decodeBufferViewToDracoMesh( return nullptr; } - BufferView& bufferView = *pBufferView; + const BufferView& bufferView = *pBufferView; Buffer* pBuffer = Model::getSafe(&model.buffers, bufferView.buffer); if (!pBuffer) { @@ -54,7 +54,7 @@ std::unique_ptr decodeBufferViewToDracoMesh( return nullptr; } - gsl::span data( + const gsl::span data( buffer.cesium.data.data() + bufferView.byteOffset, static_cast(bufferView.byteLength)); @@ -141,7 +141,7 @@ void copyDecodedIndices( Buffer& indicesBuffer = model.buffers.emplace_back(); int64_t indexBytes = pIndicesAccessor->computeByteSizeOfComponent(); - int64_t indicesBytes = pIndicesAccessor->count * indexBytes; + const int64_t indicesBytes = pIndicesAccessor->count * indexBytes; indicesBuffer.cesium.data.resize(static_cast(indicesBytes)); indicesBuffer.byteLength = indicesBytes; @@ -218,9 +218,9 @@ void copyDecodedAttribute( bufferView.buffer = static_cast(model.buffers.size()); Buffer& buffer = model.buffers.emplace_back(); - int8_t numberOfComponents = pAccessor->computeNumberOfComponents(); - int64_t stride = numberOfComponents * pAccessor->computeByteSizeOfComponent(); - int64_t sizeBytes = pAccessor->count * stride; + const int8_t numberOfComponents = pAccessor->computeNumberOfComponents(); + const int64_t stride = numberOfComponents * pAccessor->computeByteSizeOfComponent(); + const int64_t sizeBytes = pAccessor->count * stride; buffer.cesium.data.resize(static_cast(sizeBytes)); buffer.byteLength = sizeBytes; @@ -229,9 +229,9 @@ void copyDecodedAttribute( bufferView.byteOffset = 0; pAccessor->byteOffset = 0; - auto doCopy = [pMesh, pAttribute, numberOfComponents](auto pOut) { + const auto doCopy = [pMesh, pAttribute, numberOfComponents](auto pOut) { for (draco::PointIndex i(0); i < pMesh->num_points(); ++i) { - draco::AttributeValueIndex valueIndex = pAttribute->mapped_index(i); + const draco::AttributeValueIndex valueIndex = pAttribute->mapped_index(i); pAttribute->ConvertValue(valueIndex, numberOfComponents, pOut); pOut += pAttribute->num_components(); } @@ -291,7 +291,7 @@ void decodePrimitive( continue; } - int32_t primitiveAttrIndex = primitiveAttrIt->second; + const int32_t primitiveAttrIndex = primitiveAttrIt->second; Accessor* pAccessor = Model::getSafe(&model.accessors, primitiveAttrIndex); if (!pAccessor) { readModel.warnings.emplace_back( @@ -299,7 +299,7 @@ void decodePrimitive( continue; } - int32_t dracoAttrIndex = attribute.second; + const int32_t dracoAttrIndex = attribute.second; const draco::PointAttribute* pAttribute = pMesh->GetAttributeByUniqueId(static_cast(dracoAttrIndex)); if (pAttribute == nullptr) { diff --git a/CesiumIonClient/src/Connection.cpp b/CesiumIonClient/src/Connection.cpp index fb8cd2408..f2ee7153d 100644 --- a/CesiumIonClient/src/Connection.cpp +++ b/CesiumIonClient/src/Connection.cpp @@ -29,9 +29,9 @@ using namespace CesiumUtility; namespace { std::string encodeBase64(const std::vector& bytes) { - size_t count = modp_b64_encode_len(bytes.size()); + const size_t count = modp_b64_encode_len(bytes.size()); std::string result(count, 0); - size_t actualLength = modp_b64_encode( + const size_t actualLength = modp_b64_encode( result.data(), reinterpret_cast(bytes.data()), bytes.size()); @@ -39,7 +39,7 @@ std::string encodeBase64(const std::vector& bytes) { // Convert to a URL-friendly form of Base64 according to the algorithm // in [RFC7636 Appendix A](https://tools.ietf.org/html/rfc7636#appendix-A) - size_t firstPaddingIndex = result.find('='); + const size_t firstPaddingIndex = result.find('='); if (firstPaddingIndex != std::string::npos) { result.erase(result.begin() + int64_t(firstPaddingIndex), result.end()); } @@ -103,7 +103,7 @@ static std::string createAuthorizationErrorHtml( std::shared_ptr pServer = std::make_shared(); - int port = pServer->bind_to_any_port("127.0.0.1"); + const int port = pServer->bind_to_any_port("127.0.0.1"); std::string redirectUrl = Uri::resolve("http://127.0.0.1:" + std::to_string(port), redirectPath); @@ -203,7 +203,7 @@ static std::string createAuthorizationErrorHtml( createSuccessHtml(friendlyApplicationName), "text/html"); promise.resolve(std::move(connection)); - } catch (std::exception& exception) { + } catch (const std::exception& exception) { response.set_content( createAuthorizationErrorHtml(friendlyApplicationName, exception), "text/html"); @@ -325,7 +325,7 @@ CesiumAsync::Future> Connection::me() const { JsonHelpers::getBoolOrDefault(d, "emailVerified", false); result.avatar = JsonHelpers::getStringOrDefault(d, "avatar", ""); - auto storageIt = d.FindMember("storage"); + const auto storageIt = d.FindMember("storage"); if (storageIt == d.MemberEnd()) { result.storage.available = 0; result.storage.total = 0; @@ -394,7 +394,7 @@ CesiumAsync::Future> Connection::assets() const { result.link = JsonHelpers::getStringOrDefault(d, "link", ""); - auto itemsIt = d.FindMember("items"); + const auto itemsIt = d.FindMember("items"); if (itemsIt != d.MemberEnd() && itemsIt->value.IsArray()) { const rapidjson::Value& items = itemsIt->value; result.items.resize(items.Size()); @@ -423,7 +423,7 @@ static Token tokenFromJson(const rapidjson::Value& json) { token.lastUsed = JsonHelpers::getStringOrDefault(json, "lastUsed", ""); token.scopes = JsonHelpers::getStrings(json, "scopes"); - auto assetsIt = json.FindMember("assets"); + const auto assetsIt = json.FindMember("assets"); if (assetsIt != json.MemberEnd()) { token.assets = JsonHelpers::getInt64s(json, "assets"); } else { @@ -546,7 +546,7 @@ CesiumAsync::Future> Connection::createToken( } writer.EndObject(); - gsl::span tokenBytes( + const gsl::span tokenBytes( reinterpret_cast(tokenBuffer.GetString()), tokenBuffer.GetSize()); return this->_pAssetAccessor @@ -610,7 +610,7 @@ CesiumAsync::Future> Connection::createToken( writer.String(codeVerifier.c_str(), rapidjson::SizeType(codeVerifier.size())); writer.EndObject(); - gsl::span payload( + const gsl::span payload( reinterpret_cast(postBuffer.GetString()), postBuffer.GetSize()); diff --git a/CesiumJsonWriter/src/JsonWriter.cpp b/CesiumJsonWriter/src/JsonWriter.cpp index 488293b9f..fe8c89f0c 100644 --- a/CesiumJsonWriter/src/JsonWriter.cpp +++ b/CesiumJsonWriter/src/JsonWriter.cpp @@ -138,7 +138,7 @@ std::string_view JsonWriter::toStringView() { } std::vector JsonWriter::toBytes() { - auto view = this->toStringView(); + const auto view = this->toStringView(); std::vector result(view.size(), std::byte(0)); std::uint8_t* u8Pointer = reinterpret_cast(result.data()); std::copy(view.begin(), view.end(), u8Pointer); diff --git a/CesiumJsonWriter/src/PrettyJsonWriter.cpp b/CesiumJsonWriter/src/PrettyJsonWriter.cpp index e46ab3a11..ced314e22 100644 --- a/CesiumJsonWriter/src/PrettyJsonWriter.cpp +++ b/CesiumJsonWriter/src/PrettyJsonWriter.cpp @@ -155,7 +155,7 @@ std::string_view PrettyJsonWriter::toStringView() { } std::vector PrettyJsonWriter::toBytes() { - auto view = this->toStringView(); + const auto view = this->toStringView(); std::vector result(view.size(), std::byte(0)); std::uint8_t* u8Pointer = reinterpret_cast(result.data()); std::copy(view.begin(), view.end(), u8Pointer); diff --git a/CesiumUtility/include/CesiumUtility/Math.h b/CesiumUtility/include/CesiumUtility/Math.h index b5c464deb..a79aad1ea 100644 --- a/CesiumUtility/include/CesiumUtility/Math.h +++ b/CesiumUtility/include/CesiumUtility/Math.h @@ -184,7 +184,7 @@ class CESIUMUTILITY_API Math final { double right, double relativeEpsilon, double absoluteEpsilon) noexcept { - double diff = glm::abs(left - right); + const double diff = glm::abs(left - right); return diff <= absoluteEpsilon || diff <= relativeEpsilonToAbsolute(left, right, relativeEpsilon); } @@ -218,7 +218,7 @@ class CESIUMUTILITY_API Math final { const glm::vec& right, double relativeEpsilon, double absoluteEpsilon) noexcept { - glm::vec diff = glm::abs(left - right); + const glm::vec diff = glm::abs(left - right); return glm::lessThanEqual(diff, glm::vec(absoluteEpsilon)) == glm::vec(true) || glm::lessThanEqual( @@ -277,7 +277,7 @@ class CESIUMUTILITY_API Math final { * @returns The angle in the range [0, `Math::TWO_PI`]. */ static double zeroToTwoPi(double angle) noexcept { - double mod = Math::mod(angle, Math::TWO_PI); + const double mod = Math::mod(angle, Math::TWO_PI); if (glm::abs(mod) < Math::EPSILON14 && glm::abs(angle) > Math::EPSILON14) { return Math::TWO_PI; } @@ -382,9 +382,9 @@ class CESIUMUTILITY_API Math final { * @snippet TestMath.cpp convertLongitudeRange */ static double convertLongitudeRange(double angle) noexcept { - double twoPi = Math::TWO_PI; + const double twoPi = Math::TWO_PI; - double simplified = angle - glm::floor(angle / twoPi) * twoPi; + const double simplified = angle - glm::floor(angle / twoPi) * twoPi; if (simplified < -Math::ONE_PI) { return simplified + twoPi; @@ -407,8 +407,8 @@ class CESIUMUTILITY_API Math final { * @return The rounded value. */ static double roundUp(double value, double tolerance) noexcept { - double up = glm::ceil(value); - double down = glm::floor(value); + const double up = glm::ceil(value); + const double down = glm::floor(value); if (value - down < tolerance) { return down; } else { @@ -427,8 +427,8 @@ class CESIUMUTILITY_API Math final { * @return The rounded value. */ static double roundDown(double value, double tolerance) noexcept { - double up = glm::ceil(value); - double down = glm::floor(value); + const double up = glm::ceil(value); + const double down = glm::floor(value); if (up - value < tolerance) { return up; } else { diff --git a/CesiumUtility/src/JsonHelpers.cpp b/CesiumUtility/src/JsonHelpers.cpp index 35bf70d18..a29850d94 100644 --- a/CesiumUtility/src/JsonHelpers.cpp +++ b/CesiumUtility/src/JsonHelpers.cpp @@ -6,7 +6,7 @@ namespace CesiumUtility { std::optional JsonHelpers::getScalarProperty( const rapidjson::Value& tileJson, const std::string& key) { - auto it = tileJson.FindMember(key.c_str()); + const auto it = tileJson.FindMember(key.c_str()); if (it == tileJson.MemberEnd() || !it->value.IsNumber()) { return std::nullopt; } @@ -17,7 +17,7 @@ std::optional JsonHelpers::getScalarProperty( std::optional JsonHelpers::getTransformProperty( const rapidjson::Value& tileJson, const std::string& key) { - auto it = tileJson.FindMember(key.c_str()); + const auto it = tileJson.FindMember(key.c_str()); if (it == tileJson.MemberEnd() || !it->value.IsArray() || it->value.Size() < 16) { return std::nullopt; @@ -58,7 +58,7 @@ std::optional> JsonHelpers::getDoubles( const rapidjson::Value& json, int32_t expectedSize, const std::string& key) { - auto it = json.FindMember(key.c_str()); + const auto it = json.FindMember(key.c_str()); if (it == json.MemberEnd()) { return std::nullopt; } @@ -86,7 +86,7 @@ std::string JsonHelpers::getStringOrDefault( const rapidjson::Value& json, const std::string& key, const std::string& defaultValue) { - auto it = json.FindMember(key.c_str()); + const auto it = json.FindMember(key.c_str()); return it == json.MemberEnd() ? defaultValue : JsonHelpers::getStringOrDefault(it->value, defaultValue); @@ -105,7 +105,7 @@ double JsonHelpers::getDoubleOrDefault( const rapidjson::Value& json, const std::string& key, double defaultValue) { - auto it = json.FindMember(key.c_str()); + const auto it = json.FindMember(key.c_str()); return it == json.MemberEnd() ? defaultValue : JsonHelpers::getDoubleOrDefault(it->value, defaultValue); @@ -124,7 +124,7 @@ uint32_t JsonHelpers::getUint32OrDefault( const rapidjson::Value& json, const std::string& key, uint32_t defaultValue) { - auto it = json.FindMember(key.c_str()); + const auto it = json.FindMember(key.c_str()); return it == json.MemberEnd() ? defaultValue : JsonHelpers::getUint32OrDefault(it->value, defaultValue); @@ -143,7 +143,7 @@ int32_t JsonHelpers::getInt32OrDefault( const rapidjson::Value& json, const std::string& key, int32_t defaultValue) { - auto it = json.FindMember(key.c_str()); + const auto it = json.FindMember(key.c_str()); return it == json.MemberEnd() ? defaultValue : JsonHelpers::getInt32OrDefault(it->value, defaultValue); @@ -162,7 +162,7 @@ uint64_t JsonHelpers::getUint64OrDefault( const rapidjson::Value& json, const std::string& key, uint64_t defaultValue) { - auto it = json.FindMember(key.c_str()); + const auto it = json.FindMember(key.c_str()); return it == json.MemberEnd() ? defaultValue : JsonHelpers::getUint64OrDefault(it->value, defaultValue); @@ -181,7 +181,7 @@ int64_t JsonHelpers::getInt64OrDefault( const rapidjson::Value& json, const std::string& key, int64_t defaultValue) { - auto it = json.FindMember(key.c_str()); + const auto it = json.FindMember(key.c_str()); return it == json.MemberEnd() ? defaultValue : JsonHelpers::getInt64OrDefault(it->value, defaultValue); @@ -200,7 +200,7 @@ bool JsonHelpers::getBoolOrDefault( const rapidjson::Value& json, const std::string& key, bool defaultValue) { - auto it = json.FindMember(key.c_str()); + const auto it = json.FindMember(key.c_str()); return it == json.MemberEnd() ? defaultValue : JsonHelpers::getBoolOrDefault(it->value, defaultValue); @@ -219,7 +219,7 @@ std::vector JsonHelpers::getStrings(const rapidjson::Value& json, const std::string& key) { std::vector result; - auto it = json.FindMember(key.c_str()); + const auto it = json.FindMember(key.c_str()); if (it != json.MemberEnd() && it->value.IsArray()) { const auto& valueJson = it->value; @@ -240,7 +240,7 @@ std::vector JsonHelpers::getInt64s(const rapidjson::Value& json, const std::string& key) { std::vector result; - auto it = json.FindMember(key.c_str()); + const auto it = json.FindMember(key.c_str()); if (it != json.MemberEnd() && it->value.IsArray()) { const auto& valueJson = it->value; diff --git a/CesiumUtility/src/Uri.cpp b/CesiumUtility/src/Uri.cpp index 3e49383e5..4a8260a73 100644 --- a/CesiumUtility/src/Uri.cpp +++ b/CesiumUtility/src/Uri.cpp @@ -114,7 +114,7 @@ std::string Uri::substituteTemplateParameters( // Find the end of this parameter ++nextPos; - size_t endPos = templateUri.find('}', nextPos); + const size_t endPos = templateUri.find('}', nextPos); if (endPos == std::string::npos) { throw std::runtime_error("Unclosed template parameter"); }