diff options
Diffstat (limited to 'src/mbgl/util/geometry_util.hpp')
-rw-r--r-- | src/mbgl/util/geometry_util.hpp | 59 |
1 files changed, 43 insertions, 16 deletions
diff --git a/src/mbgl/util/geometry_util.hpp b/src/mbgl/util/geometry_util.hpp index ccf7bfc504..3bdef9f357 100644 --- a/src/mbgl/util/geometry_util.hpp +++ b/src/mbgl/util/geometry_util.hpp @@ -1,25 +1,52 @@ #pragma once +#include <array> #include <mbgl/util/geometry.hpp> namespace mbgl { +// contains minX, minY, maxX, maxY template <typename T> -struct GeometryUtil { - using type = T; - static bool segmentIntersectSegment(const Point<type>& a, - const Point<type>& b, - const Point<type>& c, - const Point<type>& d); - static bool rayIntersect(const Point<type>& p, const Point<type>& p1, const Point<type>& p2); - static bool pointOnBoundary(const Point<type>& p, const Point<type>& p1, const Point<type>& p2); - static bool lineIntersectPolygon(const Point<type>& p1, const Point<type>& p2, const Polygon<type>& polygon); - static bool pointWithinPolygon(const Point<type>& point, const Polygon<type>& polygon, bool trueOnBoundary = false); - static bool pointWithinPolygons(const Point<type>& point, - const MultiPolygon<type>& polygons, - bool trueOnBoundary = false); - static bool lineStringWithinPolygon(const LineString<type>& line, const Polygon<type>& polygon); - static bool lineStringWithinPolygons(const LineString<type>& line, const MultiPolygon<type>& polygons); -}; +using GeometryBBox = std::array<T, 4>; +const GeometryBBox<int64_t> DefaultWithinBBox = std::array<int64_t, 4>{std::numeric_limits<int64_t>::max(), + std::numeric_limits<int64_t>::max(), + std::numeric_limits<int64_t>::min(), + std::numeric_limits<int64_t>::min()}; + +const GeometryBBox<double> DefaultDistanceBBox = std::array<double, 4>{std::numeric_limits<double>::infinity(), + std::numeric_limits<double>::infinity(), + -std::numeric_limits<double>::infinity(), + -std::numeric_limits<double>::infinity()}; + +template <typename T> +void updateBBox(GeometryBBox<T>& bbox, const Point<T>& p); + +// check if bbox1 is within bbox2 +template <typename T> +bool boxWithinBox(const GeometryBBox<T>& bbox1, const GeometryBBox<T>& bbox2); + +template <typename T> +bool segmentIntersectSegment(const Point<T>& a, const Point<T>& b, const Point<T>& c, const Point<T>& d); + +template <typename T> +bool rayIntersect(const Point<T>& p, const Point<T>& p1, const Point<T>& p2); + +template <typename T> +bool pointOnBoundary(const Point<T>& p, const Point<T>& p1, const Point<T>& p2); + +template <typename T> +bool lineIntersectPolygon(const Point<T>& p1, const Point<T>& p2, const Polygon<T>& polygon); + +template <typename T> +bool pointWithinPolygon(const Point<T>& point, const Polygon<T>& polygon, bool trueOnBoundary = false); + +template <typename T> +bool pointWithinPolygons(const Point<T>& point, const MultiPolygon<T>& polygons, bool trueOnBoundary = false); + +template <typename T> +bool lineStringWithinPolygon(const LineString<T>& line, const Polygon<T>& polygon); + +template <typename T> +bool lineStringWithinPolygons(const LineString<T>& line, const MultiPolygon<T>& polygons); } // namespace mbgl |