A high-performance two-dimensional vector implementation using fixed-point arithmetic.
Vector2D provides a comprehensive set of 2D vector operations optimized for Saturn hardware. It uses fixed-point arithmetic (Fxp) for all components to avoid floating-point operations while maintaining high precision.
Key features:
Common applications:
The implementation follows a right-handed coordinate system where:
#include <vector2d.hpp>
Public Member Functions | |
constexpr | Vector2D () |
Default constructor, initializes all coordinates to 0. | |
constexpr | Vector2D (const Fxp &fxp) |
Constructor to initialize all coordinates with the same value. | |
constexpr | Vector2D (const Fxp &valueX, const Fxp &valueY) |
Constructor to initialize coordinates with specific values. | |
constexpr | Vector2D (const Vector2D &vec) |
Copy constructor. | |
constexpr Vector2D | Abs () const |
Calculate the absolute values of each coordinate. | |
constexpr Fxp | Cross (const Vector2D &vec) const |
Calculate the cross product (z-component) of this vector and another Vector2D. | |
template<Precision P = Precision::Default> | |
constexpr Fxp | DistanceTo (const Vector2D &other) const |
Calculate the Euclidean distance from this vector to another vector. | |
constexpr Fxp | Dot (const Vector2D &vec) const |
Calculate the dot product of this vector with another vector. | |
template<Precision P = Precision::Default> | |
constexpr Fxp | Length () const |
Calculate the length of the vector. | |
constexpr Fxp | LengthSquared () const |
Calculate the squared length of the vector. | |
template<Precision P = Precision::Default> | |
constexpr Vector2D | Normalize () const |
Normalize the vector. | |
constexpr bool | operator!= (const Vector2D &vec) const |
Check if two Vec3 objects are not equal. | |
constexpr Vector2D | operator* (const Fxp &scalar) const |
Scalar multiplication operator. | |
template<typename T> requires std::is_integral_v<T> | |
constexpr Vector2D | operator* (const T &scalar) const |
Scalar multiplication operator for integral types. | |
constexpr Vector2D & | operator*= (const Fxp &scalar) |
Compound multiplication assignment operator. | |
template<typename T> requires std::is_integral_v<T> | |
constexpr Vector2D & | operator*= (const T &scalar) |
Compound multiplication assignment operator for integral types. | |
constexpr Vector2D | operator+ (const Vector2D &vec) const |
Vector addition operator. | |
constexpr Vector2D & | operator+= (const Vector2D &vec) |
Compound addition assignment operator. | |
constexpr Vector2D | operator- () const |
Unary negation operator. | |
constexpr Vector2D | operator- (const Vector2D &vec) const |
Vector subtraction operator. | |
constexpr Vector2D & | operator-= (const Vector2D &vec) |
Compound subtraction assignment operator. | |
constexpr Vector2D | operator/ (const Fxp &scalar) const |
Scalar division operator. | |
template<typename T> requires std::is_integral_v<T> | |
constexpr Vector2D | operator/ (const T &scalar) const |
Scalar division operator for integral types. | |
constexpr Vector2D & | operator/= (const Fxp &scalar) |
Compound division assignment operator. | |
template<typename T> requires std::is_integral_v<T> | |
constexpr Vector2D & | operator/= (const T &scalar) |
Compound division assignment operator for integral types. | |
constexpr bool | operator< (const Vector2D &vec) const |
Less than operator. | |
constexpr Vector2D | operator<< (const size_t &shiftAmount) |
Bitwise left shift operator. | |
constexpr Vector2D & | operator<<= (const size_t &shiftAmount) |
Bitwise left shift assignment operator. | |
constexpr bool | operator<= (const Vector2D &vec) const |
Less than or equal operator. | |
constexpr Vector2D & | operator= (const Vector2D &vec) |
Assignment operator. | |
constexpr bool | operator== (const Vector2D &vec) const |
Check if two Vec3 objects are not equal. | |
constexpr bool | operator> (const Vector2D &vec) const |
Greater than operator. | |
constexpr bool | operator>= (const Vector2D &vec) const |
Greater than or equal operator. | |
constexpr Vector2D | operator>> (const size_t &shiftAmount) |
Bitwise right shift operator. | |
constexpr Vector2D & | operator>>= (const size_t &shiftAmount) |
Bitwise right shift assignment operator. | |
template<SortOrder O = SortOrder::Ascending> | |
constexpr Vector2D | Sort () const |
Sort coordinates in specified order. | |
Static Public Member Functions | |
static void | DotAccumulate (const Vector2D &first, const Vector2D &second) |
Helper function to perform assembly-level dot product calculation and accumulation. | |
static consteval Vector2D | Down () |
Get a vector pointing down (0,-1). | |
static consteval Vector2D | Left () |
Get a vector pointing left (-1,0). | |
template<typename... Pairs> | |
static constexpr Fxp | MultiDotAccumulate (const Pairs &... pairs) |
Calculate and accumulate the dot products of multiple 2D vector pairs. | |
static consteval Vector2D | One () |
Get a vector with all components set to one (1,1). | |
static consteval Vector2D | Right () |
Get a vector pointing right (1,0). Same as UnitX(), provided for semantic clarity. | |
static consteval Vector2D | UnitX () |
Get a unit vector pointing along the X axis (1,0). | |
static consteval Vector2D | UnitY () |
Get a unit vector pointing along the Y axis (0,1). | |
static consteval Vector2D | Up () |
Get a vector pointing up (0,1). Same as UnitY(), provided for semantic clarity. | |
static consteval Vector2D | Zero () |
Get a zero vector (0,0). | |
Public Attributes | |
Fxp | X |
Fxp | Y |