From f6e79d70735361438655f279c8699a786d25458c Mon Sep 17 00:00:00 2001 From: Lauren Budorick Date: Thu, 27 Apr 2017 15:56:55 -0700 Subject: [core] Render fill-extrusion layers (#8431) --- include/mbgl/util/indexed_tuple.hpp | 56 +++++++++++++++++++++++++++++++++++++ include/mbgl/util/interpolate.hpp | 12 ++++++++ include/mbgl/util/type_list.hpp | 40 ++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 include/mbgl/util/indexed_tuple.hpp create mode 100644 include/mbgl/util/type_list.hpp (limited to 'include/mbgl/util') diff --git a/include/mbgl/util/indexed_tuple.hpp b/include/mbgl/util/indexed_tuple.hpp new file mode 100644 index 0000000000..a414639530 --- /dev/null +++ b/include/mbgl/util/indexed_tuple.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include + +#include +#include + +namespace mbgl { + +template +struct TypeIndex; + +template +struct TypeIndex : std::integral_constant {}; + +template +struct TypeIndex : std::integral_constant::value> {}; + +template class IndexedTuple; + +// A tuple of Ts, where individual members can be accessed via `t.get()` for I ∈ Is. +// +// See https://github.com/mapbox/cpp/blob/master/C%2B%2B%20Structural%20Metaprogramming.md +// for motivation. +// +template +class IndexedTuple, TypeList> : public std::tuple { +public: + static_assert(sizeof...(Is) == sizeof...(Ts), "IndexedTuple size mismatch"); + + using std::tuple::tuple; + + template + static constexpr std::size_t Index = TypeIndex::value; + + template + auto& get() { + return std::get>(*this); + } + + template + const auto& get() const { + return std::get>(*this); + } + + template + IndexedTuple, TypeList> + concat(const IndexedTuple, TypeList>& other) const { + return IndexedTuple, TypeList> { + get()..., + other.template get()... + }; + } +}; + +} // namespace mbgl diff --git a/include/mbgl/util/interpolate.hpp b/include/mbgl/util/interpolate.hpp index d463ffc056..a2103f18b2 100644 --- a/include/mbgl/util/interpolate.hpp +++ b/include/mbgl/util/interpolate.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -46,6 +47,17 @@ public: } }; +template <> +struct Interpolator { +public: + style::Position operator()(const style::Position& a, const style::Position& b, const double t) { + auto pos = style::Position(); + auto interpolated = interpolate(a.getCartesian(), b.getCartesian(), t); + pos.setCartesian(interpolated); + return { pos }; + } +}; + template <> struct Interpolator { public: diff --git a/include/mbgl/util/type_list.hpp b/include/mbgl/util/type_list.hpp new file mode 100644 index 0000000000..4a5e95c8a4 --- /dev/null +++ b/include/mbgl/util/type_list.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include +#include + +namespace mbgl { + +template +class TypeList {}; + +namespace detail { + +template +struct TypeCons; + +template +struct TypeCons> { + using Type = TypeList; +}; + +template class> +struct TypeFilter; + +template