|
| Vector2 (float *p_data) |
| [AI] Construct a 2D vector using an external float buffer. More...
|
|
| Vector2 (const float *p_data) |
| [AI] Construct a 2D vector from a (likely constant) array of floats without copying (just pointer assignment). More...
|
|
virtual float * | GetData () |
| [AI] Retrieves the mutable in-memory data pointer for this vector. More...
|
|
virtual const float * | GetData () const |
| [AI] Retrieves the immutable data pointer for this vector. More...
|
|
virtual void | Clear () |
| [AI] Zeros all elements (sets all coordinates to 0.0). More...
|
|
virtual float | Dot (const float *p_a, const float *p_b) const |
| [AI] Compute the dot product of the two float arrays interpreted as vectors of 2 elements. More...
|
|
virtual float | Dot (const Vector2 &p_a, const Vector2 &p_b) const |
| [AI] Compute the dot product of two Vector2 objects. More...
|
|
virtual float | Dot (const float *p_a, const Vector2 &p_b) const |
| [AI] Compute the dot product given a pointer and a Vector2 (second param). More...
|
|
virtual float | Dot (const Vector2 &p_a, const float *p_b) const |
| [AI] Compute the dot product given a Vector2 (first param) and a pointer (second param). More...
|
|
virtual float | LenSquared () const |
| [AI] Compute the squared length (magnitude^2) of the vector. More...
|
|
virtual int | Unitize () |
| [AI] Scales the vector so its norm is 1 (unit vector). More...
|
|
virtual void | operator+= (float p_value) |
| [AI] In-place add a scalar to all coordinates. More...
|
|
virtual void | operator+= (const float *p_other) |
| [AI] In-place add vector elements via float pointer. More...
|
|
virtual void | operator+= (const Vector2 &p_other) |
| [AI] In-place add another Vector2. More...
|
|
virtual void | operator-= (const float *p_other) |
| [AI] In-place subtraction of vector pointed to by p_other. More...
|
|
virtual void | operator-= (const Vector2 &p_other) |
| [AI] In-place subtraction of another Vector2. More...
|
|
virtual void | operator*= (const float *p_other) |
| [AI] In-place per-element multiplication of this vector by another array. More...
|
|
virtual void | operator*= (const Vector2 &p_other) |
| [AI] In-place per-element multiplication by another Vector2. More...
|
|
virtual void | operator*= (const float &p_value) |
| [AI] In-place multiplication by a scalar. More...
|
|
virtual void | operator/= (const float &p_value) |
| [AI] In-place scalar division. More...
|
|
virtual void | operator= (const float *p_other) |
| [AI] Assigns this vector's elements from a pointer to two floats. More...
|
|
virtual void | operator= (const Vector2 &p_other) |
| [AI] Assigns this vector's elements from another Vector2. More...
|
|
float & | operator[] (int idx) |
| [AI] Accesses the idx-th float in the vector (0 or 1). More...
|
|
const float & | operator[] (int idx) const |
| [AI] Const version of the index operator. More...
|
|
|
virtual void | AddImpl (const float *p_value) |
| [AI] Adds the values pointed to by p_value to this vector. More...
|
|
virtual void | AddImpl (float p_value) |
| [AI] Adds a scalar value to every element of this vector. More...
|
|
virtual void | SubImpl (const float *p_value) |
| [AI] Subtracts the vector specified by p_value from this vector. More...
|
|
virtual void | MulImpl (const float *p_value) |
| [AI] Multiplies this vector by another vector (per element). More...
|
|
virtual void | MulImpl (const float &p_value) |
| [AI] Multiplies this vector by a scalar value. More...
|
|
virtual void | DivImpl (const float &p_value) |
| [AI] Divides this vector by a scalar value. More...
|
|
virtual float | DotImpl (const float *p_a, const float *p_b) const |
| [AI] Computes the dot product of two arrays interpreted as vectors. More...
|
|
virtual void | SetData (float *p_data) |
| [AI] Set the internal data pointer to external storage. More...
|
|
virtual void | EqualsImpl (const float *p_data) |
| [AI] Assigns values from provided array to this vector. More...
|
|
[AI] Represents a 2D mathematical vector with floating-point coordinates.
Provides a flexible base class for 2D, 3D, and 4D specialization. Vector data may be shared externally via an internal pointer rather than fixed storage.
[AI] Vector2 supports polymorphic math (addition, subtraction, multiplication, division, dot product, etc.) through its overridden virtual member functions evaluated per element or for the whole structure. All operations can be dispatched either by a scalar, vector, or float pointer. Serves as a base for Vector3 and Vector4 to provide extensible vector algebra. The memory pointed to by m_data is not owned by Vector2; it is provided and managed externally.
Definition at line 16 of file vector.h.
void Vector2::AddImpl |
( |
const float * |
p_value | ) |
|
|
inlineprotectedvirtual |
[AI] Adds the values pointed to by p_value to this vector.
[AI] Adds a 2D float array to the vector data in-place.
- Parameters
-
p_value | Pointer to an array containing values to add. [AI] |
This is used for vector addition with an array.
- Parameters
-
p_value | Pointer to a float array containing the values to add. |
[AI] Each component of the input array is added to the corresponding component of the vector. The length must be 2.
Reimplemented in Vector3, and Vector4.
void Vector2::AddImpl |
( |
float |
p_value | ) |
|
|
inlineprotectedvirtual |
[AI] Adds a scalar value to every element of this vector.
[AI] Adds a scalar value to both components of the vector.
- Parameters
-
p_value | The value to add to each coordinate. [AI] |
p_value | The scalar value to add. |
[AI] The scalar is added to both x and y components.
Reimplemented in Vector3, and Vector4.
void Vector2::DivImpl |
( |
const float & |
p_value | ) |
|
|
inlineprotectedvirtual |
[AI] Divides this vector by a scalar value.
[AI] Divides both components of the vector by a scalar.
- Parameters
-
p_value | Scalar divisor. [AI] |
p_value | The scalar value to divide by. |
[AI] Both components are divided by the scalar. No zero check.
Reimplemented in Vector3, and Vector4.
float Vector2::DotImpl |
( |
const float * |
p_a, |
|
|
const float * |
p_b |
|
) |
| const |
|
inlineprotectedvirtual |
[AI] Computes the dot product of two arrays interpreted as vectors.
[AI] Computes the dot product of two 2D float arrays.
- Parameters
-
p_a | Pointer to the first vector. [AI] |
p_b | Pointer to the second vector. [AI] |
- Returns
- The computed dot product. [AI]
- Parameters
-
p_a | Pointer to first 2D float array. |
p_b | Pointer to second 2D float array. |
- Returns
- The resulting dot product.
[AI] Calculates and returns p_a[0]*p_b[0] + p_a[1]*p_b[1].
Reimplemented in Vector3, and Vector4.
void Vector2::EqualsImpl |
( |
const float * |
p_data | ) |
|
|
inlineprotectedvirtual |
[AI] Assigns values from provided array to this vector.
[AI] Copies the values from a float array into the vector's data.
- Parameters
-
p_data | Pointer to array to copy from. [AI] |
p_data | Pointer to float array containing the values to copy. |
[AI] Uses memcpy for fast assignment of both vector components.
Reimplemented in Vector3, and Vector4.
float Vector2::LenSquared |
( |
| ) |
const |
|
inlinevirtual |
[AI] Compute the squared length (magnitude^2) of the vector.
[AI] Returns the squared Euclidean length of the vector.
- Returns
- Squared length. [AI]
-
The sum of squares of the x and y values.
[AI] Useful for distance comparisons without sqrt.
Reimplemented in Vector3, and Vector4.
void Vector2::MulImpl |
( |
const float & |
p_value | ) |
|
|
inlineprotectedvirtual |
[AI] Multiplies this vector by a scalar value.
[AI] Multiplies both components of the vector by a scalar.
- Parameters
-
p_value | Scalar multiplier. [AI] |
p_value | The scalar value to multiply by. |
[AI] Both components are multiplied by the scalar.
Reimplemented in Vector3, and Vector4.
void Vector2::MulImpl |
( |
const float * |
p_value | ) |
|
|
inlineprotectedvirtual |
[AI] Multiplies this vector by another vector (per element).
[AI] Multiplies the vector by another 2D float array component-wise.
- Parameters
-
p_value | Pointer to the vector to multiply with. [AI] |
p_value | Pointer to a float array containing the values to multiply by. |
[AI] Each component of the vector is multiplied by the corresponding component in the input array.
Reimplemented in Vector3, and Vector4.
void Vector2::SubImpl |
( |
const float * |
p_value | ) |
|
|
inlineprotectedvirtual |
[AI] Subtracts the vector specified by p_value from this vector.
[AI] Subtracts a 2D float array from the vector data in-place.
- Parameters
-
p_value | Pointer to array to subtract. [AI] |
p_value | Pointer to a float array containing the values to subtract. |
[AI] Each component of the input array is subtracted from the corresponding component of the vector. The length must be 2.
Reimplemented in Vector3, and Vector4.
[AI] Scales the vector so its norm is 1 (unit vector).
[AI] Normalizes the vector to have unit length (if length > 0).
Returns 0 if successful, nonzero on failure (e.g. if length is 0).
- Returns
- Unitization status. [AI]
-
0 on success, -1 if length is zero.
[AI] Divides components by the vector's length. Safe against zero division.