CGPdocs

vecN

Operations shared by all vectors (vec2, vec3, vec4), written once for any size.

Applies to: vec2, vec3, vec4

template numarray_stack<T,N>module 02_numarraysource: numarray_stack.hpp
vec2, vec3 and vec4 store their floats x, y, z, w side by side (indices 0 to 3); the same element has four spellings, and the common calls are norm, normalize, dot and cross.
vec2, vec3 and vec4 store their floats x, y, z, w side by side (indices 0 to 3); the same element has four spellings, and the common calls are norm, normalize, dot and cross. Tap to enlarge.

Fields and methods

Members of the primary template numarray_stack. Most of what you do with a CGP type goes through the free functions listed below.

Fields

std::array<T,N> datastd::array holding the N components, stored contiguously.

Methods

Number of components N, fixed at compile time. src
Sets the N components to the given value and returns the vector. src
Returns the element at index, bound-checked unless CGP_NO_DEBUG is defined. src
Returns a const reference to the element at the given index, with bound checking unless CGP_NO_DEBUG is defined. src
Returns a const reference to the element at the given index; bound-checked for sizes 2, 3 and 4 (vec2, vec3, vec4) unless CGP_NO_DEBUG is defined, but not checked for the other sizes N. src
Returns a const iterator to the first element (a plain pointer for sizes 2, 3 and 4). src
Returns a const iterator one past the last element (a plain pointer for sizes 2, 3 and 4). src
Returns a const iterator to the first element (a plain pointer for sizes 2, 3 and 4). src
Returns a const iterator one past the last element (a plain pointer for sizes 2, 3 and 4). src
Returns a const reference to the element at the given index, without bound checking. src

Functions taking any vecN

Transform 14

template <typename T, int N>
numarray_stack<T,N> abs(numarray_stack<T,N> const& a)

Component-wise absolute value.

add

2 overloads
template <typename T, int N>
numarray_stack<T,N> add(numarray_stack<T,N> const& a, T const& b)
source
template <typename T, int N>
numarray_stack<T,N> add(T const& a, numarray_stack<T,N> const& b)
source

Add a scalar to each component.

template <typename T, int N>
numarray_stack<T,N> clamp(
    numarray_stack<T,N> const& x,
    numarray_stack<T,N> const& p_min,
    numarray_stack<T,N> const& p_max
)

Component-wise clamp between a min and max vector.

div

3 overloads
template <typename T, int N>
numarray_stack<T,N> div(numarray_stack<T,N> const& a, T const& b)
source

Divide each component by a scalar.

template <typename T, int N>
numarray_stack<T,N> div(T const& a, numarray_stack<T,N> const& b)
source

Scalar divided by each component.

template <typename T, int N>
numarray_stack<T,N> div(numarray_stack<T,N> const& a, T b)
source

Divide each component by a scalar.

mul

3 overloads
template <typename T, int N>
numarray_stack<T,N> mul(numarray_stack<T,N> const& a, T const& b)
source

Multiply each component by a scalar.

template <typename T, int N>
numarray_stack<T,N> mul(T const& a, numarray_stack<T,N> const& b)
source

Multiply each component by a scalar.

template <typename T, int N>
numarray_stack<T,N> mul(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)
source

Component-wise (Hadamard) product.

normalize

2 overloads
template <typename T, int N>
numarray_stack<T,N> normalize(numarray_stack<T,N> const& v)
source

Unit vector in the same direction (asserts on near-zero norm).

template <typename T, int N>
numarray_stack<T,N> normalize(numarray_stack<T,N> const& v, numarray_stack<T,N> const& default_zero_norm)
source

Unit vector, returning a given default when the norm is near zero.

sub

2 overloads
template <typename T, int N>
numarray_stack<T,N> sub(numarray_stack<T,N> const& a, T const& b)
source

Subtract a scalar from each component.

template <typename T, int N>
numarray_stack<T,N> sub(T const& a, numarray_stack<T,N> const& b)
source

Scalar minus each component.

Compute 6

template <typename T, int N>
T average(numarray_stack<T,N> const& a)

Mean of the components.

template <typename T, int N>
T dot(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)

Dot (scalar) product of two vectors.

template <typename T, int N>
T max(numarray_stack<T,N> const& v)

Largest component.

template <typename T, int N>
T min(numarray_stack<T,N> const& v)

Smallest component.

template <typename T, int N>
T norm(numarray_stack<T,N> const& v)

Euclidean length of the vector.

template <typename T, int N>
T sum(numarray_stack<T,N> const& v)

Sum of the components.

Convert 2

template <typename T, int N>
std::string str(
    numarray_stack<T,N> const& v,
    std::string const& separator = " ",
    std::string const& begin = "",
    std::string const& end = ""
)

Text representation of the components, joined by separator and surrounded by begin and end.

template <typename T, int N>
std::string type_str(numarray_stack<T,N> const&)

Type name as a string, e.g. "numarray_stack<float,5>".

I/O 1

template <typename T, int N>
std::istream& read_from_stream(std::istream& stream, numarray_stack<T,N>& data)

Reads the N components of a vector from the stream, stopping early if the stream fails.

Access 6

template <typename T, int N, typename INDEX_TYPE>
void check_index_bounds(INDEX_TYPE index, numarray_stack<T,N> const& data)

Raises an error if the index is outside [0, N-1]; no-op when CGP_NO_DEBUG is defined.

template <int idx, typename T, int N>
T const& get(numarray_stack<T,N> const& data)
T& get(numarray_stack<T,N>& data)

Component idx with the index checked at compile time (static_assert).

is_equal

2 overloads
template <typename T1, typename T2, int N1, int N2>
bool is_equal(numarray_stack<T1,N1> const& a, numarray_stack<T2,N2> const& b)
source

Component-wise equality of two fixed-size vectors, approximate for floating-point values; false if sizes differ.

template <typename T, int N>
bool is_equal(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)
source

Component-wise equality of two fixed-size vectors, approximate for floating-point values.

template <typename T, int N>
auto const* ptr(numarray_stack<T,N> const& v)

Pointer to the first scalar of the vector.

template <typename T, int N>
int size_in_memory(numarray_stack<T,N> const& v)

Size in bytes of the N components.

Functions returning any vecN

None.

Operators

Show the 17 operators (+, -, *, ==, ...)

operator*

3 overloads
template <typename T, int N>
numarray_stack<T,N> operator*(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)
source

Component-wise (Hadamard) product of two vectors.

template <typename T, int N, typename S>
numarray_stack<T,N> operator*(numarray_stack<T,N> const& a, S b)
source

Vector scaled by a scalar.

template <typename T, int N, typename S>
numarray_stack<T,N> operator*(S a, numarray_stack<T,N> const& b)
source

Vector scaled by a scalar.

operator*=

2 overloads
template <typename T, int N>
numarray_stack<T,N>& operator*=(numarray_stack<T,N>& a, numarray_stack<T,N> const& b)
source

Multiplies by a vector component-wise in place.

template <typename T, int N, typename S>
numarray_stack<T,N>& operator*=(numarray_stack<T,N>& a, S b)
source

Multiplies each component by a scalar in place.

template <typename T, int N>
numarray_stack<T,N> operator+(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)

Component-wise sum of two vectors.

template <typename T, int N>
numarray_stack<T,N>& operator+=(numarray_stack<T,N>& a, numarray_stack<T,N> const& b)

Adds a vector component-wise in place.

operator-

2 overloads
template <typename T, int N>
numarray_stack<T,N> operator-(numarray_stack<T,N> const& a)
source

Component-wise negation of a vector.

template <typename T, int N>
numarray_stack<T,N> operator-(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)
source

Component-wise difference of two vectors.

template <typename T, int N>
numarray_stack<T,N>& operator-=(numarray_stack<T,N>& a, numarray_stack<T,N> const& b)

Subtracts a vector component-wise in place.

operator/

3 overloads
template <typename T, int N>
numarray_stack<T,N> operator/(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)
source

Component-wise quotient of two vectors.

template <typename T, int N, typename S>
numarray_stack<T,N> operator/(numarray_stack<T,N> const& a, S b)
source

Vector with each component divided by a scalar.

template <typename T, int N, typename S>
numarray_stack<T,N> operator/(S a, numarray_stack<T,N> const& b)
source

Vector of a scalar divided by each component.

operator/=

2 overloads
template <typename T, int N>
numarray_stack<T,N>& operator/=(numarray_stack<T,N>& a, numarray_stack<T,N> const& b)
source

Divides by a vector component-wise in place.

template <typename T, int N, typename S>
numarray_stack<T,N>& operator/=(numarray_stack<T,N>& a, S b)
source

Divides each component by a scalar in place.

template <typename T, int N>
std::ostream& operator<<(std::ostream& s, numarray_stack<T,N> const& v)

Writes the components of the vector to the stream, separated by spaces.

Documented on another page

  • operator*Matrix-vector product, giving a vector of size N1.on matN
CGP - Computer Graphics Programming.