URL: https://graphicscomputing.fr/cgp/reference/vecN/
Description: Operations shared by all vectors (vec2, vec3, vec4), written once for any size.

# vecN

C++ type: `numarray_stack<T,N>`.
Shared by: vec2, vec3, vec4.
Operations shared by all vectors (vec2, vec3, vec4), written once for any size.

Fields:

- `std::array<T,N> data` - std::array holding the N components, stored contiguously.

Functions taking it:

- `T const& get(numarray_stack<T,N> const& data)` - Component idx with the index checked at compile time (static_assert).
- `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.
- `std::string type_str(numarray_stack<T,N> const&)` - Type name as a string, e.g. "numarray_stack<float,5>".
- `int size_in_memory(numarray_stack<T,N> const& v)` - Size in bytes of the N components.
- `auto const* ptr(numarray_stack<T,N> const& v)` - Pointer to the first scalar of the vector.
- `bool is_equal(numarray_stack<T1,N1> const& a, numarray_stack<T2,N2> const& b)` - Component-wise equality of two fixed-size vectors, approximate for floating-point values; false if sizes differ.
- `bool is_equal(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)` - Component-wise equality of two fixed-size vectors, approximate for floating-point values.
- `numarray_stack<T,N> normalize(numarray_stack<T,N> const& v)` - Unit vector in the same direction (asserts on near-zero norm).
- `numarray_stack<T,N> normalize(numarray_stack<T,N> const& v, numarray_stack<T,N> const& default_zero_norm)` - Unit vector, returning a given default when the norm is near zero.
- `T norm(numarray_stack<T,N> const& v)` - Euclidean length of the vector.
- `T dot(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)` - Dot (scalar) product of two vectors.
- `T max(numarray_stack<T,N> const& v)` - Largest component.
- `T min(numarray_stack<T,N> const& v)` - Smallest component.
- `T average(numarray_stack<T,N> const& a)` - Mean of the components.
- `T sum(numarray_stack<T,N> const& v)` - Sum of the components.
- `numarray_stack<T,N> abs(numarray_stack<T,N> const& a)` - Component-wise absolute value.
- `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.
- `numarray_stack<T,N> sub(numarray_stack<T,N> const& a, T const& b)` - Subtract a scalar from each component.
- `numarray_stack<T,N> add(numarray_stack<T,N> const& a, T const& b)` - Add a scalar to each component.
- `numarray_stack<T,N> mul(numarray_stack<T,N> const& a, T const& b)` - Multiply each component by a scalar.
- `numarray_stack<T,N> div(numarray_stack<T,N> const& a, T const& b)` - Divide each component by a scalar.
- `numarray_stack<T,N> sub(T const& a, numarray_stack<T,N> const& b)` - Scalar minus each component.
- `numarray_stack<T,N> add(T const& a, numarray_stack<T,N> const& b)` - Add a scalar to each component.
- `numarray_stack<T,N> mul(T const& a, numarray_stack<T,N> const& b)` - Multiply each component by a scalar.
- `numarray_stack<T,N> div(T const& a, numarray_stack<T,N> const& b)` - Scalar divided by each component.
- `numarray_stack<T,N> mul(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)` - Component-wise (Hadamard) product.
- `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.
- `numarray_stack<T,N> div(numarray_stack<T,N> const& a, T b)` - Divide each component by a scalar.
- `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.

Operators:

- `std::ostream& operator<<(std::ostream& s, numarray_stack<T,N> const& v)` - Writes the components of the vector to the stream, separated by spaces.
- `numarray_stack<T,N> operator-(numarray_stack<T,N> const& a)` - Component-wise negation of a vector.
- `numarray_stack<T,N>& operator+=(numarray_stack<T,N>& a, numarray_stack<T,N> const& b)` - Adds a vector component-wise in place.
- `numarray_stack<T,N> operator+(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)` - Component-wise sum of two vectors.
- `numarray_stack<T,N>& operator-=(numarray_stack<T,N>& a, numarray_stack<T,N> const& b)` - Subtracts a vector component-wise in place.
- `numarray_stack<T,N> operator-(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)` - Component-wise difference of two vectors.
- `numarray_stack<T,N>& operator*=(numarray_stack<T,N>& a, numarray_stack<T,N> const& b)` - Multiplies by a vector component-wise in place.
- `numarray_stack<T,N>& operator*=(numarray_stack<T,N>& a, S b)` - Multiplies each component by a scalar in place.
- `numarray_stack<T,N> operator*(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)` - Component-wise (Hadamard) product of two vectors.
- `numarray_stack<T,N> operator*(numarray_stack<T,N> const& a, S b)` - Vector scaled by a scalar.
- `numarray_stack<T,N> operator*(S a, numarray_stack<T,N> const& b)` - Vector scaled by a scalar.
- `numarray_stack<T,N>& operator/=(numarray_stack<T,N>& a, numarray_stack<T,N> const& b)` - Divides by a vector component-wise in place.
- `numarray_stack<T,N>& operator/=(numarray_stack<T,N>& a, S b)` - Divides each component by a scalar in place.
- `numarray_stack<T,N> operator/(numarray_stack<T,N> const& a, numarray_stack<T,N> const& b)` - Component-wise quotient of two vectors.
- `numarray_stack<T,N> operator/(numarray_stack<T,N> const& a, S b)` - Vector with each component divided by a scalar.
- `numarray_stack<T,N> operator/(S a, numarray_stack<T,N> const& b)` - Vector of a scalar divided by each component.
- `numarray_stack<T,N1> operator*(matrix_stack<T,N1,N2> const& a, numarray_stack<T,N2> const& b)` - Matrix-vector product, giving a vector of size N1.
