From 08f8bf69ecdb1ad26b264cba52e2d0ac712ee129 Mon Sep 17 00:00:00 2001 From: Fabian Klebert Date: Tue, 21 Jan 2025 12:32:28 +0100 Subject: [PATCH 1/6] ci: upgrade download artifact version --- .github/workflows/deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 96109ed..e967bf0 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -14,7 +14,7 @@ jobs: - name: Fetch # Use official download-artifact action once fixed: # https://github.com/actions/download-artifact/issues/3 - uses: dawidd6/action-download-artifact@v2 + uses: dawidd6/action-download-artifact@v6 with: workflow: cmake.yaml name: mapget-py${{ matrix.python-version }}-${{ matrix.os }} From 218263d1f2fd5e234975321b5c1af6f82eb4e022 Mon Sep 17 00:00:00 2001 From: Wagram Airiian Date: Wed, 22 Jan 2025 12:12:48 +0100 Subject: [PATCH 2/6] Allow to set legal information on the tile. --- libs/model/include/mapget/model/layer.h | 7 +++++++ libs/model/src/featurelayer.cpp | 4 ++-- libs/model/src/layer.cpp | 21 +++++++++++++++++++++ libs/model/src/validity.cpp | 12 ++++++------ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/libs/model/include/mapget/model/layer.h b/libs/model/include/mapget/model/layer.h index 07ee5d3..4d7bf9d 100644 --- a/libs/model/include/mapget/model/layer.h +++ b/libs/model/include/mapget/model/layer.h @@ -169,6 +169,12 @@ class TileLayer [[nodiscard]] nlohmann::json info() const; void setInfo(std::string const& k, nlohmann::json const& v); + /** + * Getter and setter for this tile's copyright information. + */ + [[nodiscard]] std::optional legalInfo() const; + void setLegalInfo(const std::string& legalInfoString); + /** Serialization */ virtual void write(std::ostream& outputStream); virtual nlohmann::json toJson() const; @@ -183,6 +189,7 @@ class TileLayer std::chrono::time_point timestamp_; std::optional ttl_; nlohmann::json info_; + std::optional legalInfo_; // Copyright-related information }; } diff --git a/libs/model/src/featurelayer.cpp b/libs/model/src/featurelayer.cpp index bc35e73..9866d4f 100644 --- a/libs/model/src/featurelayer.cpp +++ b/libs/model/src/featurelayer.cpp @@ -91,7 +91,7 @@ struct TileFeatureLayer::Impl { /** * Indexing of features by their id hash. The hash-feature pairs are kept * in a vector, which is kept in a sorted state. This allows finding a - * feature by it's id in O(log(n)) time. + * feature by its id in O(log(n)) time. */ struct FeatureAddrWithIdHash { @@ -780,7 +780,7 @@ nlohmann::json TileFeatureLayer::toJson() const features.push_back(f->toJson()); return nlohmann::json::object({ {"type", "FeatureCollection"}, - {"features", features}, + {"features", features} }); } diff --git a/libs/model/src/layer.cpp b/libs/model/src/layer.cpp index 04c09d4..397b54f 100644 --- a/libs/model/src/layer.cpp +++ b/libs/model/src/layer.cpp @@ -133,6 +133,13 @@ TileLayer::TileLayer( error_ = ""; // Tell the optional that it has a value. s.text1b(*error_, std::numeric_limits::max()); } + + bool hasLegalInfo = false; + s.value1b(hasLegalInfo); + if (hasLegalInfo) { + legalInfo_ = ""; // Tell the optional that it has a value. + s.text1b(*legalInfo_, std::numeric_limits::max()); + } } TileId TileLayer::tileId() const { @@ -171,6 +178,11 @@ nlohmann::json TileLayer::info() const { return info_; } +std::optional TileLayer::legalInfo() const +{ + return legalInfo_; +} + void TileLayer::setTileId(const TileId& id) { tileId_ = id; } @@ -207,6 +219,11 @@ void TileLayer::setInfo(std::string const& k, nlohmann::json const& v) { info_[k] = v; } +void TileLayer::setLegalInfo(const std::string& legalInfoString) +{ + legalInfo_ = legalInfoString; +} + void TileLayer::write(std::ostream& outputStream) { using namespace std::chrono; @@ -226,6 +243,10 @@ void TileLayer::write(std::ostream& outputStream) s.value1b(error_.has_value()); if (error_) s.text1b(*error_, std::numeric_limits::max()); + s.value1b(legalInfo_.has_value()); + if (legalInfo_.has_value()) { + s.text1b(legalInfo_.value(), std::numeric_limits::max()); + } } MapTileKey TileLayer::id() const diff --git a/libs/model/src/validity.cpp b/libs/model/src/validity.cpp index deddee3..b1f7f0f 100644 --- a/libs/model/src/validity.cpp +++ b/libs/model/src/validity.cpp @@ -27,16 +27,16 @@ model_ptr Validity::featureId() const if (!data_->featureAddress_) { return {}; } - return model().resolveFeatureId(*ModelNode::Ptr::make(model_, data_->featureAddress_)); + return model().resolveFeatureId(*Ptr::make(model_, data_->featureAddress_)); } -void Validity::setFeatureId(model_ptr feature) +void Validity::setFeatureId(model_ptr featureId) { - if (!feature) { + if (!featureId) { data_->featureAddress_ = {}; return; } - data_->featureAddress_ = feature->addr(); + data_->featureAddress_ = featureId->addr(); } Validity::Validity(Validity::Data* data, @@ -254,7 +254,7 @@ SelfContainedGeometry Validity::computeGeometry( if (feature) { geometryCollection = feature->geomOrNull(); } else { - mapget::log().warn("Could not find feature by its ID {}", featureId()->toString()); + log().warn("Could not find feature by its ID {}", featureId()->toString()); } } @@ -312,7 +312,7 @@ SelfContainedGeometry Validity::computeGeometry( return {points, points.size() > 1 ? GeomType::Line : GeomType::Points}; } - // Handle BufferOffset (a range of the goemetry bound by two indices). + // Handle BufferOffset (a range of the geometry bound by two indices). if (offsetType == BufferOffset) { auto startPointIndex = static_cast(startPoint.x); if (startPointIndex >= geometry->numPoints()) { From ed62fe8bd8871f368c94eeef765ec731fa974a75 Mon Sep 17 00:00:00 2001 From: Wagram Airiian Date: Thu, 23 Jan 2025 17:23:07 +0100 Subject: [PATCH 3/6] Update GitHub actions --- .github/workflows/cmake.yaml | 8 ++++---- .github/workflows/coverage.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cmake.yaml b/.github/workflows/cmake.yaml index 8833dae..cfd9576 100644 --- a/.github/workflows/cmake.yaml +++ b/.github/workflows/cmake.yaml @@ -17,7 +17,7 @@ jobs: ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true SCCACHE_GHA_ENABLED: "true" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: submodules: recursive - name: Run sccache-cache @@ -52,7 +52,7 @@ jobs: . ./venv/bin/activate ctest --preset conan-release -C Release --verbose --no-tests=error - name: Deploy - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: mapget-py${{ matrix.python-version }}-ubuntu-latest path: build/Release/bin/wheel/*.whl @@ -65,7 +65,7 @@ jobs: env: SCCACHE_GHA_ENABLED: "true" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: submodules: recursive - name: Run sccache-cache @@ -118,7 +118,7 @@ jobs: -DMAPGET_BUILD_EXAMPLES=YES cmake --build --preset conan-release - name: Deploy - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: mapget-py${{ matrix.python-version }}-${{ matrix.os }} path: build/**/bin/wheel/*.whl diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 4d0da77..662bb12 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -13,7 +13,7 @@ jobs: env: SCCACHE_GHA_ENABLED: "true" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true - name: Run sccache-cache @@ -58,7 +58,7 @@ jobs: --gcov-ignore-parse-errors=negative_hits.warn_once_per_file - name: Publish Coverage HTML - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: Test Coverage path: coverage From 17e4c5fc3fde81b93ec954179884280e22884dd8 Mon Sep 17 00:00:00 2001 From: Wagram Airiian Date: Thu, 23 Jan 2025 17:41:10 +0100 Subject: [PATCH 4/6] Bump version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d88384..81f796c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_policy(SET CMP0117 NEW) project(mapget CXX) -set(MAPGET_VERSION 2024.5.0) +set(MAPGET_VERSION 2025.1.0) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) From 3d5efdb3db708065bce3a61de77e6268280ce87b Mon Sep 17 00:00:00 2001 From: Wagram Airiian Date: Thu, 23 Jan 2025 18:20:29 +0100 Subject: [PATCH 5/6] Add percentage position method for combined geometries --- libs/model/include/mapget/model/geometry.h | 13 ++++++++++ libs/model/src/geometry.cpp | 28 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/libs/model/include/mapget/model/geometry.h b/libs/model/include/mapget/model/geometry.h index 48da04a..6e62980 100644 --- a/libs/model/include/mapget/model/geometry.h +++ b/libs/model/include/mapget/model/geometry.h @@ -113,6 +113,19 @@ class Geometry final : public simfil::MandatoryDerivedModelNodeBase pointsFromLengthBound(double start, std::optional end) const; + /** + * Return percentage position point on the entire combined line geometries. + * @param geoms vector of line geometries to determine the position on their entire length. + * @param lengths vector of each geomtery length. + * @param numBits number of bits to store the percentage value. + * @param position percentage position on the geometries. + */ + [[nodiscard]] static Point percentagePositionFromGeometries( + std::vector> const& geoms, + std::vector const& lengths, + uint32_t numBits, + double position); + /** * Turn the points and type from this geometry into a self-contained * struct which can be passed around. diff --git a/libs/model/src/geometry.cpp b/libs/model/src/geometry.cpp index 50d64cd..016d9c1 100644 --- a/libs/model/src/geometry.cpp +++ b/libs/model/src/geometry.cpp @@ -10,10 +10,14 @@ #include #include +#include +#include #include #include #include +#include "mapget/log.h" + static const std::string_view GeometryCollectionStr("GeometryCollection"); static const std::string_view MultiPointStr("MultiPoint"); static const std::string_view LineStringStr("LineString"); @@ -433,6 +437,30 @@ std::vector Geometry::pointsFromLengthBound(double start, std::optional> const& geoms, + std::vector const& lengths, uint32_t numBits, double position) +{ + double totalLength = std::reduce(std::execution::par_unseq, lengths.begin(), lengths.end(), 0.0); + auto maxPos = static_cast((1 << numBits) - 1); + auto percentagePosition = (position / maxPos) * totalLength; + Point positionPoint; + for (size_t i = 0; i < lengths.size(); i++) { + if (lengths[i] < percentagePosition) { + percentagePosition -= lengths[i]; + } + else { + auto points = geoms[i]->pointsFromLengthBound(percentagePosition, std::nullopt); + if (points.empty()) { + log().error("Could not find any points from length bound"); + break; + } + positionPoint = points[0]; + break; + } + } + return positionPoint; +} + /** ModelNode impls. for PolygonNode */ PolygonNode::PolygonNode(ModelConstPtr pool, ModelNodeAddress const& a) From b1274d60501c1978928dedf576e3055628d394d7 Mon Sep 17 00:00:00 2001 From: Wagram Airiian Date: Thu, 23 Jan 2025 18:36:43 +0100 Subject: [PATCH 6/6] Use std::accumulate --- libs/model/src/geometry.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libs/model/src/geometry.cpp b/libs/model/src/geometry.cpp index 016d9c1..47f382d 100644 --- a/libs/model/src/geometry.cpp +++ b/libs/model/src/geometry.cpp @@ -3,21 +3,16 @@ #include "simfil/model/nodes.h" #include "simfil/model/string-pool.h" #include "sourcedatareference.h" -#include "sourceinfo.h" #include "stringpool.h" -#include "validity.h" #include "pointnode.h" #include #include -#include #include #include #include #include -#include "mapget/log.h" - static const std::string_view GeometryCollectionStr("GeometryCollection"); static const std::string_view MultiPointStr("MultiPoint"); static const std::string_view LineStringStr("LineString"); @@ -440,7 +435,7 @@ std::vector Geometry::pointsFromLengthBound(double start, std::optional> const& geoms, std::vector const& lengths, uint32_t numBits, double position) { - double totalLength = std::reduce(std::execution::par_unseq, lengths.begin(), lengths.end(), 0.0); + double totalLength = std::accumulate(lengths.begin(), lengths.end(), 0.0); auto maxPos = static_cast((1 << numBits) - 1); auto percentagePosition = (position / maxPos) * totalLength; Point positionPoint; @@ -451,7 +446,6 @@ Point Geometry::percentagePositionFromGeometries(std::vector else { auto points = geoms[i]->pointsFromLengthBound(percentagePosition, std::nullopt); if (points.empty()) { - log().error("Could not find any points from length bound"); break; } positionPoint = points[0];