# shz::vecN

Source: https://sh4zam.com/api/cpp/vecn/

Common C++ base structure inherited by all vector types.

This struct template serves as the base class for all concrete vector types, providing:

- Common API routines
- Adaptor between C and C++ types
- Convenience overloaded operators and STL iterators.

- **Header:** `#include <sh4zam/shz_vector.hpp>` ([source](https://github.com/gyrovorbis/sh4zam/blob/ba1e30c88d49df0311870b229e1dd860ef26c477/include/sh4zam/shz_vector.hpp#L43))
- **Bases:** `C`

## Static functions

### from

```cpp
static CppType shz::vecN< CRTP, C, R >::from(const auto &raw) noexcept
```

Conversion operator for going from a layout-compatible vector type to a SH4ZAM vector type.

### lerp

```cpp
static CppType shz::vecN< CRTP, C, R >::lerp(const CppType &start, const CppType &end, float t) noexcept
```

Returns the vector that is linearly interpolated between the two given vectors by the `0.0f-1.0f` factor, `t`.

Calls: [`shz_vec_lerp()`](https://sh4zam.com/api/vector/shz_vec_lerp/)

### step

```cpp
static CppType shz::vecN< CRTP, C, R >::step(const CppType &vec, T &&edge) noexcept
```

Compares each component of the vector to the edge. 0 returned in that component if x\[i\] \< edge. Otherwise the component is 1.

Calls: [`shz_vec_step()`](https://sh4zam.com/api/vector/shz_vec_step/)

### smoothstep

```cpp
static CppType shz::vecN< CRTP, C, R >::smoothstep(const CppType &vec, T &&edge0, T &&edge1) noexcept
```

Returns a vector where each component is smoothly interpolated from 0 to 1 between edge0 and edge1.

Calls: [`shz_vec_smoothstep()`](https://sh4zam.com/api/vector/shz_vec_smoothstep/)

### smoothstep_safe

```cpp
static CppType shz::vecN< CRTP, C, R >::smoothstep_safe(const CppType &vec, T &&edge0, T &&edge1) noexcept
```

Returns a vector where each component is smoothly interpolated from 0 to 1 between edge0 and edge1.

Calls: [`shz_vec_smoothstep_safe()`](https://sh4zam.com/api/vector/shz_vec_smoothstep_safe/)

## Members

### vecN

```cpp
shz::vecN< CRTP, C, R >::vecN() noexcept=default
shz::vecN< CRTP, C, R >::vecN(const vecN &other) noexcept=default
shz::vecN< CRTP, C, R >::vecN(const CType &other) noexcept
shz::vecN< CRTP, C, R >::vecN(const volatile CType &other) noexcept
```

Default constructor, does nothing.

### to

```cpp
T shz::vecN< CRTP, C, R >::to() const noexcept
```

Conversion operator for going from a SH4ZAM vector type to another layout-compatible type.

### deref

```cpp
CppType & shz::vecN< CRTP, C, R >::deref(const auto *raw) noexcept
```

Conversion operator for accessing an existing pointer type as though it were a refrence to a SH4ZAM type.

### operator+=

```cpp
CppType & shz::vecN< CRTP, C, R >::operator+=(const CppType &other) noexcept
```

Overloaded operator for adding and accumulating a vector onto another.

### operator-=

```cpp
CppType & shz::vecN< CRTP, C, R >::operator-=(const CppType &other) noexcept
```

Overloaded subtraction assignment operator, subtracts a vector from the left-hand vector.

### operator*=

```cpp
CppType & shz::vecN< CRTP, C, R >::operator*=(const CppType &other) noexcept
CppType & shz::vecN< CRTP, C, R >::operator*=(float other) noexcept
```

Overloaded multiplication assignment operator, multiplies and accumulates a vector onto the left-hand vector.

### operator/=

```cpp
CppType & shz::vecN< CRTP, C, R >::operator/=(const CppType &other) noexcept
CppType & shz::vecN< CRTP, C, R >::operator/=(float other) noexcept
```

Overloaded division assignment operator, divides the left vector by the right, assigning the left to the result.

### swizzle

```cpp
CppType shz::vecN< CRTP, C, R >::swizzle() const noexcept
```

Swizzle oeprator which takes a compile-time list of indices as non-type template arguments for the index each element should use as its new value.

Calls: [`shz_vec_swizzle()`](https://sh4zam.com/api/vector/shz_vec_swizzle/)

### abs

```cpp
CppType shz::vecN< CRTP, C, R >::abs() const noexcept
```

Returns a new vector whose components are the absolute value of the given vector.

Calls: [`shz_vec_abs()`](https://sh4zam.com/api/vector/shz_vec_abs/)

### neg

```cpp
CppType shz::vecN< CRTP, C, R >::neg() const noexcept
```

Returns a new vector whose components are the negative values of the given vector.

Calls: [`shz_vec_neg()`](https://sh4zam.com/api/vector/shz_vec_neg/)

### inv

```cpp
CppType shz::vecN< CRTP, C, R >::inv() const noexcept
```

Returns a new vector whose components are the reciprocal values of the given vector.

Calls: [`shz_vec_inv()`](https://sh4zam.com/api/vector/shz_vec_inv/)

### max

```cpp
float shz::vecN< CRTP, C, R >::max() const noexcept
```

Returns the maximum value of every element within the vector.

Calls: [`shz_vec_max()`](https://sh4zam.com/api/vector/shz_vec_max/)

### min

```cpp
float shz::vecN< CRTP, C, R >::min() const noexcept
```

Returns the minimum value of every element within the vector.

Calls: [`shz_vec_min()`](https://sh4zam.com/api/vector/shz_vec_min/)

### clamp

```cpp
CppType shz::vecN< CRTP, C, R >::clamp(float min, float max) const noexcept
```

Returns a new vector whose values are the clamped components of the given vector.

Calls: [`shz_vec_clamp()`](https://sh4zam.com/api/vector/shz_vec_clamp/)

### floor

```cpp
CppType shz::vecN< CRTP, C, R >::floor() const noexcept
```

Returns a new vector with the component-wise floor of the given vector.

Calls: [`shz_vec_floor()`](https://sh4zam.com/api/vector/shz_vec_floor/)

### ceil

```cpp
CppType shz::vecN< CRTP, C, R >::ceil() const noexcept
```

Returns a new vector with the component-wise ceil of the given vector.

Calls: [`shz_vec_ceil()`](https://sh4zam.com/api/vector/shz_vec_ceil/)

### round

```cpp
CppType shz::vecN< CRTP, C, R >::round() const noexcept
```

Returns a new vector with the component-wise rounding of the given vector.

Calls: [`shz_vec_round()`](https://sh4zam.com/api/vector/shz_vec_round/)

### fract

```cpp
CppType shz::vecN< CRTP, C, R >::fract() const noexcept
```

Returns a new vector with the fractional part of each component.

Calls: [`shz_vec_fract()`](https://sh4zam.com/api/vector/shz_vec_fract/)

### sign

```cpp
CppType shz::vecN< CRTP, C, R >::sign() const noexcept
```

Returns a new vector with the sign of each component (-1, 0, or 1).

Calls: [`shz_vec_sign()`](https://sh4zam.com/api/vector/shz_vec_sign/)

### saturate

```cpp
CppType shz::vecN< CRTP, C, R >::saturate() const noexcept
```

Returns a new vector with each component clamped to \[0, 1\].

Calls: [`shz_vec_saturate()`](https://sh4zam.com/api/vector/shz_vec_saturate/)

### minv

```cpp
CppType shz::vecN< CRTP, C, R >::minv(const CppType &other) const noexcept
```

Returns a new vector with the component-wise minimum of two vectors.

Calls: [`shz_vec_minv()`](https://sh4zam.com/api/vector/shz_vec_minv/)

### maxv

```cpp
CppType shz::vecN< CRTP, C, R >::maxv(const CppType &other) const noexcept
```

Returns a new vector with the component-wise maximum of two vectors.

Calls: [`shz_vec_maxv()`](https://sh4zam.com/api/vector/shz_vec_maxv/)

### inv_sqrtf

```cpp
CppType shz::vecN< CRTP, C, R >::inv_sqrtf() const noexcept
```

Returns a new vector whose components are the inverse square root of the given vector.

Calls: [`shz_vec_inv_sqrtf()`](https://sh4zam.com/api/vector/shz_vec_inv_sqrtf/)

### sqrtf

```cpp
CppType shz::vecN< CRTP, C, R >::sqrtf() const noexcept
```

Returns a new vector whose components are the square root of the given vector.

Calls: [`shz_vec_sqrtf()`](https://sh4zam.com/api/vector/shz_vec_sqrtf/)

### dot

```cpp
float shz::vecN< CRTP, C, R >::dot(const CppType &other) const noexcept
vec2 shz::vecN< CRTP, C, R >::dot(const CppType &v1, const CppType &v2) const noexcept
vec3 shz::vecN< CRTP, C, R >::dot(const CppType &v1, const CppType &v2, const CppType &v3) const noexcept
```

Returns the dot product of the given vector and another.

Calls: [`shz_vec_dot()`](https://sh4zam.com/api/vector/shz_vec_dot/)

### magnitude

```cpp
float shz::vecN< CRTP, C, R >::magnitude() const noexcept
```

Returns the magnitude of the given vector.

Calls: [`shz_vec_magnitude()`](https://sh4zam.com/api/vector/shz_vec_magnitude/)

### magnitude_sqr

```cpp
float shz::vecN< CRTP, C, R >::magnitude_sqr() const noexcept
```

Returns the squared magnitude of the given vector.

Calls: [`shz_vec_magnitude_sqr()`](https://sh4zam.com/api/vector/shz_vec_magnitude_sqr/)

### magnitude_inv

```cpp
float shz::vecN< CRTP, C, R >::magnitude_inv() const noexcept
```

Returns the inverse magnitude of the given vector.

Calls: [`shz_vec_magnitude_inv()`](https://sh4zam.com/api/vector/shz_vec_magnitude_inv/)

### direction

```cpp
CppType shz::vecN< CRTP, C, R >::direction() const noexcept
```

Returns the direction vector resulting from normalizing the given vector.

Calls: [`shz_vec_normalize()`](https://sh4zam.com/api/vector/shz_vec_normalize/)

### direction_safe

```cpp
CppType shz::vecN< CRTP, C, R >::direction_safe() const noexcept
```

Returns the direction vector of a given vector, safely protecting against division-by-zero.

Calls: [`shz_vec_normalize_safe()`](https://sh4zam.com/api/vector/shz_vec_normalize_safe/)

### normalize

```cpp
void shz::vecN< CRTP, C, R >::normalize() noexcept
```

Normalizes the given vector.

Calls: [`shz_vec_normalize()`](https://sh4zam.com/api/vector/shz_vec_normalize/)

### normalize_safe

```cpp
void shz::vecN< CRTP, C, R >::normalize_safe() noexcept
```

Normalizes the given vector, safely protecting against division-by-zero.

Calls: [`shz_vec_normalize_safe()`](https://sh4zam.com/api/vector/shz_vec_normalize_safe/)

### normalized

```cpp
CppType shz::vecN< CRTP, C, R >::normalized() const noexcept
```

Return the normalized vector.

Calls: [`shz_vec_normalize()`](https://sh4zam.com/api/vector/shz_vec_normalize/)

### normalized_safe

```cpp
CppType shz::vecN< CRTP, C, R >::normalized_safe() const noexcept
```

Return the normalized vector, safely protecting against division-by-zero.

Calls: [`shz_vec_normalize_safe()`](https://sh4zam.com/api/vector/shz_vec_normalize_safe/)

### distance

```cpp
float shz::vecN< CRTP, C, R >::distance(const CppType &other) const noexcept
```

Returns the magnitude of the difference between two vectors as their distance.

Calls: [`shz_vec_distance()`](https://sh4zam.com/api/vector/shz_vec_distance/)

### distance_sqr

```cpp
float shz::vecN< CRTP, C, R >::distance_sqr(const CppType &other) const noexcept
```

Returns the value of the distance between two vectors squared (faster than actual distance).

Calls: [`shz_vec_distance_sqr()`](https://sh4zam.com/api/vector/shz_vec_distance_sqr/)

### move

```cpp
CppType shz::vecN< CRTP, C, R >::move(const CppType &target, float maxdist) const noexcept
```

Moves the given vector towards the target by the given `maxdist`.

Calls: [`shz_vec_move()`](https://sh4zam.com/api/vector/shz_vec_move/)

### reflect

```cpp
CppType shz::vecN< CRTP, C, R >::reflect(const CppType &normal) const noexcept
```

Returns the vector created from reflecting the given vector over the normal of a surface.

Calls: [`shz_vec_reflect()`](https://sh4zam.com/api/vector/shz_vec_reflect/)

### refract

```cpp
CppType shz::vecN< CRTP, C, R >::refract(const CppType &normal, float eta) const noexcept
```

Returns the vector create from refracting the given incidence vector over the normal of a surface, using the given refraction ratio index.

Calls: [`shz_vec_refract()`](https://sh4zam.com/api/vector/shz_vec_refract/)

### project

```cpp
CppType shz::vecN< CRTP, C, R >::project(const CppType &onto) const noexcept
```

Returns the vector created from projecting the given vector onto another.

Calls: [`shz_vec_project()`](https://sh4zam.com/api/vector/shz_vec_project/)

### project_safe

```cpp
CppType shz::vecN< CRTP, C, R >::project_safe(const CppType &onto) const noexcept
```

Returns the vector created from projecting the given vector onto another, safely protecting against division-by-zero.

Calls: [`shz_vec_project_safe()`](https://sh4zam.com/api/vector/shz_vec_project_safe/)

### angle_between

```cpp
float shz::vecN< CRTP, C, R >::angle_between(const CppType &other) const noexcept
```

Returns the angle between the given vector and another, in radians.

Calls: [`shz_vec_angle_between()`](https://sh4zam.com/api/vector/shz_vec_angle_between/)

### angles

```cpp
auto shz::vecN< CRTP, C, R >::angles() const noexcept
```

Returns the angle(s) created between the given vector axis and the +X axis, in radians.

Calls: [`shz_vec_angles()`](https://sh4zam.com/api/vector/shz_vec_angles/)

### operator==

```cpp
bool operator==(const CppType &lhs, const CppType &rhs) noexcept
```

Overloaded equality operator, for comparing vectors.

### operator-

```cpp
CppType operator-(const CppType &vec) noexcept
```

Overloaded unary negation operator, returns the negated vector.
