diff --git a/bezier.cpp b/bezier.cpp index 678b12d9..5e85f344 100644 --- a/bezier.cpp +++ b/bezier.cpp @@ -144,7 +144,7 @@ namespace util { std::array bezier<3>::coeffs (void) const { - auto &v = reinterpret_cast (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 bezier<2>::coeffs (void) const { - auto &v = reinterpret_cast (m_points); + auto &v = m_coeffs; return { +1 * v[2] -2 * v[1] + 1 * v[0], @@ -179,7 +179,7 @@ namespace util { std::array bezier<1>::coeffs (void) const { - auto &v = reinterpret_cast (m_points); + auto &v = m_coeffs; return { -1 * v[1] + 1 * v[0], diff --git a/bezier.hpp b/bezier.hpp index d6919a07..287a9212 100644 --- a/bezier.hpp +++ b/bezier.hpp @@ -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