summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-11-28 13:00:53 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-11-29 06:52:24 -0800
commit3d2d57cd30aae8d2811f679fcb30fd0e8f2ab2e9 (patch)
tree5a2700d943cdb190e7cb73c8683d08e186806263 /include
parent99c2bf2580f57542ce2a473dba2587604d10f6ac (diff)
downloadqtlocation-mapboxgl-3d2d57cd30aae8d2811f679fcb30fd0e8f2ab2e9.tar.gz
[core] Assert valid range for color components
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/color.hpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/mbgl/util/color.hpp b/include/mbgl/util/color.hpp
index 7693ce636d..178d0dc758 100644
--- a/include/mbgl/util/color.hpp
+++ b/include/mbgl/util/color.hpp
@@ -2,6 +2,7 @@
#include <mbgl/util/optional.hpp>
+#include <cassert>
#include <string>
namespace mbgl {
@@ -9,6 +10,19 @@ namespace mbgl {
// Stores a premultiplied color, with all four channels ranging from 0..1
class Color {
public:
+ constexpr Color() = default;
+ constexpr Color(float r_, float g_, float b_, float a_)
+ : r(r_), g(g_), b(b_), a(a_) {
+ assert(r_ >= 0.0f);
+ assert(r_ <= 1.0f);
+ assert(g_ >= 0.0f);
+ assert(g_ <= 1.0f);
+ assert(b_ >= 0.0f);
+ assert(b_ <= 1.0f);
+ assert(a_ >= 0.0f);
+ assert(a_ <= 1.0f);
+ }
+
float r = 0.0f;
float g = 0.0f;
float b = 0.0f;
@@ -33,6 +47,8 @@ constexpr bool operator!=(const Color& colorA, const Color& colorB) {
}
constexpr Color operator*(const Color& color, float alpha) {
+ assert(alpha >= 0.0f);
+ assert(alpha <= 1.0f);
return {
color.r * alpha,
color.g * alpha,