SH4ZAM! 0.1.0
Fast math library for the Sega Dreamcast's SH4 CPU
Loading...
Searching...
No Matches
shz::vec2 Struct Reference

#include <shz_vector.hpp>

Inheritance diagram for shz::vec2:
Collaboration diagram for shz::vec2:

Public Member Functions

 vec2 ()=default
 
 vec2 (float v) noexcept
 
 vec2 (float x, float y) noexcept
 
 vec2 (sincos pair) noexcept
 
float cross (vec2 other) const noexcept
 
vec2 rotate (float radians) const noexcept
 
 vecN ()=default
 
 vecN (CType other) noexcept
 
float dot (CppType other) const noexcept
 
vec2 dot (CppType v1, CppType v2) const noexcept
 
vec3 dot (CppType v1, CppType v2, CppType v3) const noexcept
 
- Public Member Functions inherited from shz::vecN< vec2, shz_vec2_t, 2 >
 vecN ()=default
 
 vecN (CType other) noexcept
 
to () const noexcept
 
CppTypederef (const auto *raw) noexcept
 
CppTypeoperator+= (CppType other) noexcept
 
CppTypeoperator-= (CppType other) noexcept
 
CppTypeoperator*= (CppType other) noexcept
 
CppTypeoperator*= (float other) noexcept
 
CppTypeoperator/= (CppType other) noexcept
 
CppTypeoperator/= (float other) noexcept
 
CppType swizzle () const noexcept
 
CppType abs () const noexcept
 
CppType neg () const noexcept
 
CppType inv () const noexcept
 
float max () const noexcept
 
float min () const noexcept
 
CppType clamp (float min, float max) const noexcept
 
CppType floor () const noexcept
 
CppType ceil () const noexcept
 
CppType round () const noexcept
 
CppType fract () const noexcept
 
CppType sign () const noexcept
 
CppType saturate () const noexcept
 
CppType minv (CppType other) const noexcept
 
CppType maxv (CppType other) const noexcept
 
float dot (CppType other) const noexcept
 
vec2 dot (CppType v1, CppType v2) const noexcept
 
vec3 dot (CppType v1, CppType v2, CppType v3) const noexcept
 
float magnitude () const noexcept
 
float magnitude_sqr () const noexcept
 
float magnitude_inv () const noexcept
 
CppType direction () const noexcept
 
void normalize () noexcept
 
CppType direction_safe () const noexcept
 
void normalize_safe () noexcept
 
float distance (const CppType &other) const noexcept
 
float distance_sqr (const CppType &other) const noexcept
 
CppType move (CppType target, float maxdist) const noexcept
 
CppType reflect (CppType normal) const noexcept
 
CppType refract (CppType normal, float eta) const noexcept
 
CppType project (CppType onto) const noexcept
 
CppType project_safe (CppType onto) const noexcept
 
float angle_between (CppType other) const noexcept
 
auto angles () const noexcept
 

Static Public Member Functions

static vec2 from_angle (float rads) noexcept
 
static vec2 from_angle_deg (float deg) noexcept
 
- Static Public Member Functions inherited from shz::vecN< vec2, shz_vec2_t, 2 >
static CppType from (const auto &raw) noexcept
 
static CppType lerp (CppType start, CppType end, float t) noexcept
 
static CppType step (CppType vec, T edge) noexcept
 
static CppType smoothstep (CppType vec, T edge0, T edge1) noexcept
 
static CppType smoothstep_safe (CppType vec, T edge0, T edge1) noexcept
 

Additional Inherited Members

- Public Types inherited from shz::vecN< vec2, shz_vec2_t, 2 >
using CppType
 
using CType
 
- Data Fields inherited from shz_vec2_t
union { 
 
   float   e [2] 
 
   struct { 
 
      float   x 
 
      float   y 
 
   }  
 
};  
 
- Static Public Attributes inherited from shz::vecN< vec2, shz_vec2_t, 2 >
static constexpr size_t Rows
 
static constexpr size_t Cols
 

Detailed Description

2D Vector type

C++ structure for representing a 2-dimensional vector.

See also
shz::vecN, shz_vec2_t, shz::vec3, shz::vec4

Definition at line 391 of file shz_vector.hpp.

Constructor & Destructor Documentation

◆ vec2() [1/4]

shz::vec2::vec2 ( )
default

Default constructor: does nothing.

◆ vec2() [2/4]

shz::vec2::vec2 ( float v)
inlinenoexcept

Single-value constructor: sets both components equal to v.

Definition at line 402 of file shz_vector.hpp.

402 :
403 vecN(shz_vec2_fill(v)) {}
shz_vec2_t shz_vec2_fill(float v) SHZ_NOEXCEPT
Returns a 2D vector with the value of each component equal to v.
vecN()=default
Default constructor, does nothing.

◆ vec2() [3/4]

shz::vec2::vec2 ( float x,
float y )
inlinenoexcept

Constructs a vec2 with the given values as components.

Definition at line 406 of file shz_vector.hpp.

406 :
407 vecN(shz_vec2_init(x, y)) {}
shz_vec2_t shz_vec2_init(float x, float y) SHZ_NOEXCEPT
Returns a 2D vector with the given x, and y coordinates.
float x
X coordinate.
Definition shz_vector.h:42
float y
Y coordinate.
Definition shz_vector.h:43

◆ vec2() [4/4]

shz::vec2::vec2 ( sincos pair)
inlinenoexcept

Constructs a vec2 from the given angle of rotation from the +X axis.

Definition at line 410 of file shz_vector.hpp.

410 :
411 vecN(shz_vec2_from_sincos(pair)) {}
shz_vec2_t shz_vec2_from_sincos(shz_sincos_t sincos) SHZ_NOEXCEPT
Returns the 2D unit vector representing a rotation from the positive X axis.

Member Function Documentation

◆ from_angle()

static vec2 shz::vec2::from_angle ( float rads)
inlinestaticnoexcept

Constructs a vec2 from the given angle of rotation from the +X axis, in radians.

Definition at line 414 of file shz_vector.hpp.

414 {
415 return shz_vec2_from_angle(rads);
416 }
shz_vec2_t shz_vec2_from_angle(float radians) SHZ_NOEXCEPT
Returns the 2D unit vector representing a rotation from the positive X axis in radians.

◆ from_angle_deg()

static vec2 shz::vec2::from_angle_deg ( float deg)
inlinestaticnoexcept

Constructs a vec2 from the given angle of rotation from the +X axis, in degrees.

Definition at line 419 of file shz_vector.hpp.

419 {
420 return shz_vec2_from_angle_deg(deg);
421 }
shz_vec2_t shz_vec2_from_angle_deg(float degrees) SHZ_NOEXCEPT
Returns the 2D unit vector representing a rotation from the positive X axis in degrees.

◆ cross()

float shz::vec2::cross ( vec2 other) const
inlinenoexcept

C++ wrapper for shz_vec2_cross().

Definition at line 424 of file shz_vector.hpp.

424 {
425 return shz_vec2_cross(*this, other);
426 }
float shz_vec2_cross(shz_vec2_t vec1, shz_vec2_t vec2) SHZ_NOEXCEPT
Returns the cross product, as a scalar, between two 2D vectors.

◆ rotate()

vec2 shz::vec2::rotate ( float radians) const
inlinenoexcept

C++ wrapper for shz_vec2_rotate().

Definition at line 429 of file shz_vector.hpp.

429 {
430 return shz_vec2_rotate(*this, radians);
431 }
shz_vec2_t shz_vec2_rotate(shz_vec2_t vec, float radians) SHZ_NOEXCEPT
Rotates the given 2D vector about the Z axis by the given angle in radians.

◆ vecN() [1/2]

shz::vecN< CRTP, C, R >::vecN ( )
default

Default constructor, does nothing.

◆ vecN() [2/2]

shz::vecN< CRTP, C, R >::vecN ( CType other)
inlinenoexcept

Converting constructor from existing C instance.

Definition at line 54 of file shz_vector.hpp.

54 :
55 CType(other) {}

◆ dot() [1/3]

float shz::vecN< CRTP, C, R >::dot ( CppType other) const
inlinenoexcept

Returns the dot product of the given vector and another.

Definition at line 246 of file shz_vector.hpp.

246 {
247 return shz_vec_dot(*static_cast<const CppType*>(this), other);
248 }
#define shz_vec_dot(vec1, vec2)
C type-generic vector dot product.
Definition shz_vector.h:778

◆ dot() [2/3]

vec2 shz::vecN< CRTP, C, R >::dot ( CppType v1,
CppType v2 ) const
noexcept

Returns the dot product of the given vector against two others.

Definition at line 251 of file shz_vector.hpp.

610 {
611 return shz_vec_dot2(*static_cast<const CRTP*>(this), v1, v2);
612}
#define shz_vec_dot2(l, r1, r2)
C type-generic vector chained double dot product.
Definition shz_vector.h:785

◆ dot() [3/3]

vec3 shz::vecN< CRTP, C, R >::dot ( CppType v1,
CppType v2,
CppType v3 ) const
noexcept

Returns the dot product of the given vector against three others.

Definition at line 254 of file shz_vector.hpp.

615 {
616 return shz_vec_dot3(*static_cast<const CRTP*>(this), v1, v2, v3);
617}
#define shz_vec_dot3(l, r1, r2, r3)
C type-generic vector chained triple dot product.
Definition shz_vector.h:792

The documentation for this struct was generated from the following file: