|
Sparkle 0.0.1
|
2D value type holding two components with basic arithmetic helpers. More...
#include <spk_vector2.hpp>

Public Types | |
| using | value_type = TType |
| Component type stored by the vector. | |
Public Member Functions | |
| constexpr | IVector2 ()=default |
| Builds a zero vector. | |
| template<typename TX, typename TY> requires (std::is_constructible_v<TType, TX> && std::is_constructible_v<TType, TY>) | |
| constexpr | IVector2 (const TX &p_x, const TY &p_y) |
| Builds a vector from two components. | |
| template<typename TOther> requires std::is_constructible_v<TType, TOther> | |
| constexpr | IVector2 (const IVector2< TOther > &p_other) |
| Converting constructor from another component type. | |
| template<typename TOther> requires std::is_constructible_v<TType, TOther> | |
| constexpr | IVector2 (const TOther &p_value) |
| Fills both components with the same value. | |
| std::string | toString () const |
| Converts the vector to a string. | |
| std::wstring | toWstring () const |
| Converts the vector to a wide string. | |
| bool | operator== (const IVector2 &p_other) const |
| Checks component-wise equality using SafeComparand. | |
| bool | operator!= (const IVector2 &p_other) const |
| Negation of equality. | |
| IVector2 | operator+ (const IVector2 &p_other) const |
| Component-wise addition. | |
| IVector2 | operator- (const IVector2 &p_other) const |
| Component-wise subtraction. | |
| IVector2 | operator* (const IVector2 &p_other) const |
| Component-wise multiplication. | |
| IVector2 | operator/ (const IVector2 &p_other) const |
| Component-wise division. | |
| IVector2 | operator+ (const TType &p_scalar) const |
| Adds a scalar to each component. | |
| IVector2 | operator- (const TType &p_scalar) const |
| Subtracts a scalar from each component. | |
| IVector2 | operator* (const TType &p_scalar) const |
| Multiplies each component by a scalar. | |
| IVector2 | operator/ (const TType &p_scalar) const |
| Divides each component by a scalar. | |
| IVector2 | inverse () const |
| Return the inverse vector. | |
| IVector2 | operator- () const |
| Unary minus. | |
| IVector2 & | operator+= (const IVector2 &p_other) |
| In-place component-wise addition. | |
| IVector2 & | operator-= (const IVector2 &p_other) |
| In-place component-wise subtraction. | |
| IVector2 & | operator*= (const IVector2 &p_other) |
| In-place component-wise multiplication. | |
| IVector2 & | operator/= (const IVector2 &p_other) |
| In-place component-wise division. | |
| IVector2 & | operator+= (const TType &p_scalar) |
| In-place scalar addition. | |
| IVector2 & | operator-= (const TType &p_scalar) |
| In-place scalar subtraction. | |
| IVector2 & | operator*= (const TType &p_scalar) |
| In-place scalar multiplication. | |
| IVector2 & | operator/= (const TType &p_scalar) |
| In-place scalar division. | |
| bool | isZero () const |
| Checks if both components are zero. | |
| float | squaredLength () const |
| Computes squared vector length. | |
| IVector2< float > | normalize () const |
| Return the vector once normalized by its length. | |
| float | length () const |
| Computes Euclidean length. | |
| float | squaredDistance (const IVector2 &p_other) const |
| Computes squared distance to another vector. | |
| float | distance (const IVector2 &p_other) const |
| Computes Euclidean distance to another vector. | |
| float | dot (const IVector2 &p_other) const |
| Computes dot product with another vector. | |
| float | cross (const IVector2 &p_other) const |
| Computes 2D cross product (x1*y2 - y1*x2). | |
| IVector2 | perpendicular () const |
| Returns a perpendicular vector (rotated 90 degrees). | |
| IVector2 | clamped (const IVector2 &p_boundMinimum, const IVector2 &p_boundMaximum) const |
| Returns a clamped copy of this vector. | |
| template<typename TOther> requires std::is_constructible_v<TOther, TType> | |
| constexpr | operator IVector2< TOther > () const |
| Explicitly converts to another IVector2 component type. | |
Static Public Member Functions | |
| static IVector2 | lerp (const IVector2 &p_from, const IVector2 &p_to, const float &p_alpha) |
| Linearly interpolates between two vectors. | |
| static IVector2 | min (const IVector2 &p_a, const IVector2 &p_b) |
| Component-wise minimum of two vectors. | |
| template<typename... TOthers> requires (sizeof...(TOthers) > 0 && (std::is_same_v<TOthers, IVector2> && ...)) | |
| static IVector2 | min (const IVector2 &p_a, const IVector2 &p_b, const TOthers &...p_rest) |
| Component-wise minimum of multiple vectors. | |
| static IVector2 | min (std::initializer_list< IVector2 > p_values) |
| Component-wise minimum across an initializer list. | |
| static IVector2 | max (const IVector2 &p_a, const IVector2 &p_b) |
| Component-wise maximum of two vectors. | |
| template<typename... TOthers> requires (sizeof...(TOthers) > 0 && (std::is_same_v<TOthers, IVector2> && ...)) | |
| static IVector2 | max (const IVector2 &p_a, const IVector2 &p_b, const TOthers &...p_rest) |
| Component-wise maximum of multiple vectors. | |
| static IVector2 | max (std::initializer_list< IVector2 > p_values) |
| Component-wise maximum across an initializer list. | |
| static IVector2 | clamp (const IVector2 &p_value, const IVector2 &p_boundMinimum, const IVector2 &p_boundMaximum) |
| Clamps each component of a vector between two bounds. | |
| static bool | isBetween (const IVector2 &p_value, const IVector2 &p_valueA, const IVector2 &p_valueB) |
| Checks whether a vector lies within inclusive bounds. | |
Public Attributes | |
| TType | x {} |
| X component. | |
| TType | y {} |
| Y component. | |
Static Public Attributes | |
| static const IVector2 | Zero |
| Predefined zero vector. | |
| static const IVector2 | One |
| Predefined unit vector (1, 1). | |
Friends | |
| std::ostream & | operator<< (std::ostream &p_stream, const IVector2 &p_value) |
| Streams the vector to an output stream. | |
| std::wostream & | operator<< (std::wostream &p_stream, const IVector2 &p_value) |
| Streams the vector to a wide output stream. | |
| IVector2 | operator+ (const TType &p_scalar, const IVector2 &p_vector) |
| Adds a scalar to a vector (scalar on the left side). | |
| IVector2 | operator- (const TType &p_scalar, const IVector2 &p_vector) |
| Subtracts vector components from a scalar (scalar on the left side). | |
| IVector2 | operator* (const TType &p_scalar, const IVector2 &p_vector) |
| Multiplies a scalar by a vector (scalar on the left side). | |
| IVector2 | operator/ (const TType &p_scalar, const IVector2 &p_vector) |
| Divides a scalar by each vector component (scalar on the left side). | |
2D value type holding two components with basic arithmetic helpers.
| TType | arithmetic component type; must be constructible from input values and support +, -, * and / and self assignation operator, in addition to comparisons. |
|
inlineconstexpr |
Builds a vector from two components.
| p_x | X value. |
| p_y | Y value. |
|
inlineexplicitconstexpr |
Converting constructor from another component type.
| TOther | source component type; must be constructible into TType. |
| p_other | Source vector to copy and cast from. |
|
inlineexplicitconstexpr |
Fills both components with the same value.
| p_value | Component value to duplicate. |
|
inlinestatic |
Clamps each component of a vector between two bounds.
| p_value | Value to clamp. |
| p_boundMinimum | Minimal value to clamp onto. |
| p_boundMaximum | Maximam value to clamp onto. |

|
inline |
Returns a clamped copy of this vector.
| p_boundMinimum | Minimal value to clamp onto. |
| p_boundMaximum | Maximam value to clamp onto. |
|
inline |
Computes 2D cross product (x1*y2 - y1*x2).
| p_other | Target vector. |
|
inline |
Computes Euclidean distance to another vector.
| p_other | Target vector. |
|
inline |
Computes dot product with another vector.
| p_other | Target vector. |
|
inline |
Return the inverse vector.

|
inlinestatic |
Checks whether a vector lies within inclusive bounds.
| p_value | Value to test. |
| p_valueA | Lower bound of the check. |
| p_valueB | Higher bound of the check. |
|
inline |
Checks if both components are zero.

|
inline |
Computes Euclidean length.

|
inlinestatic |
Linearly interpolates between two vectors.
| p_from | Start vector. |
| p_to | End vector. |
| p_alpha | Interpolation factor (0 -> start, 1 -> end); not clamped. |
|
inlinestatic |
Component-wise maximum of two vectors.
| p_a | First vector. |
| p_b | Second vector. |

|
inlinestatic |
Component-wise maximum of multiple vectors.
| TOthers | Additional vector types (must be IVector2). |
| p_a | First vector. |
| p_b | Second vector. |
| p_rest | Remaining vectors. |
|
inlinestatic |
Component-wise maximum across an initializer list.
| p_values | Collection of vectors (must contain at least one element). |
| std::invalid_argument | when the list is empty. |
|
inlinestatic |
Component-wise minimum of two vectors.
| p_a | First vector. |
| p_b | Second vector. |

|
inlinestatic |
Component-wise minimum of multiple vectors.
| TOthers | Additional vector types (must be IVector2). |
| p_a | First vector. |
| p_b | Second vector. |
| p_rest | Remaining vectors. |
|
inlinestatic |
Component-wise minimum across an initializer list.
| p_values | Collection of vectors (must contain at least one element). |
| std::invalid_argument | when the list is empty. |
|
inline |
Return the vector once normalized by its length.
|
inlineexplicitconstexpr |
Explicitly converts to another IVector2 component type.
| TOther | Target component type; must be constructible from TType. |
|
inline |
Negation of equality.
| p_other | Vector to compare against. |
|
inline |
Component-wise multiplication.
| p_other | Vector to multiply. |
|
inline |
Multiplies each component by a scalar.
| p_scalar | Scalar factor. |
|
inline |
In-place component-wise multiplication.
| p_other | Vector multiplier. |
|
inline |
In-place scalar multiplication.
| p_scalar | Scalar factor. |
|
inline |
Component-wise addition.
| p_other | Vector to add. |
|
inline |
Adds a scalar to each component.
| p_scalar | Scalar value to add. |
|
inline |
In-place component-wise addition.
| p_other | Vector to add. |
|
inline |
In-place scalar addition.
| p_scalar | Scalar to add. |
|
inline |
Unary minus.
|
inline |
Component-wise subtraction.
| p_other | Vector to subtract. |
|
inline |
Subtracts a scalar from each component.
| p_scalar | Scalar value to subtract. |
|
inline |
In-place component-wise subtraction.
| p_other | Vector to subtract. |
|
inline |
In-place scalar subtraction.
| p_scalar | Scalar to subtract. |
|
inline |
Component-wise division.
| p_other | Vector to divide by. |
| std::invalid_argument | when any divisor component is zero. |
|
inline |
Divides each component by a scalar.
| p_scalar | Scalar divisor. |
| std::invalid_argument | when divisor is zero. |
|
inline |
In-place component-wise division.
| p_other | Vector divisor. |
| std::invalid_argument | when any divisor component is zero. |
|
inline |
In-place scalar division.
| p_scalar | Scalar divisor. |
| std::invalid_argument | when divisor is zero. |
|
inline |
Checks component-wise equality using SafeComparand.
| p_other | Vector to compare against. |
|
inline |
Returns a perpendicular vector (rotated 90 degrees).
|
inline |
Computes squared distance to another vector.
| p_other | Target vector. |
|
inline |
Computes squared vector length.

|
inline |
Converts the vector to a string.
|
inline |
Converts the vector to a wide string.
|
friend |
Multiplies a scalar by a vector (scalar on the left side).
| p_scalar | Scalar factor. |
| p_vector | Vector value. |
|
friend |
Adds a scalar to a vector (scalar on the left side).
| p_scalar | Scalar value. |
| p_vector | Vector value. |
|
friend |
Subtracts vector components from a scalar (scalar on the left side).
| p_scalar | Scalar value. |
| p_vector | Vector value. |
|
friend |
Divides a scalar by each vector component (scalar on the left side).
| p_scalar | Scalar numerator. |
| p_vector | Vector divisor. |
| std::invalid_argument | when any divisor component is zero. |
|
friend |
Streams the vector to an output stream.
| p_stream | Destination stream. |
| p_value | Vector to print. |
|
friend |
Streams the vector to a wide output stream.
| p_stream | Destination stream. |
| p_value | Vector to print. |