C++11: Added _htmlColor literal operator.
Allows inline specification of colors in HTML syntax.
This commit is contained in:
@@ -412,6 +412,26 @@ typedef VectorT<double,6> Vec6d;
|
|||||||
//=============================================================================
|
//=============================================================================
|
||||||
} // namespace OpenMesh
|
} // 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 // OPENMESH_VECTOR_HH defined
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
#endif // DOXYGEN
|
#endif // DOXYGEN
|
||||||
|
|||||||
@@ -111,6 +111,18 @@ TEST_F(OpenMeshVectorTest, cpp11_constructors) {
|
|||||||
EXPECT_EQ(1.23, vec4d[2]);
|
EXPECT_EQ(1.23, vec4d[2]);
|
||||||
EXPECT_EQ(1.23, vec4d[3]);
|
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
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user