Skip to content

Commit

Permalink
Merge pull request #65 from ndsev/move-simfil-ext-geo-to-mapget
Browse files Browse the repository at this point in the history
Move simfil ext-geo to mapget
  • Loading branch information
josephbirkner committed Jun 19, 2024
2 parents 1705d77 + 8f4f3bd commit 9749caf
Show file tree
Hide file tree
Showing 31 changed files with 3,181 additions and 112 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ set(SIMFIL_WITH_MODEL_JSON YES)
if (NOT TARGET simfil)
FetchContent_Declare(simfil
GIT_REPOSITORY "https://github.com/Klebert-Engineering/simfil.git"
GIT_TAG "5af9ada73898c952657d1bf1358205e54e82a584"
GIT_TAG "v0.2.0"
GIT_SHALLOW ON)
FetchContent_MakeAvailable(simfil)
endif()
Expand Down
3 changes: 2 additions & 1 deletion libs/http-service/include/mapget/http-service/http-service.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class HttpService : public HttpServer, public Service
explicit HttpService(Cache::Ptr cache = std::make_shared<MemCache>());
~HttpService() override;

private:
protected:
void setup(httplib::Server& server) override;

private:
struct Impl;
friend struct Impl;
std::unique_ptr<Impl> impl_;
Expand Down
9 changes: 8 additions & 1 deletion libs/logging/include/mapget/log.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "spdlog/spdlog.h"
#include "fmt/core.h"
#include "simfil/exception-handler.h"

namespace mapget
Expand Down Expand Up @@ -35,4 +36,10 @@ template<typename ExceptionType=std::runtime_error, typename... Args>
simfil::raise<ExceptionType>(exceptionInstance);
}

}
template <class ExceptionType = std::runtime_error, class... Args>
[[noreturn]] void raiseFmt(std::string_view fmt, Args&&... args)
{
raise<ExceptionType>(fmt::vformat(fmt, fmt::make_format_args(std::forward<Args>(args)...)));
}

}
6 changes: 5 additions & 1 deletion libs/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ add_library(mapget-model STATIC
include/mapget/model/featureid.h
include/mapget/model/stream.h
include/mapget/model/relation.h
include/mapget/model/geometry.h
include/mapget/model/simfil-geometry.h

src/fields.cpp
src/layer.cpp
Expand All @@ -22,8 +24,10 @@ add_library(mapget-model STATIC
src/attrlayer.cpp
src/tileid.cpp
src/featureid.cpp
src/relation.cpp
src/stream.cpp
src/relation.cpp)
src/geometry.cpp
src/simfil-geometry.cpp)

target_include_directories(mapget-model
PUBLIC
Expand Down
4 changes: 3 additions & 1 deletion libs/model/include/mapget/model/attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace mapget
{

class Geometry;

/**
* Represents a feature attribute which belongs to an
* AttributeLayer, and may have typed `direction` and
Expand Down Expand Up @@ -79,4 +81,4 @@ class Attribute : public simfil::ProceduralObject<2, Attribute>
Data* data_ = nullptr;
};

}
}
15 changes: 9 additions & 6 deletions libs/model/include/mapget/model/feature.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once

#include "simfil/model/nodes.h"

#include "attr.h"
#include "attrlayer.h"
#include "featureid.h"
#include "tileid.h"
#include "relation.h"
#include "geometry.h"

#include "nlohmann/json.hpp"

Expand Down Expand Up @@ -84,19 +87,19 @@ class Feature : public simfil::MandatoryDerivedModelNodeBase<TileFeatureLayer>
[[nodiscard]] model_ptr<Object> attributes() const;

/** Add a point to the feature. */
void addPoint(Point const& p);
void addPoint(Point<> const& p);

/** Add multiple points to the feature. */
void addPoints(std::vector<Point> const& points);
void addPoints(std::vector<Point<>> const& points);

/** Add a line to the feature. */
void addLine(std::vector<Point> const& points);
void addLine(std::vector<Point<>> const& points);

/** Add a mesh to the feature. Points must be a multiple of 3. */
void addMesh(std::vector<Point> const& points);
void addMesh(std::vector<Point<>> const& points);

/** Add a polygon to the feature. Will be auto-closed. Must not have holes. */
void addPoly(std::vector<Point> const& points);
void addPoly(std::vector<Point<>> const& points);

/**
* Evaluate a filter expression on this feature, get the first (or Null) result.
Expand Down Expand Up @@ -217,4 +220,4 @@ class Feature : public simfil::MandatoryDerivedModelNodeBase<TileFeatureLayer>
};
};

} // namespace mapget
} // namespace mapget
7 changes: 2 additions & 5 deletions libs/model/include/mapget/model/featureid.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "simfil/model/nodes.h"
#include <functional>
#include "info.h"
#include "sfl/small_vector.hpp"

namespace mapget
{
Expand All @@ -15,9 +15,6 @@ using model_ptr = simfil::shared_model_ptr<T>;

using Object = simfil::Object;
using Array = simfil::Array;
using GeometryCollection = simfil::GeometryCollection;
using Geometry = simfil::Geometry;
using GeomType = simfil::Geometry::GeomType;

/**
* Unique feature ID
Expand Down Expand Up @@ -73,4 +70,4 @@ class FeatureId : public simfil::MandatoryDerivedModelNodeBase<TileFeatureLayer>
model_ptr<Object> fields_;
};

}
}
46 changes: 45 additions & 1 deletion libs/model/include/mapget/model/featurelayer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "simfil/simfil.h"
#include "simfil/model/model.h"
#include "simfil/model/arena.h"
#include "simfil/environment.h"

Expand All @@ -10,6 +9,7 @@
#include "feature.h"
#include "attrlayer.h"
#include "relation.h"
#include "geometry.h"

namespace mapget
{
Expand All @@ -30,8 +30,17 @@ class TileFeatureLayer : public TileLayer, public simfil::ModelPool
friend class Feature;
friend class FeatureId;
friend class Relation;
friend class Attribute;
friend class AttributeLayer;
friend class AttributeLayerList;
friend class Geometry;
friend class GeometryCollection;
friend class VertexNode;
friend class VertexBufferNode;
friend class PolygonNode;
friend class MeshNode;
friend class MeshTriangleCollectionNode;
friend class LinearRingNode;

public:
/**
Expand Down Expand Up @@ -121,6 +130,21 @@ class TileFeatureLayer : public TileLayer, public simfil::ModelPool
*/
model_ptr<AttributeLayer> newAttributeLayer(size_t initialCapacity=8);

/**
* Create a new geometry collection.
*/
model_ptr<GeometryCollection> newGeometryCollection(size_t initialCapacity=1);

/**
* Create a new geometry.
*/
model_ptr<Geometry> newGeometry(Geometry::GeomType geomType, size_t initialCapacity=1);

/**
* Create a new geometry view.
*/
model_ptr<Geometry> newGeometryView(Geometry::GeomType geomType, uint32_t offset, uint32_t size, const model_ptr<Geometry>& base);

/**
* Return type for begin() and end() methods to support range-based
* for-loops to iterate over all features in a TileFeatureLayer.
Expand Down Expand Up @@ -224,6 +248,15 @@ class TileFeatureLayer : public TileLayer, public simfil::ModelPool
model_ptr<Feature> resolveFeature(simfil::ModelNode const& n) const;
model_ptr<FeatureId> resolveFeatureId(simfil::ModelNode const& n) const;
model_ptr<Relation> resolveRelation(simfil::ModelNode const& n) const;
model_ptr<VertexNode> resolvePoints(simfil::ModelNode const& n) const;
model_ptr<VertexBufferNode> resolvePointBuffers(simfil::ModelNode const& n) const;
model_ptr<Geometry> resolveGeometry(simfil::ModelNode const& n) const;
model_ptr<GeometryCollection> resolveGeometryCollection(simfil::ModelNode const& n) const;
model_ptr<MeshNode> resolveMesh(simfil::ModelNode const& n) const;
model_ptr<MeshTriangleCollectionNode> resolveMeshTriangleCollection(simfil::ModelNode const& n) const;
model_ptr<LinearRingNode> resolveMeshTriangleLinearRing(simfil::ModelNode const& n) const;
model_ptr<PolygonNode> resolvePolygon(simfil::ModelNode const& n) const;
model_ptr<LinearRingNode> resolveLinearRing(simfil::ModelNode const& n) const;

protected:
/**
Expand All @@ -238,6 +271,15 @@ class TileFeatureLayer : public TileLayer, public simfil::ModelPool
AttributeLayers,
AttributeLayerLists,
Relations,
Points,
PointBuffers,
Geometries,
GeometryCollections,
Mesh,
MeshTriangleCollection,
MeshTriangleLinearRing, // LinearRing with fixed size 3
Polygon,
LinearRing,
};

/** Get the primary id composition for the given feature type. */
Expand All @@ -253,6 +295,8 @@ class TileFeatureLayer : public TileLayer, public simfil::ModelPool
*/
void resolve(const simfil::ModelNode &n, const ResolveFn &cb) const override;

Geometry::Storage& vertexBufferStorage();

struct Impl;
std::unique_ptr<Impl> impl_;
};
Expand Down
9 changes: 8 additions & 1 deletion libs/model/include/mapget/model/fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ struct Fields : public simfil::Fields
NameStr,
TargetStr,
SourceValidityStr,
TargetValidityStr
TargetValidityStr,
LonStr,
LatStr,
GeometryStr,
GeometriesStr,
TypeStr,
CoordinatesStr,
ElevationStr,
};

explicit Fields(const std::string_view& nodeId);
Expand Down
Loading

0 comments on commit 9749caf

Please sign in to comment.