vec2 ==== Header file: ``include/vec2.h`` **vec2** is a vector with **2 scalars**, **x** and **y**. :math:`vec2 = \begin{bmatrix} x \\ y \end{bmatrix}` Class variables --------------- .. table:: :width: 100% :widths: 15 15 70 :class: code-table +-------+-------+-----------------------------------+ | Type | Name | Description | +=======+=======+===================================+ | float | x | The first element of the *vec2*. | +-------+-------+-----------------------------------+ | float | y | The second element of the *vec2*. | +-------+-------+-----------------------------------+ Class functions --------------- Constructors ~~~~~~~~~~~~ .. table:: :width: 100% :widths: 30 70 :class: code-table +----------------------------------------------------------------------------+--------------------------------------------+ | Name | Description | +============================================================================+============================================+ | :doc:`vec2() ` | Construct a (0.0, 0.0) vector. | +----------------------------------------------------------------------------+--------------------------------------------+ | :doc:`vec2(float _value) ` | Construct a (*_value*, *_value*) vector. | +----------------------------------------------------------------------------+--------------------------------------------+ | :doc:`vec2(float _x, float _y) ` | Construct a (*_x*, *_y*) vector. | +----------------------------------------------------------------------------+--------------------------------------------+ | :doc:`vec2(const float* _ptr) ` | Construct a vector from a pointer. | +----------------------------------------------------------------------------+--------------------------------------------+ | :doc:`vec2(const nml::vec3& _xyz) ` | Construct a (*_xyz.x*, *_xyz.y*) vector. | +----------------------------------------------------------------------------+--------------------------------------------+ | :doc:`vec2(const nml::vec4& _xyzw) ` | Construct a (*_xyzw.x*, *_xyzw.y*) vector. | +----------------------------------------------------------------------------+--------------------------------------------+ Operators ~~~~~~~~~ .. table:: :width: 100% :widths: 50 50 :class: code-table +---------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+ | Name | Description | +===================================================================================================+========================================================================================================+ | :doc:`nml::vec2& operator+=(const nml::vec2& other) ` | Add a *vec2* to the current *vec2*. | +---------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+ | :doc:`nml::vec2& operator-=(const nml::vec2& other) ` | Substract a *vec2* from the current *vec2*. | +---------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+ | :doc:`nml::vec2& operator*=(const float other) ` | Multiply the current *vec2* by a scalar. | +---------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+ | :doc:`nml::vec2& operator/=(const float other) ` | Divide the current *vec2* by a scalar. | +---------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+ | :doc:`nml::vec2 operator-() ` | Return the negative of the current *vec2*. | +---------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+ | :doc:`float& operator[](size_t index) ` | Return a reference to *x* if index is 0 or a reference to *y* if index is 1, else, throw an exception. | +---------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+ | :doc:`const float operator[](size_t index) const ` | Return the value of *x* if index is 0 or the value of *y* if index is 1, else, throw an exception. | +---------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+ Functions ~~~~~~~~~ .. table:: :width: 100% :widths: 30 70 :class: code-table +-------------------------------------------------+--------------------------------------------+ | Name | Description | +=================================================+============================================+ | :doc:`float length() ` | Return the length of the vector. | +-------------------------------------------------+--------------------------------------------+ | :doc:`float* data() ` | Return a pointer to the vector's elements. | +-------------------------------------------------+--------------------------------------------+ Namespace functions ------------------- Operators ~~~~~~~~~ .. table:: :width: 100% :widths: 40 60 :class: code-table +-------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+ | Name | Description | +=========================================================================================================================+=====================================================================+ | :doc:`nml::vec2 operator+(nml::vec2 lhs, const nml::vec2& rhs) ` | Return a *vec2* that is the sum between two *vec2*. | +-------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+ | :doc:`nml::vec2 operator-(nml::vec2 lhs, const nml::vec2& rhs) ` | Return a *vec2* that is the difference between two *vec2*. | +-------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+ | :doc:`nml::vec2 operator*(nml::vec2 lhs, const float rhs) ` | Return a *vec2* that is the product between a *vec2* and a scalar. | +-------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+ | :doc:`nml::vec2 operator*(float lhs, const nml::vec2& rhs) ` | Return a *vec2* that is the product between a scalar and a *vec2*. | +-------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+ | :doc:`nml::vec2 operator/(nml::vec2 lhs, const float rhs) ` | Return a *vec2* that is the quotient between a vec2 and a scalar. | +-------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+ | :doc:`bool operator==(const nml::vec2& lhs, const nml::vec2& rhs) ` | Return true if the two *vec2* are identical, else, return false. | +-------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+ | :doc:`bool operator!=(const nml::vec2& lhs, const nml::vec2& rhs) ` | Return true if the two *vec2* are different, else, return false. | +-------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------+ Functions ~~~~~~~~~ .. table:: :width: 100% :widths: 40 60 :class: code-table +-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+ | Name | Description | +===============================================================================================================================+========================================================================================================================================================+ | :doc:`nml::vec2 nml::normalize(const nml::vec2& vec) ` | Return a *vec2* with the same direction as *vec* but with length 1. | +-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+ | :doc:`float nml::dot(const nml::vec2& a, const nml::vec2& b) ` | Return the dot product between two *vec2*. | +-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+ | :doc:`nml::vec2 nml::reflect(const nml::vec2& i, const nml::vec2& n) ` | Return the reflected direction between the incident vector *i* and the normal *n*. *n* should be normalized. | +-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+ | :doc:`nml::vec2 nml::refract(const nml::vec2& i, const nml::vec2& n, float ior) ` | Return the refracted direction between the incident vector *i*, the normal *n* and the ratio of indices of refraction *ior*. *n* should be normalized. | +-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+ | :doc:`std::string nml::to_string(const nml::vec2& vec) ` | Return a *vec2* as a string under the format "[*x*, *y*]". | +-------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+