diff options
author | Jesse Crocker <jesse@gaiagps.com> | 2017-03-01 11:15:11 -0700 |
---|---|---|
committer | Jesse Crocker <jesse@gaiagps.com> | 2017-03-01 11:15:11 -0700 |
commit | 9e8dc9a9e3e86adb9987ae69766cc42c7d9efece (patch) | |
tree | f5f0abd4d342c89ad0405d01969f9d6caecc1c90 /src/mbgl/gl/normalization.hpp | |
parent | 16fb0672e64a72b7400c321d55858b73cd5d8c3f (diff) | |
parent | f28d75dccd9bf4a7615df87faccc5cf5eff8df89 (diff) | |
download | qtlocation-mapboxgl-9e8dc9a9e3e86adb9987ae69766cc42c7d9efece.tar.gz |
Merge remote-tracking branch 'origin/master' into feature/custom-vector-source
Diffstat (limited to 'src/mbgl/gl/normalization.hpp')
-rw-r--r-- | src/mbgl/gl/normalization.hpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mbgl/gl/normalization.hpp b/src/mbgl/gl/normalization.hpp new file mode 100644 index 0000000000..83fa67a3ec --- /dev/null +++ b/src/mbgl/gl/normalization.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include <mbgl/math/clamp.hpp> + +#include <cassert> +#include <limits> + +namespace mbgl { +namespace gl { + +template <class T> +class Normalized { +public: + T value; + + Normalized() : value(0) {} + + explicit Normalized(float f) + : value(static_cast<T>(std::numeric_limits<T>::max() * util::clamp(f, 0.0f, 1.0f))) { + assert(f >= 0.0f); + assert(f <= 1.0f); + } + + float denormalized() const { + return float(value) / std::numeric_limits<T>::max(); + } +}; + +template <class T> +bool operator==(const Normalized<T>& lhs, const Normalized<T>& rhs) { + return lhs.value == rhs.value; +} + +} // namespace gl +} // namespace mbgl |