vecN
Operations shared by all vectors (vec2, vec3, vec4), written once for any size.
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> data | std::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 overloadstemplate <typename T, int N>
numarray_stack<T,N> add(numarray_stack<T,N> const& a, T const& b)sourcetemplate <typename T, int N>
numarray_stack<T,N> add(T const& a, numarray_stack<T,N> const& b)sourceAdd 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 overloadstemplate <typename T, int N>
numarray_stack<T,N> div(numarray_stack<T,N> const& a, T const& b)sourceDivide each component by a scalar.
template <typename T, int N>
numarray_stack<T,N> div(T const& a, numarray_stack<T,N> const& b)sourceScalar divided by each component.
template <typename T, int N>
numarray_stack<T,N> div(numarray_stack<T,N> const& a, T b)sourceDivide each component by a scalar.
mul
3 overloadstemplate <typename T, int N>
numarray_stack<T,N> mul(numarray_stack<T,N> const& a, T const& b)sourceMultiply each component by a scalar.
template <typename T, int N>
numarray_stack<T,N> mul(T const& a, numarray_stack<T,N> const& b)sourceMultiply 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)sourceComponent-wise (Hadamard) product.
normalize
2 overloadstemplate <typename T, int N>
numarray_stack<T,N> normalize(numarray_stack<T,N> const& v)sourceUnit 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)sourceUnit vector, returning a given default when the norm is near zero.
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 norm(numarray_stack<T,N> const& v)Euclidean length of the vector.
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.
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 overloadstemplate <typename T1, typename T2, int N1, int N2>
bool is_equal(numarray_stack<T1,N1> const& a, numarray_stack<T2,N2> const& b)sourceComponent-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)sourceComponent-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 overloadstemplate <typename T, int N>
numarray_stack<T,N> operator*(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)sourceComponent-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)sourceVector scaled by a scalar.
template <typename T, int N, typename S>
numarray_stack<T,N> operator*(S a, numarray_stack<T,N> const& b)sourceVector scaled by a scalar.
operator*=
2 overloadstemplate <typename T, int N>
numarray_stack<T,N>& operator*=(numarray_stack<T,N>& a, numarray_stack<T,N> const& b)sourceMultiplies 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)sourceMultiplies 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 overloadstemplate <typename T, int N>
numarray_stack<T,N> operator-(numarray_stack<T,N> const& a)sourceComponent-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)sourceComponent-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 overloadstemplate <typename T, int N>
numarray_stack<T,N> operator/(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)sourceComponent-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)sourceVector 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)sourceVector of a scalar divided by each component.
operator/=
2 overloadstemplate <typename T, int N>
numarray_stack<T,N>& operator/=(numarray_stack<T,N>& a, numarray_stack<T,N> const& b)sourceDivides 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)sourceDivides 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.onmatN