Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenMesh
OpenMesh
Commits
c2c627ed
Commit
c2c627ed
authored
Nov 09, 2015
by
Hans-Christian Ebke
Browse files
C++11: Added _htmlColor literal operator.
Allows inline specification of colors in HTML syntax.
parent
97ccb1d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/OpenMesh/Core/Geometry/VectorT.hh
View file @
c2c627ed
...
...
@@ -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.0
f
,
((
raw_color
>>
16
)
&
0xFF
)
/
255.0
f
,
((
raw_color
>>
8
)
&
0xFF
)
/
255.0
f
,
((
raw_color
>>
0
)
&
0xFF
)
/
255.0
f
);
}
#endif
#endif // OPENMESH_VECTOR_HH defined
//=============================================================================
#endif // DOXYGEN
src/Unittests/unittests_vector_type.cc
View file @
c2c627ed
...
...
@@ -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.1215686274
f
,
0.8117647058
f
,
1.0
f
,
1.0
f
)
-
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
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment