Commit c2c627ed authored by Hans-Christian Ebke's avatar Hans-Christian Ebke
Browse files

C++11: Added _htmlColor literal operator.

Allows inline specification of colors in HTML syntax.
parent 97ccb1d6
......@@ -412,6 +412,26 @@ typedef VectorT<double,6> Vec6d;
//=============================================================================
} // namespace OpenMesh
//=============================================================================
#ifdef CPP11_ENABLED
/**
* Literal operator for inline specification of colors in HTML syntax.
*
* Example:
* \code{.cpp}
* OpenMesh::Vec4f light_blue = 0x1FCFFFFF_htmlColor;
* \endcode
*/
constexpr OpenMesh::Vec4f operator"" _htmlColor(unsigned long long raw_color) {
return OpenMesh::Vec4f(
((raw_color >> 24) & 0xFF) / 255.0f,
((raw_color >> 16) & 0xFF) / 255.0f,
((raw_color >> 8) & 0xFF) / 255.0f,
((raw_color >> 0) & 0xFF) / 255.0f);
}
#endif
#endif // OPENMESH_VECTOR_HH defined
//=============================================================================
#endif // DOXYGEN
......@@ -111,6 +111,18 @@ TEST_F(OpenMeshVectorTest, cpp11_constructors) {
EXPECT_EQ(1.23, vec4d[2]);
EXPECT_EQ(1.23, vec4d[3]);
}
TEST_F(OpenMeshVectorTest, cpp11_htmlColorLiteral) {
const OpenMesh::Vec4f light_blue = 0x1FCFFFFF_htmlColor;
EXPECT_LE((OpenMesh::Vec4f(0.1215686274f, 0.8117647058f, 1.0f, 1.0f)
- light_blue).sqrnorm(), 1e-10);
const auto light_blue_2 = 0x1FCFFFFF_htmlColor;
// Check whether auto type deduction works as expected.
static_assert(std::is_same<decltype(light_blue_2), decltype(light_blue)>
::value, "Bad type deduced from _htmlColor literal.");
EXPECT_EQ(light_blue, light_blue_2);
}
#endif
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment