From a8298ee5151a02b55479ce3e19793dbaa077fcbe Mon Sep 17 00:00:00 2001 From: Gautam Dey Date: Wed, 13 Feb 2019 17:43:25 -0800 Subject: [PATCH] Forgotten files --- mbgl/c/build_render_with_local.sh | 1 + mbgl/c/include/mapbox/feature.hpp | 113 +++++++++++++++++ mbgl/c/include/mapbox/geometry.hpp | 12 ++ mbgl/c/include/mapbox/geometry/box.hpp | 36 ++++++ mbgl/c/include/mapbox/geometry/empty.hpp | 18 +++ mbgl/c/include/mapbox/geometry/envelope.hpp | 33 +++++ .../mapbox/geometry/for_each_point.hpp | 51 ++++++++ mbgl/c/include/mapbox/geometry/geometry.hpp | 56 +++++++++ .../c/include/mapbox/geometry/line_string.hpp | 28 +++++ .../mapbox/geometry/multi_line_string.hpp | 28 +++++ .../c/include/mapbox/geometry/multi_point.hpp | 28 +++++ .../include/mapbox/geometry/multi_polygon.hpp | 28 +++++ mbgl/c/include/mapbox/geometry/point.hpp | 42 +++++++ .../mapbox/geometry/point_arithmetic.hpp | 119 ++++++++++++++++++ mbgl/c/include/mapbox/geometry/polygon.hpp | 45 +++++++ mbgl/c/include/mapbox/geometry_io.hpp | 98 +++++++++++++++ mbgl/c/install.sh | 2 + mbgl/mbgl.go | 1 + mbgl/simplified/simplified_linux.go | 1 + 19 files changed, 740 insertions(+) create mode 100644 mbgl/c/include/mapbox/feature.hpp create mode 100644 mbgl/c/include/mapbox/geometry.hpp create mode 100644 mbgl/c/include/mapbox/geometry/box.hpp create mode 100644 mbgl/c/include/mapbox/geometry/empty.hpp create mode 100644 mbgl/c/include/mapbox/geometry/envelope.hpp create mode 100644 mbgl/c/include/mapbox/geometry/for_each_point.hpp create mode 100644 mbgl/c/include/mapbox/geometry/geometry.hpp create mode 100644 mbgl/c/include/mapbox/geometry/line_string.hpp create mode 100644 mbgl/c/include/mapbox/geometry/multi_line_string.hpp create mode 100644 mbgl/c/include/mapbox/geometry/multi_point.hpp create mode 100644 mbgl/c/include/mapbox/geometry/multi_polygon.hpp create mode 100644 mbgl/c/include/mapbox/geometry/point.hpp create mode 100644 mbgl/c/include/mapbox/geometry/point_arithmetic.hpp create mode 100644 mbgl/c/include/mapbox/geometry/polygon.hpp create mode 100644 mbgl/c/include/mapbox/geometry_io.hpp diff --git a/mbgl/c/build_render_with_local.sh b/mbgl/c/build_render_with_local.sh index 79b8e98..e6a5cde 100755 --- a/mbgl/c/build_render_with_local.sh +++ b/mbgl/c/build_render_with_local.sh @@ -6,6 +6,7 @@ g++ \ -DRAPIDJSON_HAS_STDSTRING=1 \ -D_GLIBCXX_USE_CXX11_ABI=1 \ -Iinclude \ + -Iinclude/include \ -ftemplate-depth=1024 \ -Wall \ -Wextra \ diff --git a/mbgl/c/include/mapbox/feature.hpp b/mbgl/c/include/mapbox/feature.hpp new file mode 100644 index 0000000..8d03f46 --- /dev/null +++ b/mbgl/c/include/mapbox/feature.hpp @@ -0,0 +1,113 @@ +#pragma once + +#include + +#include + +#include +#include +#include +#include + +namespace mapbox { +namespace feature { + +struct value; + +struct null_value_t +{ +}; + +constexpr bool operator==(const null_value_t&, const null_value_t&) { return true; } +constexpr bool operator!=(const null_value_t&, const null_value_t&) { return false; } +constexpr bool operator<(const null_value_t&, const null_value_t&) { return false; } + +constexpr null_value_t null_value = null_value_t(); + +// Multiple numeric types (uint64_t, int64_t, double) are present in order to support +// the widest possible range of JSON numbers, which do not have a maximum range. +// Implementations that produce `value`s should use that order for type preference, +// using uint64_t for positive integers, int64_t for negative integers, and double +// for non-integers and integers outside the range of 64 bits. +using value_base = mapbox::util::variant>, + mapbox::util::recursive_wrapper>>; + +struct value : value_base +{ + using value_base::value_base; +}; + +using property_map = std::unordered_map; + +// The same considerations and requirement for numeric types apply as for `value_base`. +using identifier = mapbox::util::variant; + +template +struct feature +{ + using coordinate_type = T; + using geometry_type = mapbox::geometry::geometry; // Fully qualified to avoid GCC -fpermissive error. + + geometry_type geometry; + property_map properties; + identifier id; + + feature() + : geometry(), + properties(), + id() {} + feature(geometry_type const& geom_) + : geometry(geom_), + properties(), + id() {} + feature(geometry_type&& geom_) + : geometry(std::move(geom_)), + properties(), + id() {} + feature(geometry_type const& geom_, property_map const& prop_) + : geometry(geom_), properties(prop_), id() {} + feature(geometry_type&& geom_, property_map&& prop_) + : geometry(std::move(geom_)), + properties(std::move(prop_)), + id() {} + feature(geometry_type const& geom_, property_map const& prop_, identifier const& id_) + : geometry(geom_), + properties(prop_), + id(id_) {} + feature(geometry_type&& geom_, property_map&& prop_, identifier&& id_) + : geometry(std::move(geom_)), + properties(std::move(prop_)), + id(std::move(id_)) {} +}; + +template +constexpr bool operator==(feature const& lhs, feature const& rhs) +{ + return lhs.id == rhs.id && lhs.geometry == rhs.geometry && lhs.properties == rhs.properties; +} + +template +constexpr bool operator!=(feature const& lhs, feature const& rhs) +{ + return !(lhs == rhs); +} + +template class Cont = std::vector> +struct feature_collection : Cont> +{ + using coordinate_type = T; + using feature_type = feature; + using container_type = Cont; + using size_type = typename container_type::size_type; + + template + feature_collection(Args&&... args) : container_type(std::forward(args)...) + { + } + feature_collection(std::initializer_list args) + : container_type(std::move(args)) {} +}; + +} // namespace feature +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry.hpp b/mbgl/c/include/mapbox/geometry.hpp new file mode 100644 index 0000000..9caecd9 --- /dev/null +++ b/mbgl/c/include/mapbox/geometry.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/mbgl/c/include/mapbox/geometry/box.hpp b/mbgl/c/include/mapbox/geometry/box.hpp new file mode 100644 index 0000000..bb3ea57 --- /dev/null +++ b/mbgl/c/include/mapbox/geometry/box.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include + +namespace mapbox { +namespace geometry { + +template +struct box +{ + using coordinate_type = T; + using point_type = point; + + constexpr box(point_type const& min_, point_type const& max_) + : min(min_), max(max_) + { + } + + point_type min; + point_type max; +}; + +template +constexpr bool operator==(box const& lhs, box const& rhs) +{ + return lhs.min == rhs.min && lhs.max == rhs.max; +} + +template +constexpr bool operator!=(box const& lhs, box const& rhs) +{ + return lhs.min != rhs.min || lhs.max != rhs.max; +} + +} // namespace geometry +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry/empty.hpp b/mbgl/c/include/mapbox/geometry/empty.hpp new file mode 100644 index 0000000..0ea446d --- /dev/null +++ b/mbgl/c/include/mapbox/geometry/empty.hpp @@ -0,0 +1,18 @@ +#pragma once + +namespace mapbox { +namespace geometry { + +struct empty +{ +}; // this Geometry type represents the empty point set, ∅, for the coordinate space (OGC Simple Features). + +constexpr bool operator==(empty, empty) { return true; } +constexpr bool operator!=(empty, empty) { return false; } +constexpr bool operator<(empty, empty) { return false; } +constexpr bool operator>(empty, empty) { return false; } +constexpr bool operator<=(empty, empty) { return true; } +constexpr bool operator>=(empty, empty) { return true; } + +} // namespace geometry +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry/envelope.hpp b/mbgl/c/include/mapbox/geometry/envelope.hpp new file mode 100644 index 0000000..e1f722f --- /dev/null +++ b/mbgl/c/include/mapbox/geometry/envelope.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include +#include + +#include + +namespace mapbox { +namespace geometry { + +template +box envelope(G const& geometry) +{ + using limits = std::numeric_limits; + + T min_t = limits::has_infinity ? -limits::infinity() : limits::min(); + T max_t = limits::has_infinity ? limits::infinity() : limits::max(); + + point min(max_t, max_t); + point max(min_t, min_t); + + for_each_point(geometry, [&](point const& point) { + if (min.x > point.x) min.x = point.x; + if (min.y > point.y) min.y = point.y; + if (max.x < point.x) max.x = point.x; + if (max.y < point.y) max.y = point.y; + }); + + return box(min, max); +} + +} // namespace geometry +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry/for_each_point.hpp b/mbgl/c/include/mapbox/geometry/for_each_point.hpp new file mode 100644 index 0000000..d31b484 --- /dev/null +++ b/mbgl/c/include/mapbox/geometry/for_each_point.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include + +namespace mapbox { +namespace geometry { + +template +void for_each_point(mapbox::geometry::empty const&, F&&) +{ +} + +template +auto for_each_point(Point&& point, F&& f) + -> decltype(point.x, point.y, void()) +{ + f(std::forward(point)); +} + +template +auto for_each_point(Container&& container, F&& f) + -> decltype(container.begin(), container.end(), void()); + +template +void for_each_point(mapbox::util::variant const& geom, F&& f) +{ + mapbox::util::variant::visit(geom, [&](auto const& g) { + for_each_point(g, f); + }); +} + +template +void for_each_point(mapbox::util::variant& geom, F&& f) +{ + mapbox::util::variant::visit(geom, [&](auto& g) { + for_each_point(g, f); + }); +} + +template +auto for_each_point(Container&& container, F&& f) + -> decltype(container.begin(), container.end(), void()) +{ + for (auto& e : container) + { + for_each_point(e, f); + } +} + +} // namespace geometry +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry/geometry.hpp b/mbgl/c/include/mapbox/geometry/geometry.hpp new file mode 100644 index 0000000..fa1e7c3 --- /dev/null +++ b/mbgl/c/include/mapbox/geometry/geometry.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include + +// stl +#include + +namespace mapbox { +namespace geometry { + +template class Cont = std::vector> +struct geometry_collection; + +template class Cont = std::vector> +using geometry_base = mapbox::util::variant, + line_string, + polygon, + multi_point, + multi_line_string, + multi_polygon, + geometry_collection>; + +template class Cont = std::vector> +struct geometry : geometry_base +{ + using coordinate_type = T; + using geometry_base::geometry_base; +}; + +template class Cont> +struct geometry_collection : Cont> +{ + using coordinate_type = T; + using geometry_type = geometry; + using container_type = Cont; + using size_type = typename container_type::size_type; + + template + geometry_collection(Args&&... args) : container_type(std::forward(args)...) + { + } + geometry_collection(std::initializer_list args) + : container_type(std::move(args)) {} +}; + +} // namespace geometry +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry/line_string.hpp b/mbgl/c/include/mapbox/geometry/line_string.hpp new file mode 100644 index 0000000..a015f71 --- /dev/null +++ b/mbgl/c/include/mapbox/geometry/line_string.hpp @@ -0,0 +1,28 @@ +#pragma once + +// mapbox +#include +// stl +#include + +namespace mapbox { +namespace geometry { + +template class Cont = std::vector> +struct line_string : Cont> +{ + using coordinate_type = T; + using point_type = point; + using container_type = Cont; + using size_type = typename container_type::size_type; + + template + line_string(Args&&... args) : container_type(std::forward(args)...) + { + } + line_string(std::initializer_list args) + : container_type(std::move(args)) {} +}; + +} // namespace geometry +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry/multi_line_string.hpp b/mbgl/c/include/mapbox/geometry/multi_line_string.hpp new file mode 100644 index 0000000..b528fa6 --- /dev/null +++ b/mbgl/c/include/mapbox/geometry/multi_line_string.hpp @@ -0,0 +1,28 @@ +#pragma once + +// mapbox +#include +// stl +#include + +namespace mapbox { +namespace geometry { + +template class Cont = std::vector> +struct multi_line_string : Cont> +{ + using coordinate_type = T; + using line_string_type = line_string; + using container_type = Cont; + using size_type = typename container_type::size_type; + + template + multi_line_string(Args&&... args) : container_type(std::forward(args)...) + { + } + multi_line_string(std::initializer_list args) + : container_type(std::move(args)) {} +}; + +} // namespace geometry +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry/multi_point.hpp b/mbgl/c/include/mapbox/geometry/multi_point.hpp new file mode 100644 index 0000000..060927b --- /dev/null +++ b/mbgl/c/include/mapbox/geometry/multi_point.hpp @@ -0,0 +1,28 @@ +#pragma once + +// mapbox +#include +// stl +#include + +namespace mapbox { +namespace geometry { + +template class Cont = std::vector> +struct multi_point : Cont> +{ + using coordinate_type = T; + using point_type = point; + using container_type = Cont; + using size_type = typename container_type::size_type; + + template + multi_point(Args&&... args) : container_type(std::forward(args)...) + { + } + multi_point(std::initializer_list args) + : container_type(std::move(args)) {} +}; + +} // namespace geometry +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry/multi_polygon.hpp b/mbgl/c/include/mapbox/geometry/multi_polygon.hpp new file mode 100644 index 0000000..9546860 --- /dev/null +++ b/mbgl/c/include/mapbox/geometry/multi_polygon.hpp @@ -0,0 +1,28 @@ +#pragma once + +// mapbox +#include +// stl +#include + +namespace mapbox { +namespace geometry { + +template class Cont = std::vector> +struct multi_polygon : Cont> +{ + using coordinate_type = T; + using polygon_type = polygon; + using container_type = Cont; + using size_type = typename container_type::size_type; + + template + multi_polygon(Args&&... args) : container_type(std::forward(args)...) + { + } + multi_polygon(std::initializer_list args) + : container_type(std::move(args)) {} +}; + +} // namespace geometry +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry/point.hpp b/mbgl/c/include/mapbox/geometry/point.hpp new file mode 100644 index 0000000..da8d677 --- /dev/null +++ b/mbgl/c/include/mapbox/geometry/point.hpp @@ -0,0 +1,42 @@ +#pragma once + +namespace mapbox { +namespace geometry { + +template +struct point +{ + using coordinate_type = T; + + constexpr point() + : x(), y() + { + } + constexpr point(T x_, T y_) + : x(x_), y(y_) + { + } + + T x; + T y; +}; + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" + +template +constexpr bool operator==(point const& lhs, point const& rhs) +{ + return lhs.x == rhs.x && lhs.y == rhs.y; +} + +#pragma GCC diagnostic pop + +template +constexpr bool operator!=(point const& lhs, point const& rhs) +{ + return !(lhs == rhs); +} + +} // namespace geometry +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry/point_arithmetic.hpp b/mbgl/c/include/mapbox/geometry/point_arithmetic.hpp new file mode 100644 index 0000000..0c4c632 --- /dev/null +++ b/mbgl/c/include/mapbox/geometry/point_arithmetic.hpp @@ -0,0 +1,119 @@ +#pragma once + +namespace mapbox { +namespace geometry { + +template +point operator+(point const& lhs, point const& rhs) +{ + return point(lhs.x + rhs.x, lhs.y + rhs.y); +} + +template +point operator+(point const& lhs, T const& rhs) +{ + return point(lhs.x + rhs, lhs.y + rhs); +} + +template +point operator-(point const& lhs, point const& rhs) +{ + return point(lhs.x - rhs.x, lhs.y - rhs.y); +} + +template +point operator-(point const& lhs, T const& rhs) +{ + return point(lhs.x - rhs, lhs.y - rhs); +} + +template +point operator*(point const& lhs, point const& rhs) +{ + return point(lhs.x * rhs.x, lhs.y * rhs.y); +} + +template +point operator*(point const& lhs, T const& rhs) +{ + return point(lhs.x * rhs, lhs.y * rhs); +} + +template +point operator/(point const& lhs, point const& rhs) +{ + return point(lhs.x / rhs.x, lhs.y / rhs.y); +} + +template +point operator/(point const& lhs, T const& rhs) +{ + return point(lhs.x / rhs, lhs.y / rhs); +} + +template +point& operator+=(point& lhs, point const& rhs) +{ + lhs.x += rhs.x; + lhs.y += rhs.y; + return lhs; +} + +template +point& operator+=(point& lhs, T const& rhs) +{ + lhs.x += rhs; + lhs.y += rhs; + return lhs; +} + +template +point& operator-=(point& lhs, point const& rhs) +{ + lhs.x -= rhs.x; + lhs.y -= rhs.y; + return lhs; +} + +template +point& operator-=(point& lhs, T const& rhs) +{ + lhs.x -= rhs; + lhs.y -= rhs; + return lhs; +} + +template +point& operator*=(point& lhs, point const& rhs) +{ + lhs.x *= rhs.x; + lhs.y *= rhs.y; + return lhs; +} + +template +point& operator*=(point& lhs, T const& rhs) +{ + lhs.x *= rhs; + lhs.y *= rhs; + return lhs; +} + +template +point& operator/=(point& lhs, point const& rhs) +{ + lhs.x /= rhs.x; + lhs.y /= rhs.y; + return lhs; +} + +template +point& operator/=(point& lhs, T const& rhs) +{ + lhs.x /= rhs; + lhs.y /= rhs; + return lhs; +} + +} // namespace geometry +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry/polygon.hpp b/mbgl/c/include/mapbox/geometry/polygon.hpp new file mode 100644 index 0000000..5cad7bb --- /dev/null +++ b/mbgl/c/include/mapbox/geometry/polygon.hpp @@ -0,0 +1,45 @@ +#pragma once + +// mapbox +#include + +// stl +#include + +namespace mapbox { +namespace geometry { + +template class Cont = std::vector> +struct linear_ring : Cont> +{ + using coordinate_type = T; + using point_type = point; + using container_type = Cont; + using size_type = typename container_type::size_type; + + template + linear_ring(Args&&... args) : container_type(std::forward(args)...) + { + } + linear_ring(std::initializer_list args) + : container_type(std::move(args)) {} +}; + +template class Cont = std::vector> +struct polygon : Cont> +{ + using coordinate_type = T; + using linear_ring_type = linear_ring; + using container_type = Cont; + using size_type = typename container_type::size_type; + + template + polygon(Args&&... args) : container_type(std::forward(args)...) + { + } + polygon(std::initializer_list args) + : container_type(std::move(args)) {} +}; + +} // namespace geometry +} // namespace mapbox diff --git a/mbgl/c/include/mapbox/geometry_io.hpp b/mbgl/c/include/mapbox/geometry_io.hpp new file mode 100644 index 0000000..4d91ccc --- /dev/null +++ b/mbgl/c/include/mapbox/geometry_io.hpp @@ -0,0 +1,98 @@ +#pragma once + +#include +#include + +#include +#include + +namespace mapbox { +namespace geometry { + +std::ostream& operator<<(std::ostream& os, const empty&) +{ + return os << "[]"; +} + +template +std::ostream& operator<<(std::ostream& os, const point& point) +{ + return os << "[" << point.x << "," << point.y << "]"; +} + +template class C, class... Args> +std::ostream& operator<<(std::ostream& os, const C& cont) +{ + os << "["; + for (auto it = cont.cbegin();;) + { + os << *it; + if (++it == cont.cend()) + { + break; + } + os << ","; + } + return os << "]"; +} + +template +std::ostream& operator<<(std::ostream& os, const line_string& geom) +{ + return os << static_cast::container_type>(geom); +} + +template +std::ostream& operator<<(std::ostream& os, const linear_ring& geom) +{ + return os << static_cast::container_type>(geom); +} + +template +std::ostream& operator<<(std::ostream& os, const polygon& geom) +{ + return os << static_cast::container_type>(geom); +} + +template +std::ostream& operator<<(std::ostream& os, const multi_point& geom) +{ + return os << static_cast::container_type>(geom); +} + +template +std::ostream& operator<<(std::ostream& os, const multi_line_string& geom) +{ + return os << static_cast::container_type>(geom); +} + +template +std::ostream& operator<<(std::ostream& os, const multi_polygon& geom) +{ + return os << static_cast::container_type>(geom); +} + +template +std::ostream& operator<<(std::ostream& os, const geometry& geom) +{ + geometry::visit(geom, [&](const auto& g) { os << g; }); + return os; +} + +template +std::ostream& operator<<(std::ostream& os, const geometry_collection& geom) +{ + return os << static_cast::container_type>(geom); +} + +} // namespace geometry + +namespace feature { + +std::ostream& operator<<(std::ostream& os, const null_value_t&) +{ + return os << "[]"; +} + +} // namespace feature +} // namespace mapbox diff --git a/mbgl/c/install.sh b/mbgl/c/install.sh index 5aafd1d..a0d7388 100755 --- a/mbgl/c/install.sh +++ b/mbgl/c/install.sh @@ -164,6 +164,8 @@ else copy_hpps "platform" "default" copy_includes "vendor" "expected" "geometry" "variant" + + cp -R $PKG_ROOT/mapbox-gl-native/vendor/geometry.hpp/include/* ${INCLUDEDIR} fi # install mason-js (mapbox package manager) diff --git a/mbgl/mbgl.go b/mbgl/mbgl.go index 80a5fd8..77f43fa 100644 --- a/mbgl/mbgl.go +++ b/mbgl/mbgl.go @@ -6,6 +6,7 @@ package mbgl #cgo CXXFLAGS: -std=c++14 -std=gnu++14 #cgo CXXFLAGS: -g #cgo CXXFLAGS: -I${SRCDIR}/c/include +#cgo CXXFLAGS: -I${SRCDIR}/c/include/include #cgo CXXFLAGS: -I${SRCDIR}/c/mapbox-gl-native/platform/default #cgo LDFLAGS: -lmbgl-filesource diff --git a/mbgl/simplified/simplified_linux.go b/mbgl/simplified/simplified_linux.go index 36b477a..42e35a5 100644 --- a/mbgl/simplified/simplified_linux.go +++ b/mbgl/simplified/simplified_linux.go @@ -2,6 +2,7 @@ package simplified /* #cgo CXXFLAGS: -I${SRCDIR}/../c/include +#cgo CXXFLAGS: -I${SRCDIR}/../c/include/include #cgo LDFLAGS: -L${SRCDIR}/../c/lib/linux #cgo LDFLAGS: ${SRCDIR}/../c/lib/linux/libmbgl-core.a