#include <xrb_vector.hpp>
Public Member Functions | |
Vector () | |
Default constructor. | |
Vector (T const fill_with) | |
Constructs a Vector, setting each component to fill_with . | |
Vector (T const component0, T const component1) | |
Constructs a vector with the specified ordered pair. | |
Vector (T const component0, T const component1, T const component2) | |
Constructs a vector with the specified ordered triplet. | |
Vector (T const *const components) | |
Constructs a vector from an array of component values. | |
Vector (Vector< T, dimension > const &source) | |
Copy constructor. | |
~Vector () | |
Destructor. | |
void | operator= (Vector< T, dimension > const &operand) |
Assignment operator. | |
bool | operator== (Vector< T, dimension > const &operand) const |
Equality operator. | |
bool | operator!= (Vector< T, dimension > const &operand) const |
Inequality operator. | |
T const & | operator[] (Uint32 const index) const |
Bracket operator with const qualification. | |
T & | operator[] (Uint32 const index) |
Bracket operator. | |
void | operator+= (Vector< T, dimension > const &operand) |
In-place addition operator. | |
void | operator-= (Vector< T, dimension > const &operand) |
In-place addition operator. | |
void | operator*= (Vector< T, dimension > const &operand) |
In-place multiplication operator. | |
template<typename U > | |
void | operator*= (U const operand) |
In-place multiplication operator. | |
void | operator/= (Vector< T, dimension > const &operand) |
In-place division operator. | |
template<typename U > | |
void | operator/= (U const operand) |
In-place division operator. | |
Vector< T, dimension > | operator- () const |
Unary negation operator. | |
T | Length () const |
Returns the length of this vector. | |
T | LengthSquared () const |
Returns the square of the length of this vector. | |
Vector< T, dimension > | Normalization () const |
Returns the normalized version of this vector. | |
bool | IsZero () const |
Test for equality with the zero vector. | |
template<typename U > | |
Vector< U, dimension > | StaticCast () const |
The Vector equivalent to static_cast. | |
void | FillWith (T const fill_with) |
Sets each component in this vector to the specified value. | |
void | Negate () |
Sets this vector to the negative of itself. | |
void | Normalize () |
Sets this vector's length to 1, while preserving its direction. | |
void | SetComponents (T const component0, T const component1) |
Assigns the specified ordered pair to this vector. | |
void | SetComponents (T const component0, T const component1, T const component2) |
Assigns the specified ordered triplet to this vector. | |
void | SetComponents (T const *const components) |
Assigns the specified ordered array of components to the components of this vector. | |
template<typename U > | |
void | StaticCastAssign (Vector< U, dimension > const &source) |
The Vector equivalent to vector1 = static_cast<T>(vector2). | |
void | Fprint (FILE *const fptr, char const *const component_printf_format, bool const add_newline=true) const |
Prints the dimension and components of this vector to the given file stream. | |
Public Attributes | |
T | m [dimension] |
The array which stores the vector's components. | |
Static Public Attributes | |
static Vector< T, dimension > const | ms_zero |
The zero vector. |
The scalar template type given for each instantiation of Vector must have certain operations defined. Namely, addition, subtraction, unary negation, multiplication, division and a square root function.
The type must be a regular assignable type (not a type with possibly a vtable, and definitely not a type which requires deep copying to perform assignment). This is because if XRB_VECTOR_USES_MEMCPY is defined, memcpy() is used to increase efficiency on certain operations. Also, if XRB_VECTOR_USES_MEMCMP is defined, memcmp() is used on certain operations. The default behavior is to iterate over each component for operations.
Definition at line 56 of file xrb_vector.hpp.
Xrb::Vector< T, dimension >::Vector | ( | ) | [inline] |
Default constructor.
Does no initialization for the sake of efficiency.
Definition at line 78 of file xrb_vector.hpp.
Xrb::Vector< T, dimension >::Vector | ( | T const | fill_with | ) | [inline, explicit] |
Constructs a Vector, setting each component to fill_with
.
Does/can not use any memcpy/memset functions.
fill_with | The value to set each component to. |
Definition at line 85 of file xrb_vector.hpp.
Xrb::Vector< T, dimension >::Vector | ( | T const | component0, | |
T const | component1 | |||
) | [inline] |
Constructs a vector with the specified ordered pair.
I gave up trying for partial template specialization (or whatever it's called) to specify the two-parameter constructor for only Vector<T, 2>, and settled for asserting that dimension
is 2.
component0 | The value to assign to the first component (m[0]). | |
component1 | The value to assign to the second component (m[1]). |
Definition at line 97 of file xrb_vector.hpp.
Xrb::Vector< T, dimension >::Vector | ( | T const | component0, | |
T const | component1, | |||
T const | component2 | |||
) | [inline] |
Constructs a vector with the specified ordered triplet.
I gave up trying for partial template specialization (or whatever it's called) to specify the three-parameter constructor for only Vector<T, 3>, and settled for asserting that dimension
is 3.
component0 | The value to assign to the first component (m[0]). | |
component1 | The value to assign to the second component (m[1]). | |
component2 | The value to assign to the third component (m[2]). |
Definition at line 111 of file xrb_vector.hpp.
Xrb::Vector< T, dimension >::Vector | ( | T const *const | components | ) | [inline] |
Constructs a vector from an array of component values.
components | The array of ordered components to construct this vector with. Must be at least dimension elements long. |
Definition at line 123 of file xrb_vector.hpp.
Xrb::Vector< T, dimension >::Vector | ( | Vector< T, dimension > const & | source | ) | [inline] |
Copy constructor.
source | The vector to copy. |
Definition at line 136 of file xrb_vector.hpp.
Xrb::Vector< T, dimension >::~Vector | ( | ) | [inline] |
void Xrb::Vector< T, dimension >::operator= | ( | Vector< T, dimension > const & | operand | ) | [inline] |
Assignment operator.
operand | The vector to assign. |
Definition at line 159 of file xrb_vector.hpp.
bool Xrb::Vector< T, dimension >::operator== | ( | Vector< T, dimension > const & | operand | ) | const [inline] |
Equality operator.
operand | The vector to test equality against. |
Definition at line 173 of file xrb_vector.hpp.
bool Xrb::Vector< T, dimension >::operator!= | ( | Vector< T, dimension > const & | operand | ) | const [inline] |
Inequality operator.
operand | The vector to test inequality against. |
Definition at line 189 of file xrb_vector.hpp.
T const& Xrb::Vector< T, dimension >::operator[] | ( | Uint32 const | index | ) | const [inline] |
Bracket operator with const qualification.
Array index referencing. Emulates the syntax of a normal array, giving a more appealing usage (vector[1] instead of vector.m[1]).
index | The index of the component to reference. |
Definition at line 206 of file xrb_vector.hpp.
T& Xrb::Vector< T, dimension >::operator[] | ( | Uint32 const | index | ) | [inline] |
Bracket operator.
Array index referencing. Emulates the syntax of a normal array, giving a more appealing usage (vector[1] instead of vector.m[1]).
index | The index of the component to reference. |
Definition at line 217 of file xrb_vector.hpp.
void Xrb::Vector< T, dimension >::operator+= | ( | Vector< T, dimension > const & | operand | ) | [inline] |
In-place addition operator.
Performs vector addition on this and the given vector, storing the result in this vector.
operand | The vector to add to this vector. |
Definition at line 227 of file xrb_vector.hpp.
void Xrb::Vector< T, dimension >::operator-= | ( | Vector< T, dimension > const & | operand | ) | [inline] |
In-place addition operator.
Performs vector subtraction on this and the given vector, storing the result in this vector.
operand | The vector to subtract from this vector. |
Definition at line 237 of file xrb_vector.hpp.
void Xrb::Vector< T, dimension >::operator*= | ( | Vector< T, dimension > const & | operand | ) | [inline] |
In-place multiplication operator.
Performs scalar multiplication of the components of operand
on each respective component of this vector, storing the result in this vector.
operand | The vector to component-wise multiply this vector by. |
Definition at line 249 of file xrb_vector.hpp.
void Xrb::Vector< T, dimension >::operator*= | ( | U const | operand | ) | [inline] |
In-place multiplication operator.
Performs scalar multiplication on this vector by the given scalar storing the result in this vector.
operand | The scalar value to multiply this vector by. |
Definition at line 260 of file xrb_vector.hpp.
void Xrb::Vector< T, dimension >::operator/= | ( | Vector< T, dimension > const & | operand | ) | [inline] |
In-place division operator.
Performs scalar division of the components of this vector by each respective component of operand
, storing the result in this vector.
operand | The vector to component-wise divide this vector by. |
Definition at line 273 of file xrb_vector.hpp.
Referenced by Xrb::Vector< Float, 2 >::Normalize().
void Xrb::Vector< T, dimension >::operator/= | ( | U const | operand | ) | [inline] |
In-place division operator.
Performs scalar division on this vector by the given scalar storing the result in this vector.
operand | The scalar value to divide this vector by. |
Definition at line 285 of file xrb_vector.hpp.
Vector<T, dimension> Xrb::Vector< T, dimension >::operator- | ( | ) | const [inline] |
Unary negation operator.
Definition at line 293 of file xrb_vector.hpp.
T Xrb::Vector< T, dimension >::Length | ( | ) | const [inline] |
Returns the length of this vector.
Uses a square root function specific to Vector<T, dimension, Float>, and thus for integral scalar types, the actual vector length after this procedure may not be 1.
Definition at line 311 of file xrb_vector.hpp.
T Xrb::Vector< T, dimension >::LengthSquared | ( | ) | const [inline] |
Returns the square of the length of this vector.
This is as close as you can come to the length of a vector without needing a square root function.
Definition at line 320 of file xrb_vector.hpp.
Vector<T, dimension> Xrb::Vector< T, dimension >::Normalization | ( | ) | const [inline] |
Returns the normalized version of this vector.
Uses a square root function specific to Vector<T, dimension, Float>, and thus for integral scalar types, the actual vector length after this procedure may not be 1.
Definition at line 330 of file xrb_vector.hpp.
bool Xrb::Vector< T, dimension >::IsZero | ( | ) | const [inline] |
Test for equality with the zero vector.
Definition at line 340 of file xrb_vector.hpp.
Vector<U, dimension> Xrb::Vector< T, dimension >::StaticCast | ( | ) | const [inline] |
The Vector equivalent to static_cast.
Performs static_cast on each of this Vector's components to convert the values to the desired.
Definition at line 357 of file xrb_vector.hpp.
Referenced by Xrb::WidgetSkin::RatiosFromScreenCoords().
void Xrb::Vector< T, dimension >::FillWith | ( | T const | fill_with | ) | [inline] |
Sets each component in this vector to the specified value.
fill_with | The value to assign to each vector component. |
Definition at line 372 of file xrb_vector.hpp.
void Xrb::Vector< T, dimension >::Negate | ( | ) | [inline] |
Sets this vector to the negative of itself.
The in-place negation of this vector, or to put another way,
ms_zero - *this
Definition at line 381 of file xrb_vector.hpp.
void Xrb::Vector< T, dimension >::Normalize | ( | ) | [inline] |
Sets this vector's length to 1, while preserving its direction.
Uses a square root function specific to Vector<T, dimension, Float>, and thus for integral scalar types, the actual vector length after this procedure may not be 1.
Definition at line 391 of file xrb_vector.hpp.
Referenced by Xrb::Vector< Float, 2 >::Normalization().
void Xrb::Vector< T, dimension >::SetComponents | ( | T const | component0, | |
T const | component1 | |||
) | [inline] |
Assigns the specified ordered pair to this vector.
I gave up trying for partial template specialization (or whatever it's called) to specify the two-parameter SetComponents for only Vector<T, 2>, and settled for asserting that the dimension is 2.
component0 | The value to assign to the first component (m[0]). | |
component1 | The value to assign to the second component (m[1]). |
Definition at line 402 of file xrb_vector.hpp.
void Xrb::Vector< T, dimension >::SetComponents | ( | T const | component0, | |
T const | component1, | |||
T const | component2 | |||
) | [inline] |
Assigns the specified ordered triplet to this vector.
I gave up trying for partial template specialization (or whatever it's called) to specify the three-parameter SetComponents for only Vector<T, 3>, and settled for asserting that the dimension is 3.
component0 | The value to assign to the first component (m[0]). | |
component1 | The value to assign to the second component (m[1]). | |
component2 | The value to assign to the third component (m[2]). |
Definition at line 416 of file xrb_vector.hpp.
void Xrb::Vector< T, dimension >::SetComponents | ( | T const *const | components | ) | [inline] |
Assigns the specified ordered array of components to the components of this vector.
components | The array of ordered components to assign to this vector. Must be at least dimension elements long. |
Definition at line 429 of file xrb_vector.hpp.
void Xrb::Vector< T, dimension >::StaticCastAssign | ( | Vector< U, dimension > const & | source | ) | [inline] |
The Vector equivalent to vector1 = static_cast<T>(vector2).
Performs static_cast on each of the operand vector's components to convert the values.
source | The vector to assign. |
Definition at line 445 of file xrb_vector.hpp.
void Xrb::Vector< T, dimension >::Fprint | ( | FILE *const | fptr, | |
char const *const | component_printf_format, | |||
bool const | add_newline = true | |||
) | const [inline] |
Prints the dimension and components of this vector to the given file stream.
The format of each vector component is specified by component_printf_format, which should be the printf format string for a single vector component. This value must be passed in because the printf format is not known in the general case.
fptr | The file stream to print to (e.g. stderr). | |
component_printf_format | The printf format string for a single vector component. | |
add_newline | Indicates if a newline should be printed as the last character (default value is true). |
Definition at line 467 of file xrb_vector.hpp.
Referenced by Xrb::Fprint().
Vector< T, dimension > const Xrb::Vector< T, dimension >::ms_zero [inline, static] |
The zero vector.
Templatized static definition of the ms_zero
vector.
This member serves as the type-specific zero vector for use in the IsZero and IsNonZero functions, as well as providing a fast, convenient and elegant way to refer to possibly the most commonly used vector value.
This templatized definition will take care of defining the static ms_zero
member vector, assuming that static_cast<T>(0)
work.
Definition at line 66 of file xrb_vector.hpp.
Referenced by Xrb::Vector< Float, 2 >::IsZero().