This commit is contained in:
Zacharias Knudsen 2024-11-25 09:17:29 +01:00
parent bcc28cff3d
commit 1084ee8c49
No known key found for this signature in database

View File

@ -32,56 +32,6 @@ namespace ErrorCodes
extern const int ILLEGAL_COLUMN; extern const int ILLEGAL_COLUMN;
} }
class GeoPolygonContainer {
private:
// Store the polygon data
std::vector<LatLng> mainLoopVerts;
std::vector<std::vector<LatLng>> holeVerts;
// Temporary storage for C-style structs
mutable GeoLoop mutableMainLoop;
mutable GeoPolygon mutablePolygon;
mutable std::vector<GeoLoop> mutableHoles;
public:
// Constructor to create from C++ data
GeoPolygonContainer(const std::vector<LatLng>& mainLoop,
const std::vector<std::vector<LatLng>>& holes = {})
: mainLoopVerts(mainLoop), holeVerts(holes) {}
// Method to get C-style GeoPolygon pointer
const GeoPolygon* unwrap() const {
// Prepare main loop
mutableMainLoop = {
static_cast<int>(mainLoopVerts.size()),
const_cast<LatLng*>(mainLoopVerts.data())
};
// Prepare holes
mutableHoles.clear();
mutableHoles.reserve(holeVerts.size());
for (const auto& hole : holeVerts) {
mutableHoles.push_back({
static_cast<int>(hole.size()),
const_cast<LatLng*>(hole.data())
});
}
// Prepare full polygon
mutablePolygon = {
mutableMainLoop,
static_cast<int>(mutableHoles.size()),
mutableHoles.data()
};
return &mutablePolygon;
}
// Additional utility methods
size_t size() const { return mainLoopVerts.size(); }
bool empty() const { return mainLoopVerts.empty(); }
};
class FunctionH3PolygonToCells : public IFunction class FunctionH3PolygonToCells : public IFunction
{ {
public: public:
@ -212,6 +162,61 @@ public:
return dst; return dst;
} }
private:
class GeoPolygonContainer
{
private:
// Store the polygon data
std::vector<LatLng> mainLoopVerts;
std::vector<std::vector<LatLng>> holeVerts;
// Temporary storage for C-style structs
mutable GeoLoop mutableMainLoop;
mutable GeoPolygon mutablePolygon;
mutable std::vector<GeoLoop> mutableHoles;
public:
// Constructor to create from C++ data
GeoPolygonContainer(const std::vector<LatLng>& mainLoop,
const std::vector<std::vector<LatLng>>& holes = {})
: mainLoopVerts(mainLoop), holeVerts(holes) {}
// Method to get C-style GeoPolygon pointer
const GeoPolygon* unwrap() const
{
// Prepare main loop
mutableMainLoop = {
static_cast<int>(mainLoopVerts.size()),
const_cast<LatLng*>(mainLoopVerts.data())
};
// Prepare holes
mutableHoles.clear();
mutableHoles.reserve(holeVerts.size());
for (const auto& hole : holeVerts)
{
mutableHoles.push_back({
static_cast<int>(hole.size()),
const_cast<LatLng*>(hole.data())
});
}
// Prepare full polygon
mutablePolygon = {
mutableMainLoop,
static_cast<int>(mutableHoles.size()),
mutableHoles.data()
};
return &mutablePolygon;
}
// Additional utility methods
size_t size() const { return mainLoopVerts.size(); }
bool empty() const { return mainLoopVerts.empty(); }
};
}; };
REGISTER_FUNCTION(H3PolygonToCells) REGISTER_FUNCTION(H3PolygonToCells)