#include <muu/packed_unit_vector.h>
template <typename Integer, size_t Dimensions>
packed_unit_vector struct
A utility type for lossy packing of 2D or 3D unit vectors into a single integer.
muu::vector v{ 2.0f, 3.0f, 4.0f }; v.normalize(); muu::packed_unit_vector pv{ v }; // deduced as 3D with uint32_t storage muu::packed_unit_vector<uint16_t, 3> pv2{ v }; std::cout << v << " (" << sizeof(v) << " bytes)\n"; std::cout << pv << " (" << sizeof(pv) << " bytes)\n"; std::cout << pv2 << " (" << sizeof(pv2) << " bytes)";
{ 0.371391, 0.557086, 0.742781 } (12 bytes) { 0.371357, 0.557061, 0.742817 } (4 bytes) { 0.367753, 0.55163, 0.74864 } (2 bytes)
Public types
-
using constants = muu::
constants<packed_ unit_ vector> - Compile-time constants for this vector type.
- using integer_type = Integer
- The integer type used as the backing storage for this unit vector.
Public static variables
- static size_t dimensions constexpr
- The number of scalar components stored in this vector.
Constructors, destructors, conversion operators
-
template <typename T>operator vector<T, dimensions>() const explicit constexpr noexcept
- Unpacks the packed unit vector into a regular multi-component floating-point vector.
- packed_unit_vector() defaulted noexcept
- Default constructor. Storage bits are not initialized.
-
packed_unit_vector(const packed_
unit_ vector&) defaulted constexpr noexcept - Copy constructor.
-
template <typename T>packed_unit_vector(const vector<T, dimensions>& vec) explicit constexpr noexcept
- Constructs from a regular unit vector.
Public functions
-
auto operator=(const packed_
unit_ vector&) -> packed_ unit_ vector& defaulted constexpr noexcept - Copy-assigment operator.
-
template <typename T>auto unpack() const -> vector<T, dimensions> constexpr noexcept
- Unpacks the packed unit vector into a regular multi-component floating-point vector.
- auto x_negative() const -> bool constexpr noexcept
- Checks if the x-axis component is negative (without needing to unpack the vector).
- auto y_negative() const -> bool constexpr noexcept
- Checks if the y-axis component is negative (without needing to unpack the vector).
- auto z_negative() const -> bool constexpr noexcept
- Checks if the z-axis component is negative (without needing to unpack the vector).
Public variables
-
integer_
type bits - The integer used as the backing storage for this unit vector.
Friends
-
template <typename Char, typename Traits>auto operator<<(std::
basic_ostream<Char, Traits>& os, const packed_ unit_ vector& v) -> std:: basic_ostream<Char, Traits>& - Writes a packed unit vector out to a text stream.
Function documentation
muu::packed_unit_vector::packed_unit_vector(const vector<T, dimensions>& vec) explicit constexpr noexcept
Constructs from a regular unit vector.
Template parameters | |
---|---|
T | Source vector scalar type. |
Parameters | |
vec | Source vector. Should be normalized already. |