bezier: avoid type punning on points member

This commit is contained in:
Danny Robson 2015-02-03 02:21:33 +11:00
parent 65fdb5e47a
commit 34637949e2
2 changed files with 9 additions and 4 deletions

View File

@ -144,7 +144,7 @@ namespace util {
std::array<util::vector2f,4>
bezier<3>::coeffs (void) const
{
auto &v = reinterpret_cast<const util::vector2f(&)[4]> (m_points);
const auto &v = m_coeffs;
return {
-1 * v[0] +3 * v[1] -3 * v[2] +1 * v[3],
@ -162,7 +162,7 @@ namespace util {
std::array<util::vector2f,3>
bezier<2>::coeffs (void) const
{
auto &v = reinterpret_cast<const util::vector2f(&)[3]> (m_points);
auto &v = m_coeffs;
return {
+1 * v[2] -2 * v[1] + 1 * v[0],
@ -179,7 +179,7 @@ namespace util {
std::array<util::vector2f,2>
bezier<1>::coeffs (void) const
{
auto &v = reinterpret_cast<const util::vector2f(&)[2]> (m_points);
auto &v = m_coeffs;
return {
-1 * v[1] + 1 * v[0],

View File

@ -44,7 +44,12 @@ namespace util {
const point2f& operator[] (size_t idx) const;
private:
point2f m_points[S+1];
// HACK: allow easy access to component-wise arithmetic using
// vector2f rather than point2f in the implementation.
union {
point2f m_points[S+1];
vector2f m_coeffs[S+1];
};
};
template <size_t S>