summaryrefslogtreecommitdiff
path: root/include/mbgl/util
diff options
context:
space:
mode:
authorLauren Budorick <lauren@mapbox.com>2017-04-27 15:56:55 -0700
committerGitHub <noreply@github.com>2017-04-27 15:56:55 -0700
commitf6e79d70735361438655f279c8699a786d25458c (patch)
treecc01ae7aba097bae4aa84beb12ac6b8f34f4d51a /include/mbgl/util
parent839ad87f37a4880804fb4c79157d998ac59954b5 (diff)
downloadqtlocation-mapboxgl-f6e79d70735361438655f279c8699a786d25458c.tar.gz
[core] Render fill-extrusion layers (#8431)
Diffstat (limited to 'include/mbgl/util')
-rw-r--r--include/mbgl/util/indexed_tuple.hpp56
-rw-r--r--include/mbgl/util/interpolate.hpp12
-rw-r--r--include/mbgl/util/type_list.hpp40
3 files changed, 108 insertions, 0 deletions
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 <mbgl/util/type_list.hpp>
+
+#include <type_traits>
+#include <tuple>
+
+namespace mbgl {
+
+template <class T, class... Ts>
+struct TypeIndex;
+
+template <class T, class... Ts>
+struct TypeIndex<T, T, Ts...> : std::integral_constant<std::size_t, 0> {};
+
+template <class T, class U, class... Ts>
+struct TypeIndex<T, U, Ts...> : std::integral_constant<std::size_t, 1 + TypeIndex<T, Ts...>::value> {};
+
+template <class...> class IndexedTuple;
+
+// A tuple of Ts, where individual members can be accessed via `t.get<I>()` for I ∈ Is.
+//
+// See https://github.com/mapbox/cpp/blob/master/C%2B%2B%20Structural%20Metaprogramming.md
+// for motivation.
+//
+template <class... Is, class... Ts>
+class IndexedTuple<TypeList<Is...>, TypeList<Ts...>> : public std::tuple<Ts...> {
+public:
+ static_assert(sizeof...(Is) == sizeof...(Ts), "IndexedTuple size mismatch");
+
+ using std::tuple<Ts...>::tuple;
+
+ template <class I>
+ static constexpr std::size_t Index = TypeIndex<I, Is...>::value;
+
+ template <class I>
+ auto& get() {
+ return std::get<Index<I>>(*this);
+ }
+
+ template <class I>
+ const auto& get() const {
+ return std::get<Index<I>>(*this);
+ }
+
+ template <class... Js, class... Us>
+ IndexedTuple<TypeList<Is..., Js...>, TypeList<Ts..., Us...>>
+ concat(const IndexedTuple<TypeList<Js...>, TypeList<Us...>>& other) const {
+ return IndexedTuple<TypeList<Is..., Js...>, TypeList<Ts..., Us...>> {
+ get<Is>()...,
+ other.template get<Js>()...
+ };
+ }
+};
+
+} // 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 <mbgl/util/color.hpp>
#include <mbgl/util/range.hpp>
+#include <mbgl/style/position.hpp>
#include <array>
#include <vector>
@@ -47,6 +48,17 @@ public:
};
template <>
+struct Interpolator<style::Position> {
+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<Color> {
public:
Color operator()(const Color& a, const Color& b, const double t) {
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 <type_traits>
+#include <tuple>
+
+namespace mbgl {
+
+template <class...>
+class TypeList {};
+
+namespace detail {
+
+template <class, class>
+struct TypeCons;
+
+template <class T, class... Ts>
+struct TypeCons<T, TypeList<Ts...>> {
+ using Type = TypeList<T, Ts...>;
+};
+
+template <class, template <class> class>
+struct TypeFilter;
+
+template <template <class> class Predicate>
+struct TypeFilter<TypeList<>, Predicate> {
+ using Type = TypeList<>;
+};
+
+template <template <class> class Predicate, class T, class... Ts>
+struct TypeFilter<TypeList<T, Ts...>, Predicate> {
+ using Tail = typename TypeFilter<TypeList<Ts...>, Predicate>::Type;
+ using Type = std::conditional_t<Predicate<T>::value, typename TypeCons<T, Tail>::Type, Tail>;
+};
+
+} // namespace detail
+
+template <class TypeList, template <class> class Predicate>
+using FilteredTypeList = typename detail::TypeFilter<TypeList, Predicate>::Type;
+
+} // namespace mbgl