Pasha Bibko Util Library
|
Mathmatical vector class. More...
#include <Vec.h>
Public Member Functions | |
template<typename = std::enable_if_t<std::is_default_constructible_v<Ty>>> | |
Vec () | |
Default constructor which default constructs all items. | |
Vec (const Ty &value) | |
Constructor to create each item in the vector with a given value. | |
template<typename... Args> requires Internal::AllSameType<Ty, Args...> && (sizeof...(Args) == len) | |
Vec (Args &&... args) | |
Creates a vector with a given value for each item. | |
Ty & | operator[] (std::size_t index) |
Returns a reference to the item at that index. | |
Ty * | begin () noexcept |
Returns a pointer to the beginning of the array. | |
Ty * | end () |
Returns a pointer to the end of the vector. | |
template<typename OtherTy > requires Internal::CanAdd<Ty, OtherTy> && std::is_same_v<Ty, Internal::AddResultT<Ty, OtherTy>> | |
Vec & | operator+= (const Vec< len, OtherTy > &other) |
Adds another vector of the same size to itself. | |
template<typename OtherTy > requires Internal::CanSub<Ty, OtherTy> && std::is_same_v<Ty, Internal::SubResultT<Ty, OtherTy>> | |
Vec & | operator-= (const Vec< len, OtherTy > &other) |
Subtracts another vector of the same size to itself. | |
template<typename OtherTy > requires Internal::CanMul<Ty, OtherTy> && std::is_same_v<Ty, Internal::MulResultT<Ty, OtherTy>> | |
Vec & | operator*= (const Vec< len, OtherTy > &other) |
Multiplies another vector of the same size to itself. | |
template<typename OtherTy > requires Internal::CanDiv<Ty, OtherTy> && std::is_same_v<Ty, Internal::DivResultT<Ty, OtherTy>> | |
Vec & | operator/= (const Vec< len, OtherTy > &other) |
Divides another vector of the same size to itself. | |
Mathmatical vector class.
len | The length of the array, cannot be 0 or 1. |
Ty | The type that the vector contains must be copyable. |
The Vec
class is a fixed-size, strongly-typed mathematical vector implementation that supports compile-time size checking and type constraints. It is designed for mathematical operations and performance-critical applications where a fixed size and no dynamic memory allocation are desired.
For convenience whilst using there are also multiple typedefs for easier recognition of common Vec types. For vectors between size of 2 and 4 you are able to write Vec2<Ty> / Vec3<Ty> / Vec4<Ty> where Ty is the type that you want the vector to contain. If no type is provided it will default to float.
Combined with this, there are also typedefs of these lengths with the types. Below are the Vec2 types but the number can be changed to work with Vec3 and Vec4.
For further convenience vectors between the lengths of 2 and 4 allow access to their members via letters:
If you are working with colours you are also able to use those letters (only available on Vec3 and Vec4):
Letters are only availble if the vector is already that long, for example: Vec2 only has access to x and y as it is only 2 elements long.
Example usage:
Default constructor which default constructs all items.
Will only be available if Ty has a default constructor to avoid compile-time errors.
Constructor to create each item in the vector with a given value.
value | The value that will be copied to all values within the vector. |
Creates a vector with a given value for each item.
args | The arguments that will be copied to the contents of the vector. |
Requires all arguments to be the same type as Ty and have the same length as the array or will have a compile-time error.
Returns a pointer to the beginning of the array.
Used by C++ to allow the data type to be iterated over by a range for loop.
Returns a pointer to the end of the vector.
Used by C++ to allow the data type to be iterated over by a range for loop.
|
inline |
Multiplies another vector of the same size to itself.
Requires Ty to be able to be multipled by OtherTy, otherwise it will not compile and the result type to be the same as Ty.
|
inline |
Adds another vector of the same size to itself.
Requires OtherTy to be able to be added to Ty, otherwise it will not compile and the result type to be the same as Ty.
|
inline |
Subtracts another vector of the same size to itself.
Requires OtherTy to be able to be subtracted from Ty, otherwise it will not compile and the result type to be the same as Ty.
|
inline |
Divides another vector of the same size to itself.
Requires Ty to be able to be divided by OtherTy, otherwise it will not compile and the result type to be the same as Ty.
Returns a reference to the item at that index.
index | The index that it will find the item of. |