Add Visione backend foundation

This commit is contained in:
gabdevele
2026-06-02 19:22:00 +02:00 Unverified
commit 580789ac83
52 changed files with 5008 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
#include "common/GeoJson.h"
#include <vector>
namespace visione::geojson
{
namespace
{
struct Point
{
double x;
double y;
};
} // namespace
bool pointInPolygon(double latitude, double longitude, const Json::Value &geojson)
{
if (!geojson.isObject() || geojson["type"].asString() != "Polygon" ||
!geojson["coordinates"].isArray() || geojson["coordinates"].empty())
{
return false;
}
const auto &ring = geojson["coordinates"][0];
if (!ring.isArray() || ring.size() < 4)
{
return false;
}
std::vector<Point> points;
points.reserve(ring.size());
for (const auto &coordinate : ring)
{
if (!coordinate.isArray() || coordinate.size() < 2)
{
return false;
}
points.push_back({coordinate[0].asDouble(), coordinate[1].asDouble()});
}
const auto x = longitude;
const auto y = latitude;
bool inside = false;
for (size_t i = 0, j = points.size() - 1; i < points.size(); j = i++)
{
const auto &pi = points[i];
const auto &pj = points[j];
const bool intersects =
((pi.y > y) != (pj.y > y)) &&
(x < (pj.x - pi.x) * (y - pi.y) / (pj.y - pi.y) + pi.x);
if (intersects)
{
inside = !inside;
}
}
return inside;
}
} // namespace visione::geojson