Source

neglect / neglect / cpplib / include / neglect / quaternion_io.hpp

Full commit
#ifndef _INC_NEGLECT_QUATERNION_IO_HPP_
#define _INC_NEGLECT_QUATERNION_IO_HPP_

#include <neglect/quaternion.hpp>

#include <iostream>

namespace neglect {

    template <typename T>
    std::ostream &operator<<(std::ostream &lhs, const quaternion<T> &q)
    {
        lhs << "(" << q.w;
        if (q.vec.x >= T())
            lhs << " + " << q.vec.x;
        else
            lhs << " - " << std::abs(q.vec.x);
        lhs << "i";
        if (q.vec.y >= T())
            lhs << " + " << q.vec.y;
        else
            lhs << " - " << std::abs(q.vec.y);
        lhs << "j";
        if (q.vec.z >= T())
            lhs << " + " << q.vec.z;
        else
            lhs << " - " << std::abs(q.vec.z);
        lhs << "k)";
        return lhs;
    }

}

#endif