- Touched up documentation for Math library

- finished matrix implementation
 - added custom assert implementation
This commit is contained in:
2025-06-22 16:28:49 -04:00
parent 4d8466851c
commit 31e3c26b66
14 changed files with 423 additions and 206 deletions

View File

@@ -21,8 +21,6 @@
using assert_handler = void (*)(const char *, const char *, int , const char *);
extern void set_assert_handler(assert_handler handler);
extern void __assert_impl(const char* expression, const char* file, int line, const char* function);
#define assert(expression) if(not(expression)) { __assert_impl(#expression, __FILE__, __LINE__, __PRETTY_FUNCTION__); }

View File

@@ -131,7 +131,6 @@ namespace fennec
// fennec::type_transform ==============================================================================================
///
/// \struct fennec::type_transform
/// \brief Base Class for Type Transformations
///
/// \details resembles a transformation from one type to T, the result is stored in the member type_transform::type
@@ -139,7 +138,6 @@ namespace fennec
template<typename T> struct type_transform {
///
/// \typedef type_transform::type
/// \brief the type to transform into
using type = T;
};

View File

@@ -32,7 +32,10 @@
#ifndef FENNEC_MATH_EXPONENTIAL_H
#define FENNEC_MATH_EXPONENTIAL_H
#include <cmath>
#pragma push_macro("__cplusplus")
#undef __cplusplus
#include <math.h>
#pragma pop_macro("__cplusplus")
///
///
@@ -106,7 +109,7 @@ namespace fennec
/// \param y the exponent
template<typename genType>
constexpr genType pow(genType x, genType y)
{ return std::pow(x, y); }
{ return ::pow(x, y); }
template<typename genType, size_t...i>
constexpr vector<genType, i...> pow(const vector<genType, i...> & x, const vector<genType, i...> & y)
@@ -123,7 +126,7 @@ constexpr vector<genType, i...> pow(const vector<genType, i...> & x, const vecto
/// \param x the exponent
template<typename genType>
constexpr genType exp(genType x)
{ return std::exp(x); }
{ return ::exp(x); }
template<typename genType, size_t...i> constexpr vector<genType, i...> exp(const vector<genType, i...>& x)
{ return vector<genType, i...>(fennec::exp(x[i]) ...); }
@@ -138,7 +141,7 @@ template<typename genType, size_t...i> constexpr vector<genType, i...> exp(const
///
/// \param x the exponent
template<typename genType> constexpr genType exp2(genType x)
{ return std::exp2(x); }
{ return ::exp2(x); }
template<typename genType, size_t...i> constexpr vector<genType, i...> exp2(const vector<genType, i...>& x)
{ return vector<genType, i...>(fennec::exp2(x[i]) ...); }
@@ -154,7 +157,7 @@ template<typename genType, size_t...i> constexpr vector<genType, i...> exp2(cons
///
/// \param x the input value
template<typename genType> constexpr genType log(genType x)
{ return std::log(x); }
{ return ::log(x); }
template<typename genType, size_t...i> constexpr genType log(const vector<genType, i...>& x)
{ return vector<genType, i...>(log(x[i]) ...); }
@@ -171,7 +174,7 @@ template<typename genType, size_t...i> constexpr genType log(const vector<genTyp
///
/// \param x the input value
template<typename genType> constexpr genType log2(genType x)
{ return std::log2(x); }
{ return ::log2(x); }
template<typename genType, size_t...i> constexpr genType log2(const vector<genType, i...>& x)
{ return vector<genType, i...>(log2(x[i]) ...); }
@@ -187,7 +190,7 @@ template<typename genType, size_t...i> constexpr genType log2(const vector<genTy
///
/// \param x the input value
template<typename genType> constexpr genType sqrt(genType x)
{ return std::sqrt(x); }
{ return ::sqrt(x); }
template<typename genType, size_t...i> constexpr genType sqrt(const vector<genType, i...>& x)
{ return vector<genType, i...>(fennec::sqrt(x[i]) ...); }

View File

@@ -46,8 +46,8 @@
#include <fennec/math/detail/__fwd.h>
#include <fennec/containers/array.h>
#include <fennec/math/geometric.h>
#include <fennec/math/vector.h>
#include <fennec/math/vector_traits.h>
namespace fennec
@@ -80,38 +80,43 @@ constexpr vec<scalar, sizeof...(cols)> row(const matrix<scalar, rows, cols...>&
{ return vec<scalar, sizeof...(cols)>(m[cols][i]...); }
template<typename ScalarT> using tmat2x2 = mat<ScalarT, 2, 2>; ///< helper for creating 2x2 matrices of the specified type.
template<typename ScalarT> using tmat2x3 = mat<ScalarT, 2, 3>; ///< helper for creating 2x3 matrices of the specified type.
template<typename ScalarT> using tmat2x4 = mat<ScalarT, 2, 4>; ///< helper for creating 2x4 matrices of the specified type.
template<typename ScalarT> using tmat3x2 = mat<ScalarT, 3, 2>; ///< helper for creating 3x2 matrices of the specified type.
template<typename ScalarT> using tmat3x3 = mat<ScalarT, 3, 3>; ///< helper for creating 3x3 matrices of the specified type.
template<typename ScalarT> using tmat3x4 = mat<ScalarT, 3, 4>; ///< helper for creating 3x4 matrices of the specified type.
template<typename ScalarT> using tmat4x2 = mat<ScalarT, 4, 2>; ///< helper for creating 4x2 matrices of the specified type.
template<typename ScalarT> using tmat4x3 = mat<ScalarT, 4, 3>; ///< helper for creating 4x3 matrices of the specified type.
template<typename ScalarT> using tmat4x4 = mat<ScalarT, 4, 4>; ///< helper for creating 4x4 matrices of the specified type.
template<size_t rows, size_t cols> using tmat = mat<float_t, rows, cols>;
using mat2 = tmat2x2<float_t>; ///< Specification for glsl float matrices
using mat3 = tmat3x3<float_t>; ///< Specification for glsl float matrices
using mat4 = tmat3x3<float_t>; ///< Specification for glsl float matrices
using mat2 = tmat<2, 2>;
using mat3 = tmat<3, 3>;
using mat4 = tmat<4, 4>;
using mat2x2 = tmat2x2<float_t>; ///< Specification for sized glsl float matrices
using mat2x3 = tmat2x3<float_t>; ///< Specification for sized glsl float matrices
using mat2x4 = tmat2x4<float_t>; ///< Specification for sized glsl float matrices
using mat3x2 = tmat3x2<float_t>; ///< Specification for sized glsl float matrices
using mat3x3 = tmat3x3<float_t>; ///< Specification for sized glsl float matrices
using mat3x4 = tmat3x4<float_t>; ///< Specification for sized glsl float matrices
using mat4x2 = tmat4x2<float_t>; ///< Specification for sized glsl float matrices
using mat4x3 = tmat4x3<float_t>; ///< Specification for sized glsl float matrices
using mat4x4 = tmat4x4<float_t>; ///< Specification for sized glsl float matrices
using mat2x2 = tmat<2, 2>;
using mat2x3 = tmat<2, 3>;
using mat2x4 = tmat<2, 4>;
using mat3x2 = tmat<3, 2>;
using mat3x3 = tmat<3, 3>;
using mat3x4 = tmat<3, 4>;
using mat4x2 = tmat<4, 2>;
using mat4x3 = tmat<4, 3>;
using mat4x4 = tmat<4, 4>;
using dmat2 = tmat2x2<double_t>; ///< Specification for glsl double matrices
using dmat3 = tmat3x3<double_t>; ///< Specification for glsl double matrices
using dmat4 = tmat3x3<double_t>; ///< Specification for glsl double matrices
template<size_t rows, size_t cols> using tdmat = mat<float_t, rows, cols>;
using dmat2 = tdmat<2, 2>;
using dmat3 = tdmat<3, 3>;
using dmat4 = tdmat<4, 4>;
using dmat2x2 = tdmat<2, 2>;
using dmat2x3 = tdmat<2, 3>;
using dmat2x4 = tdmat<2, 4>;
using dmat3x2 = tdmat<3, 2>;
using dmat3x3 = tdmat<3, 3>;
using dmat3x4 = tdmat<3, 4>;
using dmat4x2 = tdmat<4, 2>;
using dmat4x3 = tdmat<4, 3>;
using dmat4x4 = tdmat<4, 4>;
using dmat2x2 = tmat2x2<double_t>; ///< Specification for size glsl double matrices
using dmat2x3 = tmat2x3<double_t>; ///< Specification for size glsl double matrices
using dmat2x4 = tmat2x4<double_t>; ///< Specification for size glsl double matrices
using dmat3x2 = tmat3x2<double_t>; ///< Specification for size glsl double matrices
using dmat3x3 = tmat3x3<double_t>; ///< Specification for size glsl double matrices
using dmat3x4 = tmat3x4<double_t>; ///< Specification for size glsl double matrices
using dmat4x2 = tmat4x2<double_t>; ///< Specification for size glsl double matrices
using dmat4x3 = tmat4x3<double_t>; ///< Specification for size glsl double matrices
using dmat4x4 = tmat4x4<double_t>; ///< Specification for size glsl double matrices
///
@@ -197,7 +202,7 @@ struct matrix
///
/// \details
/// \param mat matrix to move
constexpr matrix(matrix_t&& mat)
constexpr matrix(matrix_t&& mat) noexcept
: data{ mat.data } {}
@@ -215,7 +220,6 @@ struct matrix
/// </table><br><br>
///
/// \param s scalar value
///
constexpr matrix(scalar_t s)
{ (((ColIndicesV < rows) ? data[ColIndicesV][ColIndicesV] = s : 0), ...); }
@@ -278,7 +282,6 @@ struct matrix
{ assert(i < rows); return data[i]; }
///
/// \fn matrix::operator()(size_t, size_t)
/// \copydetails matrix::operator()(size_t, size_t) const
constexpr scalar_t& operator()(size_t i, size_t j)
{ assert(i < rows && j < columns); return data[i][j]; }
@@ -298,13 +301,245 @@ struct matrix
/// \name Scalar Operators
/// @{
///
/// \brief \ref fennec::matrix "matrix" - \ref scalar addition operator.
/// \param lhs the matrix
/// \param rhs the scalar
/// \returns a copy of the matrix with each component having been added by the scalar
constexpr friend matrix_t operator+(const matrix_t& lhs, scalar_t rhs)
{
matrix_t retval = lhs;
((retval[ColIndicesV] += rhs), ...);
return retval;
}
///
/// \brief \ref scalar - \ref fennec::matrix "matrix" addition operator.
/// \param lhs the scalar
/// \param rhs the matrix
/// \returns a copy of the matrix with each component having been added by the scalar
constexpr friend matrix_t operator+(scalar_t lhs, const matrix_t& rhs)
{
matrix_t retval = rhs;
((retval[ColIndicesV] += lhs), ...);
return retval;
}
///
/// \brief \ref fennec::matrix "matrix" - \ref scalar subtraction operator.
/// \param lhs the matrix
/// \param rhs the scalar
/// \returns a copy of the matrix with each component having been subtracted by the scalar
constexpr friend matrix_t operator-(const matrix_t& lhs, scalar_t rhs)
{
matrix_t retval = lhs;
((retval[ColIndicesV] -= rhs), ...);
return retval;
}
///
/// \brief \ref scalar - \ref fennec::matrix "matrix" subtraction operator.
/// \param lhs the scalar
/// \param rhs the matrix
/// \returns a copy of the matrix with each component having been subtracted by the scalar
constexpr friend matrix_t operator-(scalar_t lhs, const matrix_t& rhs)
{
matrix_t retval = rhs;
((retval[ColIndicesV] -= lhs), ...);
return retval;
}
///
/// \brief \ref fennec::matrix "matrix" - \ref scalar multiplication operator.
/// \param lhs the matrix
/// \param rhs the scalar
/// \returns a copy of the matrix with each component having been multiplied by the scalar
constexpr friend matrix_t operator*(const matrix_t& lhs, scalar_t rhs)
{
matrix_t retval = lhs;
((retval[ColIndicesV] *= rhs), ...);
return retval;
}
///
/// \brief \ref scalar - \ref fennec::matrix "matrix" multiplication operator.
/// \param lhs the scalar
/// \param rhs the matrix
/// \returns a copy of the matrix with each component having been multiplied by the scalar
constexpr friend matrix_t operator*(scalar_t lhs, const matrix_t& rhs)
{
matrix_t retval = rhs;
((retval[ColIndicesV] *= lhs), ...);
return retval;
}
///
/// \brief \ref fennec::matrix "matrix" - \ref scalar division operator.
/// \param lhs the matrix
/// \param rhs the scalar
/// \returns a copy of the matrix with each component having been divided by the scalar
constexpr friend matrix_t operator/(const matrix_t& lhs, scalar_t rhs)
{
matrix_t retval = lhs;
((retval[ColIndicesV] /= rhs), ...);
return retval;
}
///
/// \brief \ref scalar - \ref fennec::matrix "matrix" division operator.
/// \param lhs the scalar
/// \param rhs the matrix
/// \returns a copy of the matrix with each component having been divided by the scalar
constexpr friend matrix_t operator/(scalar_t lhs, const matrix_t& rhs)
{
matrix_t retval = rhs;
((retval[ColIndicesV] /= lhs), ...);
return retval;
}
///
/// \brief \ref fennec::matrix "matrix" - \ref scalar addition assignment operator.
/// \param lhs the matrix
/// \param rhs the scalar
/// \returns the matrix after having each component added by the scalar
constexpr friend matrix_t& operator+=(matrix_t& lhs, scalar_t rhs)
{
((lhs[ColIndicesV] += rhs), ...);
return lhs;
}
///
/// \brief \ref scalar - \ref fennec::matrix "matrix" addition assignment operator.
/// \param lhs the scalar
/// \param rhs the matrix
/// \returns the matrix after having each component added by the scalar
constexpr friend matrix_t& operator+=(scalar_t lhs, matrix_t& rhs)
{
((rhs[ColIndicesV] += lhs), ...);
return rhs;
}
///
/// \brief \ref fennec::matrix "matrix" - \ref scalar subtraction assignment operator.
/// \param lhs the matrix
/// \param rhs the scalar
/// \returns the matrix after having each component subtracted by the scalar
constexpr friend matrix_t& operator-=(matrix_t& lhs, scalar_t rhs)
{
((lhs[ColIndicesV] -= rhs), ...);
return lhs;
}
///
/// \brief \ref scalar - \ref fennec::matrix "matrix" addition assignment operator.
/// \param lhs the scalar
/// \param rhs the matrix
/// \returns the matrix after having each component added by the scalar
constexpr friend matrix_t& operator-=(scalar_t lhs, matrix_t& rhs)
{
((rhs[ColIndicesV] -= lhs), ...);
return rhs;
}
///
/// \brief \ref fennec::matrix "matrix" - \ref scalar multiplication assignment operator.
/// \param lhs the matrix
/// \param rhs the scalar
/// \returns the matrix after having each component multiplied by the scalar
constexpr friend matrix_t& operator*=(matrix_t& lhs, scalar_t rhs)
{
((lhs[ColIndicesV] *= rhs), ...);
return lhs;
}
///
/// \brief \ref scalar - \ref fennec::matrix "matrix" multiplication assignment operator.
/// \param lhs the scalar
/// \param rhs the matrix
/// \returns the matrix after having each component multiplied by the scalar
constexpr friend matrix_t& operator*=(scalar_t lhs, matrix_t& rhs)
{
((rhs[ColIndicesV] *= lhs), ...);
return rhs;
}
///
/// \brief \ref fennec::matrix "matrix" - \ref scalar division assignment operator.
/// \param lhs the matrix
/// \param rhs the scalar
/// \returns the matrix after having each component divided by the scalar
constexpr friend matrix_t& operator/=(matrix_t& lhs, scalar_t rhs)
{
((lhs[ColIndicesV] /= rhs), ...);
return lhs;
}
///
/// \brief \ref scalar - \ref fennec::matrix "matrix" division assignment operator.
/// \param lhs the scalar
/// \param rhs the matrix
/// \returns the matrix after having each component divided by the scalar
constexpr friend matrix_t& operator/=(scalar_t lhs, matrix_t& rhs)
{
((rhs[ColIndicesV] /= lhs), ...);
return rhs;
}
///
/// \brief \ref fennec::matrix "matrix" - \ref scalar modulo operator.
/// \param lhs the matrix
/// \param rhs the scalar
/// \returns a copy of the matrix with each component having been reduced modulo by the scalar
constexpr friend matrix_t operator%(const matrix_t& lhs, scalar_t rhs) requires is_integral_v<scalar_t>
{
matrix_t retval = lhs;
((retval[ColIndicesV] %= rhs), ...);
return retval;
}
///
/// \brief \ref scalar - \ref fennec::matrix "matrix" modulo operator.
/// \param lhs the scalar
/// \param rhs the matrix
/// \returns a copy of the matrix with each component having been reduced modulo by the scalar
constexpr friend matrix_t operator%(scalar_t lhs, const matrix_t& rhs) requires is_integral_v<scalar_t>
{
matrix_t retval = rhs;
((retval[ColIndicesV] %= lhs), ...);
return retval;
}
///
/// \brief \ref fennec::matrix "matrix" - \ref scalar modulo assignment operator.
/// \param lhs the matrix
/// \param rhs the scalar
/// \returns the matrix after having each component reduced modulo by the scalar
constexpr friend matrix_t& operator%=(matrix_t& lhs, scalar_t rhs) requires is_integral_v<scalar_t>
{
((lhs[ColIndicesV] %= rhs), ...);
return lhs;
}
///
/// \brief \ref scalar - \ref fennec::matrix "matrix" modulo assignment operator.
/// \param lhs the scalar
/// \param rhs the matrix
/// \returns the matrix after having each component reduced modulo by the scalar
constexpr friend matrix_t& operator%=(scalar_t lhs, matrix_t& rhs) requires is_integral_v<scalar_t>
{
((rhs[ColIndicesV] %= lhs), ...);
return rhs;
}
/// @}
// Vector Operators ====================================================================================================
/// \name \ref matrix_t "matrix" \ref fennec::vector "vector" Operators
/// \name \ref fennec::matrix "matrix" - \ref fennec::vector "vector" Operators
/// @{
///
@@ -330,9 +565,25 @@ struct matrix
// Matrix Operators ====================================================================================================
/// \name \ref matrix_t "matrix" \ref matrix_t "matrix" Operators
/// \name \ref fennec::matrix "matrix" - \ref fennec::matrix "matrix" Operators
/// @{
///
/// \brief matrix comparison operator
/// \param lhs the first matrix
/// \param rhs the second matrix
/// \returns a boolean value that contains \f$true\f$ when all components of `lhs` and `rhs` are equal and \f$false\f$ otherwise
constexpr friend bool operator==(const matrix_t& lhs, const matrix_t& rhs)
{ return lhs.data == rhs.data; }
///
/// \brief matrix comparison operator
/// \param lhs the first matrix
/// \param rhs the second matrix
/// \returns a boolean value that contains \f$true\f$ when all components of `lhs` and `rhs` are not equal and \f$false\f$ otherwise
constexpr friend bool operator!=(const matrix_t& lhs, const matrix_t& rhs)
{ return lhs.data != rhs.data; }
///
/// \brief performs a linear algebraic matrix multiplication
/// \param lhs the rows to multiply with
@@ -341,12 +592,6 @@ struct matrix
{ return [lhs, rhs]<size_t...i>(index_sequence<i...>) -> matrix_t
{ return matrix_t(rhs * fennec::row(lhs, i)...); }(make_index_sequence<rows>{}); }
constexpr friend bool operator==(const matrix_t& lhs, const matrix_t& rhs)
{ return lhs.data == rhs.data; }
constexpr friend bool operator!=(const matrix_t& lhs, const matrix_t& rhs)
{ return lhs.data != rhs.data; }
/// @}

View File

@@ -163,8 +163,7 @@ using ivec2 = tvec2<int32_t>;
/// \brief A three-component signed integer \ref fennec_math_vector "vector"
using ivec3 = tvec3<int32_t>;
/// \typedef ivec4
/// \anchor ivec4
///
/// \brief A four-component signed integer \ref fennec_math_vector "vector"
using ivec4 = tvec4<int32_t>;
@@ -214,7 +213,6 @@ using dvec4 = tvec4<float64_t>;
///
/// \struct fennec::vector
/// \brief Math Vector Type
/// \tparam ScalarT base \ref scalar type of each Component
/// \tparam IndicesV index of each Component
@@ -233,7 +231,6 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
/// @{
///
/// \typedef vector::base_type
/// \brief vector base type
using base_type = detail::vector_base_type<ScalarT, sizeof...(IndicesV)>;
@@ -242,12 +239,10 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
using base_type::data;
///
/// \typedef scalar_t
/// \brief alias for ScalarT
using scalar_t = ScalarT;
///
/// \typedef vector::vector_t
/// \brief alias for this type
using vector_t = vector;
@@ -667,7 +662,6 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
{ return vector((lhs[IndicesV] * rhs[IndicesV]) ...); }
///
/// \fn vector::operator/(const vector_t&, const vector_t&)
/// \brief \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" division operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
@@ -899,7 +893,7 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
///
/// \ref fennec_math_scalar "scalar" - \ref fennec_math_vector "vector" bitwise or operator
/// \ref fennec_math_scalar "scalar" - \ref fennec_math_vector "vector" bitwise xor operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
/// \returns A \ref fennec_math_vector "vector" \a v such that, \f$v_i=lhs_i\^rhs_i\f$
@@ -907,8 +901,7 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
{ return vector_t((lhs ^ rhs[IndicesV]) ...); }
///
/// \fn vector::operator^=(vector_t&, scalar_t)
/// \ref fennec_math_vector "vector" - \ref fennec_math_scalar "scalar" bitwise or assignment operator
/// \ref fennec_math_vector "vector" - \ref fennec_math_scalar "scalar" bitwise xor assignment operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
/// \returns A \ref fennec_math_vector "vector" \a v such that, \f$v_i=lhs_i\^rhs_i\f$
@@ -916,8 +909,7 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
{ return ((lhs[IndicesV] ^= rhs), ..., lhs); }
///
/// \fn vector::operator^(const vector_t&, scalar_t)
/// \ref fennec_math_vector "vector" - \ref fennec_math_scalar "scalar" bitwise or operator
/// \ref fennec_math_vector "vector" - \ref fennec_math_scalar "scalar" bitwise xor operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
/// \returns A \ref fennec_math_vector "vector" \a v such that, \f$v_i=lhs_i\^rhs_i\f$
@@ -925,8 +917,7 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
{ return vector_t((lhs[IndicesV] ^ rhs) ...); }
///
/// \fn vector::operator^=(vector_t&, const vector_t&)
/// \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" bitwise or assignment operator
/// \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" bitwise xor assignment operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
/// \returns A \ref fennec_math_vector "vector" \a v such that, \f$v_i=lhs_i\^rhs_i\f$
@@ -934,8 +925,7 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
{ return ((lhs[IndicesV] ^= rhs), ..., lhs); }
///
/// \fn vector::operator^(const vector_t&, const vector_t&)
/// \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" bitwise or operator
/// \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" bitwise xor operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
/// \returns A \ref fennec_math_vector "vector" \a v such that, \f$v_i=lhs_i\^rhs_i\f$
@@ -945,7 +935,6 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
///
/// \fn vector::operator<<=(vector_t&, scalar_t)
/// \ref fennec_math_vector "vector" - \ref fennec_math_scalar "scalar" bitwise left-shift assignment operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
@@ -954,7 +943,6 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
{ return ((lhs[IndicesV] <<= rhs), ..., lhs); }
///
/// \fn vector::operator<<(const vector_t&, scalar_t)
/// \ref fennec_math_vector "vector" - \ref fennec_math_scalar "scalar" bitwise or operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
@@ -963,7 +951,6 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
{ return vector_t((lhs[IndicesV] << rhs) ...); }
///
/// \fn vector::operator<<=(vector_t&, const vector_t&)
/// \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" bitwise or assignment operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
@@ -972,7 +959,6 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
{ return ((lhs[IndicesV] <<= rhs), ..., lhs); }
///
/// \fn vector::operator<<(const vector_t&, const vector_t&)
/// \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" bitwise or operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
@@ -983,7 +969,6 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
///
/// \fn vector::operator>>=(vector_t&, scalar_t)
/// \ref fennec_math_vector "vector" - \ref fennec_math_scalar "scalar" bitwise left-shift assignment operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
@@ -992,7 +977,6 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
{ return ((lhs[IndicesV] >>= rhs), ..., lhs); }
///
/// \fn vector::operator>>(const vector_t&, scalar_t)
/// \ref fennec_math_vector "vector" - \ref fennec_math_scalar "scalar" bitwise or operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
@@ -1001,7 +985,6 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
{ return vector_t((lhs[IndicesV] >> rhs) ...); }
///
/// \fn vector::operator>>=(vector_t&, const vector_t&)
/// \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" bitwise or assignment operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression
@@ -1010,7 +993,6 @@ struct vector : detail::vector_base_type<ScalarT, sizeof...(IndicesV)>
{ return ((lhs[IndicesV] >>= rhs), ..., lhs); }
///
/// \fn vector::operator>>(const vector_t&, const vector_t&)
/// \ref fennec_math_vector "vector" - \ref fennec_math_vector "vector" bitwise or operator
/// \param lhs Left Hand Side of the Expression
/// \param rhs Right Hand Side of the Expression

View File

@@ -34,7 +34,6 @@ namespace detail
{
///
/// \struct vector_base_type_helper
/// \brief helper class for generating vectors
/// \tparam scalar base scalar type
/// \tparam size size of the vector type
@@ -48,22 +47,18 @@ struct vector_base_type_helper
///
/// \typedef ScalarT
/// \brief Base scalar type
using ScalarT = scalar;
///
/// \typedef VectorT
/// \brief Base vector type
using VectorT = vec<ScalarT, SizeV>;
///
/// \typedef DataT
/// \brief Backing array holding the elements
using DataT = array<ScalarT, SizeV>;
///
/// \struct SwizzleGen
/// \brief Helper for generating a swizzle from a set of indices
/// \tparam IndicesV Indices of the vector to pull from
template<size_t...IndicesV> struct SwizzleGen
@@ -72,10 +67,7 @@ struct vector_base_type_helper
using type = swizzle<VectorT, DataT, ScalarT, IndicesV...>;
};
///
/// \struct SwizzleGen<IndexV>
/// \brief Partial Specialization for single component swizzles to decay into a scalar
/// \tparam IndexV
// Specialization for single component swizzles to decay into a scalar
template<size_t IndexV> struct SwizzleGen<IndexV>
{
/// \brief decayed scalar type
@@ -83,11 +75,12 @@ struct vector_base_type_helper
};
///
/// \typedef StorageT
/// \brief backing storage type
using StorageT = vector_storage<SizeV, SwizzleGen, DataT>;
};
///
/// \brief helper for getting the storage type of the vector constructed with the provided size and scalar type
template<typename ScalarT, size_t SizeV>
using vector_base_type = typename vector_base_type_helper<ScalarT, SizeV>::StorageT;

View File

@@ -30,7 +30,6 @@ namespace detail
{
///
/// \struct vector_storage
/// \brief backing storage type for vectors
/// \tparam SizeV size of the vector
/// \tparam SwizzleGenT generator for swizzles
@@ -38,17 +37,10 @@ namespace detail
template<size_t SizeV, template<size_t...> class SwizzleGenT, typename DataT> struct vector_storage;
///
/// \struct vector_storage<1, SwizzleGenT, DataT>
/// \brief specialization for single component vectors
/// \tparam SwizzleGenT generator for swizzles
/// \tparam DataT backing data type
// specialization for single component vectors
template <template <size_t...> class SwizzleGenT, typename DataT>
struct vector_storage<1, SwizzleGenT, DataT>
{
///
/// \typedef swizzle
/// alias to allow for increased legibility
template<size_t...IndicesV> using swizzle = typename SwizzleGenT<IndicesV...>::type;
vector_storage() = default;
@@ -69,16 +61,11 @@ struct vector_storage<1, SwizzleGenT, DataT>
};
///
/// \struct vector_storage<2, SwizzleGenT, DataT>
/// \brief specialization for two component vectors
/// \tparam SwizzleGenT generator for swizzles
/// \tparam DataT backing data type
// specialization for two component vectors
template <template <size_t...> class SwizzleGenT, typename DataT>
struct vector_storage<2, SwizzleGenT, DataT>
{
///
/// \typedef swizzle
/// alias to allow for increased legibility
template<size_t...IndicesV> using swizzle = typename SwizzleGenT<IndicesV...>::type;
@@ -123,17 +110,10 @@ struct vector_storage<2, SwizzleGenT, DataT>
};
///
/// \struct vector_storage<3, SwizzleGenT, DataT>
/// \brief specialization for three component vectors
/// \tparam SwizzleGenT generator for swizzles
/// \tparam DataT backing data type
// specialization for three component vectors
template <template <size_t...> class SwizzleGenT, typename DataT>
struct vector_storage<3, SwizzleGenT, DataT>
{
///
/// \typedef swizzle
/// alias to allow for increased legibility
template<size_t...IndicesV> using swizzle = typename SwizzleGenT<IndicesV...>::type;
vector_storage() = default;
@@ -266,17 +246,10 @@ struct vector_storage<3, SwizzleGenT, DataT>
};
///
/// \struct vector_storage<4, SwizzleGenT, DataT>
/// \brief specialization for four component vectors
/// \tparam SwizzleGenT generator for swizzles
/// \tparam DataT backing data type
// specialization for four component vectors
template <template <size_t...> class SwizzleGenT, typename DataT>
struct vector_storage<4, SwizzleGenT, DataT>
{
///
/// \typedef swizzle
/// alias to allow for increased legibility
template<size_t...IndicesV> using swizzle = typename SwizzleGenT<IndicesV...>::type;
vector_storage() = default;

View File

@@ -39,8 +39,8 @@ constexpr TypeT* addressof(TypeT& obj) { return FENNEC_BUILTIN_ADDRESSOF(obj); }
constexpr void* memchr(void* arr, int ch, size_t n)
{
uint8_t* a = static_cast<uint8_t*>(arr);
while (n--) if (*a++ == ch) return a - 1;
return nullptr;
while (n-- && *a++ != ch) {}
return n ? a : nullptr;
}
///
@@ -52,8 +52,8 @@ constexpr void* memchr(void* arr, int ch, size_t n)
constexpr const void* memchr(const void* arr, int ch, size_t n)
{
const uint8_t* a = static_cast<const uint8_t*>(arr);
while (n--) if (*a++ == ch) return a - 1;
return nullptr;
while (n-- && *a++ != ch) {}
return n ? a : nullptr;
}
///
@@ -67,12 +67,8 @@ constexpr int memcmp(const void* lhs, const void* rhs, size_t n)
{
const uint8_t* lhs_ = static_cast<const uint8_t*>(lhs);
const uint8_t* rhs_ = static_cast<const uint8_t*>(rhs);
while (n--)
if (*lhs_++ != *rhs_++)
return lhs_[-1] - rhs_[-1];
return 0;
while (n-- && *lhs_++ == *rhs_++) {}
return n ? *lhs_ - *rhs_ : 0;
}
///
@@ -101,8 +97,7 @@ constexpr void* memcpy(void* dst, const void* src, size_t n)
uint8_t* d = static_cast<uint8_t*>(dst);
const uint8_t* s = static_cast<const uint8_t*>(src);
while (n > 0)
{
while (n > 0) {
size_t step = detail::__memcpy(d, s, n);
d += step; s += step; n -= step;
}
@@ -130,19 +125,15 @@ constexpr void* memmove(void* dst, const void* src, size_t n)
uint8_t* d = static_cast<uint8_t*>(dst);
const uint8_t* s = static_cast<const uint8_t*>(src);
if (d < s)
{
while (n > 0)
{
if (d < s) {
while (n > 0) {
size_t step = detail::__memcpy(d, s, n);
d += step; s += step; n -= step;
}
}
else
{
else {
d += n - 1; s += n - 1;
while (n > 0)
{
while (n > 0) {
size_t step = detail::__memcpy(d, s, n);
d -= step; s -= step; n -= step;
}
@@ -167,15 +158,12 @@ constexpr void* memmove_s(void* dst, size_t n0, const void* src, size_t n1)
constexpr void* memset(void* dst, int ch, size_t n)
{
uint8_t* d = static_cast<uint8_t*>(dst);
uint8_t val8 = ch;
uint16_t val16 = (static_cast<uint16_t>(val8) << 8) | static_cast<int16_t>(val8);
uint32_t val32 = (static_cast<uint32_t>(val16) << 16) | static_cast<int32_t>(val16);
uint64_t val64 = (static_cast<uint64_t>(val32) << 32) | static_cast<int64_t>(val32);
uint8_t val[8] = { static_cast<uint8_t>(ch) };
while (n >= 8) { detail::__memcpy_64(d, &val64); d += 8; n -= 8; }
while (n >= 4) { detail::__memcpy_32(d, &val32); d += 4; n -= 4; }
while (n >= 2) { detail::__memcpy_16(d, &val16); d += 2; n -= 2; }
while (n >= 1) { *d++ = val8; --n; }
while (n > 0) {
size_t step = detail::__memcpy(d, val, n);
d += step; n -= step;
}
return dst;
}