colour: use floats for values
double is way too much precision for almost every application. we can always add more templates or other insanity later.
This commit is contained in:
parent
5956d0421e
commit
6f23e39459
30
colour.cpp
30
colour.cpp
@ -28,12 +28,12 @@ using namespace util;
|
|||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
const util::colour util::colour::WHITE ({ 1.0, 1.0, 1.0, 1.0 });
|
const util::colour util::colour::WHITE ({ 1, 1, 1, 1 });
|
||||||
const util::colour util::colour::BLACK ({ 0.0, 0.0, 0.0, 1.0 });
|
const util::colour util::colour::BLACK ({ 0, 0, 0, 1 });
|
||||||
|
|
||||||
const util::colour util::colour::RED ({ 1.0, 0.0, 0.0, 1.0 });
|
const util::colour util::colour::RED ({ 1, 0, 0, 1 });
|
||||||
const util::colour util::colour::GREEN ({ 0.0, 1.0, 0.0, 1.0 });
|
const util::colour util::colour::GREEN ({ 0, 1, 0, 1 });
|
||||||
const util::colour util::colour::BLUE ({ 0.0, 0.0, 1.0, 1.0 });
|
const util::colour util::colour::BLUE ({ 0, 0, 1, 1 });
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -43,14 +43,14 @@ const util::colour util::colour::BLUE ({ 0.0, 0.0, 1.0, 1.0 });
|
|||||||
//! json::type_error.
|
//! json::type_error.
|
||||||
const json::node&
|
const json::node&
|
||||||
operator>> (const json::node &node, colour &c) {
|
operator>> (const json::node &node, colour &c) {
|
||||||
c.red = node[0].as_number ();
|
c.red = static_cast<float> (node[0].as_number ());
|
||||||
c.green = node[1].as_number ();
|
c.green = static_cast<float> (node[1].as_number ());
|
||||||
c.blue = node[2].as_number ();
|
c.blue = static_cast<float> (node[2].as_number ());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
c.alpha = node[3].as_number ();
|
c.alpha = static_cast<float> (node[3].as_number ());
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
c.alpha = 1.0;
|
c.alpha = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
@ -62,10 +62,10 @@ namespace util {
|
|||||||
template<>
|
template<>
|
||||||
colour
|
colour
|
||||||
random (void) {
|
random (void) {
|
||||||
return colour ({ range<double>::UNIT.random (),
|
return colour ({ range<float>::UNIT.random (),
|
||||||
range<double>::UNIT.random (),
|
range<float>::UNIT.random (),
|
||||||
range<double>::UNIT.random (),
|
range<float>::UNIT.random (),
|
||||||
range<double>::UNIT.random () });
|
range<float>::UNIT.random () });
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
@ -77,7 +77,7 @@ namespace util {
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
std::ostream&
|
std::ostream&
|
||||||
operator<< (std::ostream &os, const util::colour &c) {
|
util::operator<< (std::ostream &os, const util::colour &c) {
|
||||||
os << "colour(" << c.red << ", " << c.green << ", " << c.blue << ", " << c.alpha << ")";
|
os << "colour(" << c.red << ", " << c.green << ", " << c.blue << ", " << c.alpha << ")";
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
13
colour.hpp
13
colour.hpp
@ -27,10 +27,10 @@
|
|||||||
namespace util {
|
namespace util {
|
||||||
/// An RGBA colour POD type.
|
/// An RGBA colour POD type.
|
||||||
struct colour {
|
struct colour {
|
||||||
double red;
|
float red;
|
||||||
double green;
|
float green;
|
||||||
double blue;
|
float blue;
|
||||||
double alpha;
|
float alpha;
|
||||||
|
|
||||||
static const colour WHITE;
|
static const colour WHITE;
|
||||||
static const colour BLACK;
|
static const colour BLACK;
|
||||||
@ -39,9 +39,8 @@ namespace util {
|
|||||||
static const colour GREEN;
|
static const colour GREEN;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::ostream& operator<< (std::ostream&, const util::colour&);
|
||||||
|
const json::node& operator>> (const json::node&, util::colour&);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<< (std::ostream&, const util::colour&);
|
|
||||||
const json::node& operator>> (const json::node&, util::colour&);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user