summaryrefslogtreecommitdiff
path: root/src/mbgl/util
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-10-28 16:39:50 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-02-02 09:44:42 -0800
commit141e995806576364d185626176c1b993fc519291 (patch)
treeecdc41fc7699f2a1a9e9456157348451ebe99597 /src/mbgl/util
parent6a6bddb4537004cc1bfc506e76772de74d33f3f7 (diff)
downloadqtlocation-mapboxgl-141e995806576364d185626176c1b993fc519291.tar.gz
[core] Add support for data-driven styling
Diffstat (limited to 'src/mbgl/util')
-rw-r--r--src/mbgl/util/ignore.hpp3
-rw-r--r--src/mbgl/util/indexed_tuple.hpp13
-rw-r--r--src/mbgl/util/interpolate.cpp19
-rw-r--r--src/mbgl/util/interpolate.hpp9
-rw-r--r--src/mbgl/util/type_list.hpp40
5 files changed, 81 insertions, 3 deletions
diff --git a/src/mbgl/util/ignore.hpp b/src/mbgl/util/ignore.hpp
index 955b1de2fa..577bcf4d91 100644
--- a/src/mbgl/util/ignore.hpp
+++ b/src/mbgl/util/ignore.hpp
@@ -19,5 +19,8 @@ template <class... Ts> void ignore(Ts&&...) {}
//
template <class T> void ignore(const std::initializer_list<T>&) {}
+// Handle the zero-argument case.
+inline void ignore(const std::initializer_list<int>&) {}
+
} // namespace util
} // namespace mbgl
diff --git a/src/mbgl/util/indexed_tuple.hpp b/src/mbgl/util/indexed_tuple.hpp
index 110e7dce12..a414639530 100644
--- a/src/mbgl/util/indexed_tuple.hpp
+++ b/src/mbgl/util/indexed_tuple.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <mbgl/util/type_list.hpp>
+
#include <type_traits>
#include <tuple>
@@ -14,8 +16,6 @@ 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 TypeList {};
-
template <class...> class IndexedTuple;
// A tuple of Ts, where individual members can be accessed via `t.get<I>()` for I ∈ Is.
@@ -42,6 +42,15 @@ public:
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/src/mbgl/util/interpolate.cpp b/src/mbgl/util/interpolate.cpp
new file mode 100644
index 0000000000..306a5c6630
--- /dev/null
+++ b/src/mbgl/util/interpolate.cpp
@@ -0,0 +1,19 @@
+#include <mbgl/util/interpolate.hpp>
+
+#include <cmath>
+
+namespace mbgl {
+namespace util {
+
+float interpolationFactor(float base, Range<float> range, float z) {
+ const float zoomDiff = range.max - range.min;
+ const float zoomProgress = z - range.min;
+ if (base == 1.0f) {
+ return zoomProgress / zoomDiff;
+ } else {
+ return (std::pow(base, zoomProgress) - 1) / (std::pow(base, zoomDiff) - 1);
+ }
+}
+
+} // namespace util
+} // namespace mbgl
diff --git a/src/mbgl/util/interpolate.hpp b/src/mbgl/util/interpolate.hpp
index ef066377da..d463ffc056 100644
--- a/src/mbgl/util/interpolate.hpp
+++ b/src/mbgl/util/interpolate.hpp
@@ -1,15 +1,19 @@
#pragma once
+#include <mbgl/util/color.hpp>
+#include <mbgl/util/range.hpp>
+
#include <array>
#include <vector>
#include <string>
#include <type_traits>
#include <utility>
-#include <mbgl/util/color.hpp>
namespace mbgl {
namespace util {
+float interpolationFactor(float base, Range<float> range, float z);
+
template <class T, class Enabled = void>
struct Interpolator;
@@ -78,5 +82,8 @@ template <class T>
struct Interpolator<std::vector<T>>
: Uninterpolated {};
+template <class T>
+constexpr bool Interpolatable = !std::is_base_of<Uninterpolated, Interpolator<T>>::value;
+
} // namespace util
} // namespace mbgl
diff --git a/src/mbgl/util/type_list.hpp b/src/mbgl/util/type_list.hpp
new file mode 100644
index 0000000000..4a5e95c8a4
--- /dev/null
+++ b/src/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