From 2479dc8ec12d80c8ab62a99446fc08cf5f794dd4 Mon Sep 17 00:00:00 2001 From: Matthew Rodusek Date: Sat, 5 Sep 2020 12:49:58 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Modernize=20math=20sources/heade?= =?UTF-8?q?rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The various math headers and sources have been modernized using `clang-tidy` and cleaned up with a post-processing pass. --- .../alloy/core/math/angle/basic_angle.hpp | 333 +++++++++-------- .../include/alloy/core/math/angle/degree.hpp | 22 +- .../include/alloy/core/math/angle/gradian.hpp | 25 +- .../include/alloy/core/math/angle/radian.hpp | 23 +- .../include/alloy/core/math/euler_angles.hpp | 337 +++++++++--------- .../include/alloy/core/math/interpolation.hpp | 259 ++++++++------ .../include/alloy/core/math/math.hpp | 120 ++++--- .../core/math/matrix/matrix_utilities.hpp | 180 +++------- .../include/alloy/core/math/simplex.hpp | 308 ++++++++-------- .../include/alloy/core/math/trigonometry.hpp | 76 ++-- .../src/alloy/core/math/simplex.cpp | 169 +++++---- .../src/alloy/core/math/trigonometry.cpp | 29 +- 12 files changed, 929 insertions(+), 952 deletions(-) diff --git a/lib/alloy-core/include/alloy/core/math/angle/basic_angle.hpp b/lib/alloy-core/include/alloy/core/math/angle/basic_angle.hpp index cbf3c7ff..dbf242e0 100644 --- a/lib/alloy-core/include/alloy/core/math/angle/basic_angle.hpp +++ b/lib/alloy-core/include/alloy/core/math/angle/basic_angle.hpp @@ -108,7 +108,14 @@ namespace alloy::core { using angle_unit = AngleUnit; //-------------------------------------------------------------------------- - // Constructors + // Public Static Members + //-------------------------------------------------------------------------- + public: + + static inline constexpr auto comparison_tolerance = default_tolerance; + + //-------------------------------------------------------------------------- + // Constructors / Assignment //-------------------------------------------------------------------------- public: @@ -119,33 +126,20 @@ namespace alloy::core { /// \brief Constructs a basic_angle from the given floating point value /// - /// \param value the value of the basic_angle angle - constexpr explicit basic_angle( real value ) noexcept; + /// \param angle the value of the basic_angle angle + constexpr explicit basic_angle(real angle) noexcept; /// \brief Copy-constructs a basic_angle from another basic_angle /// /// \param other the other basic_angle to copy - constexpr basic_angle( const basic_angle& other ) noexcept = default; + constexpr basic_angle(const basic_angle& other) noexcept = default; - /// \brief Move-constructs a basic_angle from another basic_angle - /// - /// \param other the other basic_angle to move - constexpr basic_angle( basic_angle&& other ) noexcept = default; - - //-------------------------------------------------------------------------- - // Assignment //-------------------------------------------------------------------------- - public: /// \brief Copy-assigns a basic_angle from another basic_angle /// /// \param other the other basic_angle to copy - basic_angle& operator=( const basic_angle& other ) noexcept = default; - - /// \brief Move-assigns a basic_angle from another basic_angle - /// - /// \param other the other basic_angle to move - basic_angle& operator=( basic_angle&& other ) noexcept = default; + auto operator=(const basic_angle& other) noexcept -> basic_angle& = default; //-------------------------------------------------------------------------- // Observers @@ -155,37 +149,37 @@ namespace alloy::core { /// \brief Gets the value decimal value of the angle /// /// \return the value of the angle - constexpr real value() const noexcept; + constexpr auto value() const noexcept -> real; /// \brief Counts the number of revolutions for the current /// \ref basic_angle /// /// \return the number of revolutions - constexpr real revolutions() const noexcept; + constexpr auto revolutions() const noexcept -> real; /// \brief Constrains the \ref basic_angle between \c 0 and /// \c AngleUnit::revolution() /// /// \return the constrained \ref basic_angle - basic_angle constrained() const noexcept; + auto constrained() const noexcept -> basic_angle; //-------------------------------------------------------------------------- // Unary Operators //-------------------------------------------------------------------------- public: - constexpr basic_angle operator+() const noexcept; - constexpr basic_angle operator-() const noexcept; + constexpr auto operator+() const noexcept -> basic_angle; + constexpr auto operator-() const noexcept -> basic_angle; //-------------------------------------------------------------------------- // Compound Assignment //-------------------------------------------------------------------------- public: - basic_angle& operator+=( const basic_angle& rhs ) noexcept; - basic_angle& operator-=( const basic_angle& rhs ) noexcept; - basic_angle& operator*=( real rhs ) noexcept; - basic_angle& operator/=( real rhs ) noexcept; + auto operator+=(const basic_angle& rhs) noexcept -> basic_angle&; + auto operator-=(const basic_angle& rhs) noexcept -> basic_angle&; + auto operator*=(real rhs) noexcept -> basic_angle&; + auto operator/=(real rhs) noexcept -> basic_angle&; //-------------------------------------------------------------------------- // Private Members @@ -204,45 +198,45 @@ namespace alloy::core { //---------------------------------------------------------------------------- template - constexpr basic_angle - operator+( const basic_angle& lhs, - const basic_angle& rhs ) noexcept; + constexpr auto operator+(const basic_angle& lhs, + const basic_angle& rhs) + noexcept -> basic_angle; template - constexpr basic_angle - operator-( const basic_angle& lhs, - const basic_angle& rhs ) noexcept; + constexpr auto operator-(const basic_angle& lhs, + const basic_angle& rhs) + noexcept -> basic_angle; template - constexpr basic_angle - operator*( const basic_angle& lhs, real rhs ) noexcept; + constexpr auto operator*(const basic_angle& lhs, real rhs) + noexcept -> basic_angle; template - constexpr basic_angle - operator*( real rhs, const basic_angle& lhs ) noexcept; + constexpr auto operator*(real lhs, const basic_angle& rhs) + noexcept -> basic_angle; template - constexpr basic_angle - operator/( const basic_angle& lhs, real rhs ) noexcept; + constexpr auto operator/(const basic_angle& lhs, real rhs) + noexcept -> basic_angle; //---------------------------------------------------------------------------- // Comparisons //---------------------------------------------------------------------------- template - constexpr bool operator==( const basic_angle& lhs, - const basic_angle& rhs ) noexcept; + constexpr auto operator==(const basic_angle& lhs, + const basic_angle& rhs) noexcept -> bool; template - constexpr bool operator!=( const basic_angle& lhs, - const basic_angle& rhs ) noexcept; + constexpr auto operator!=(const basic_angle& lhs, + const basic_angle& rhs) noexcept -> bool; template - constexpr bool operator<( const basic_angle& lhs, - const basic_angle& rhs ) noexcept; + constexpr auto operator<(const basic_angle& lhs, + const basic_angle& rhs) noexcept -> bool; template - constexpr bool operator>( const basic_angle& lhs, - const basic_angle& rhs ) noexcept; + constexpr auto operator>(const basic_angle& lhs, + const basic_angle& rhs) noexcept -> bool; template - constexpr bool operator<=( const basic_angle& lhs, - const basic_angle& rhs ) noexcept; + constexpr auto operator<=(const basic_angle& lhs, + const basic_angle& rhs) noexcept -> bool; template - constexpr bool operator>=( const basic_angle& lhs, - const basic_angle& rhs ) noexcept; + constexpr auto operator>=(const basic_angle& lhs, + const basic_angle& rhs) noexcept -> bool; //---------------------------------------------------------------------------- @@ -253,8 +247,8 @@ namespace alloy::core { /// \param rhs the right basic_angle /// \return \c true if the two basic_angle contain almost equal values template - constexpr bool almost_equal( const basic_angle& lhs, - const basic_angle& rhs ) noexcept; + constexpr auto almost_equal(const basic_angle& lhs, + const basic_angle& rhs) noexcept -> bool; /// \brief Determines equality between two basic_angle relative to /// \ref tolerance @@ -263,9 +257,9 @@ namespace alloy::core { /// \param rhs the right basic_angle /// \return \c true if the two basic_angle contain almost equal values template - constexpr bool almost_equal( const basic_angle& lhs, - const basic_angle& rhs, - real tolerance ) noexcept; + constexpr auto almost_equal(const basic_angle& lhs, + const basic_angle& rhs, + real tolerance) noexcept -> bool; //--------------------------------------------------------------------------- // Utilities : Math Functions @@ -276,7 +270,7 @@ namespace alloy::core { /// \param angle the angle to round /// \return the rounded angle template - basic_angle round( basic_angle angle ) noexcept; + auto round(basic_angle angle) noexcept -> basic_angle; /// \brief Rounds a given \p angle up as if by calling /// \code ceil( angle.value() ) \endcode @@ -284,7 +278,7 @@ namespace alloy::core { /// \param angle the radian to round up /// \return the rounded angle template - basic_angle ceil( basic_angle angle ) noexcept; + auto ceil(basic_angle angle) noexcept -> basic_angle; /// \brief Rounds a given \p angle up as if by calling /// \code floor( angle.value() ) \endcode @@ -292,7 +286,7 @@ namespace alloy::core { /// \param angle the angle to round down /// \return the rounded angle template - basic_angle floor( basic_angle angle ) noexcept; + auto floor(basic_angle angle) noexcept -> basic_angle; /// \brief Truncates the given \p angle as if by calling /// \code trunc( angle.value() ) \endcode @@ -300,7 +294,7 @@ namespace alloy::core { /// \param angle the angle to truncate /// \return the rounded angle template - basic_angle trunc( basic_angle angle ) noexcept; + auto trunc(basic_angle angle) noexcept -> basic_angle; //------------------------------------------------------------------------ @@ -310,7 +304,7 @@ namespace alloy::core { /// \param angle the angle to retrieve the absolute value of /// \return the rounded angle template - basic_angle abs( basic_angle angle ) noexcept; + auto abs(basic_angle angle) noexcept -> basic_angle; //============================================================================ // trait : is_angle @@ -331,7 +325,7 @@ namespace alloy::core { constexpr bool is_angle_v = is_angle::value; //============================================================================ - // struct : gradian_constants + // struct : basic_angle_constants //============================================================================ ////////////////////////////////////////////////////////////////////////////// @@ -342,7 +336,9 @@ namespace alloy::core { { using angle_type = basic_angle; - static inline constexpr auto revolution = angle_type{ AngleUnit::revolution() }; + static inline constexpr auto revolution = angle_type{ + AngleUnit::revolution() + }; static inline constexpr auto half_revolution = revolution / real{2}; static inline constexpr auto quarter_revolution = half_revolution / real{2}; }; @@ -359,7 +355,7 @@ namespace alloy::core { /// \param from the angle to cast /// \return the new angle template - inline constexpr To to_angle( From from ); + inline constexpr auto to_angle(From from) -> To; } // inline namespace casts } // namespace alloy::core @@ -374,8 +370,8 @@ namespace alloy::core { //------------------------------------------------------------------------------ template -inline constexpr alloy::core::basic_angle - ::basic_angle() +inline constexpr +alloy::core::basic_angle::basic_angle() noexcept : m_angle{0} { @@ -383,8 +379,8 @@ inline constexpr alloy::core::basic_angle } template -inline constexpr alloy::core::basic_angle - ::basic_angle( core::real angle ) +inline constexpr +alloy::core::basic_angle::basic_angle(real angle) noexcept : m_angle{angle} { @@ -396,31 +392,33 @@ inline constexpr alloy::core::basic_angle //------------------------------------------------------------------------------ template -inline constexpr alloy::core::real - alloy::core::basic_angle::value() - const noexcept +inline constexpr +auto alloy::core::basic_angle::value() + const noexcept -> real { return m_angle; } template -inline constexpr alloy::core::real - alloy::core::basic_angle::revolutions() - const noexcept +inline constexpr +auto alloy::core::basic_angle::revolutions() + const noexcept -> real { return m_angle / AngleUnit::revolution(); } template -inline alloy::core::basic_angle - alloy::core::basic_angle::constrained() - const noexcept +inline +auto alloy::core::basic_angle::constrained() + const noexcept -> basic_angle { const auto angle = std::fmod(m_angle, AngleUnit::revolution()); - if(angle < 0) angle += AngleUnit::revolution(); + if (angle < 0) { + angle += AngleUnit::revolution(); + } - return basic_angle{ core::real(angle) }; + return basic_angle{ real(angle) }; } //------------------------------------------------------------------------------ @@ -428,17 +426,18 @@ inline alloy::core::basic_angle //------------------------------------------------------------------------------ template -constexpr alloy::core::basic_angle - alloy::core::basic_angle::operator+() - const noexcept +inline constexpr +auto alloy::core::basic_angle::operator+() + const noexcept -> basic_angle { return (*this); } template -constexpr alloy::core::basic_angle - alloy::core::basic_angle::operator-() +inline constexpr +auto alloy::core::basic_angle::operator-() const noexcept + -> basic_angle { return basic_angle{-m_angle}; } @@ -448,36 +447,36 @@ constexpr alloy::core::basic_angle //------------------------------------------------------------------------------ template -inline alloy::core::basic_angle& - alloy::core::basic_angle::operator+=( const basic_angle& rhs ) - noexcept +inline +auto alloy::core::basic_angle::operator+=(const basic_angle& rhs) + noexcept -> basic_angle& { m_angle += rhs.m_angle; return (*this); } template -inline alloy::core::basic_angle& - alloy::core::basic_angle::operator-=( const basic_angle& rhs ) - noexcept +inline +auto alloy::core::basic_angle::operator-=(const basic_angle& rhs) + noexcept -> basic_angle& { m_angle -= rhs.m_angle; return (*this); } template -inline alloy::core::basic_angle& - alloy::core::basic_angle::operator*=( core::real rhs ) - noexcept +inline +auto alloy::core::basic_angle::operator*=(real rhs) + noexcept -> basic_angle& { m_angle *= rhs; return (*this); } template -inline alloy::core::basic_angle& - alloy::core::basic_angle::operator/=( core::real rhs ) - noexcept +inline +auto alloy::core::basic_angle::operator/=(real rhs) + noexcept -> basic_angle& { m_angle /= rhs; return (*this); @@ -492,43 +491,43 @@ inline alloy::core::basic_angle& //------------------------------------------------------------------------------ template -inline constexpr alloy::core::basic_angle - alloy::core::operator+( const basic_angle& lhs, - const basic_angle& rhs ) - noexcept +inline constexpr +auto alloy::core::operator+(const basic_angle& lhs, + const basic_angle& rhs) + noexcept -> basic_angle { return basic_angle{ lhs.value() + rhs.value() }; } template -inline constexpr alloy::core::basic_angle - alloy::core::operator-( const basic_angle& lhs, - const basic_angle& rhs ) - noexcept +inline constexpr +auto alloy::core::operator-(const basic_angle& lhs, + const basic_angle& rhs) + noexcept -> basic_angle { return basic_angle{ lhs.value() - rhs.value() }; } template -inline constexpr alloy::core::basic_angle - alloy::core::operator*( const basic_angle& lhs, core::real rhs ) - noexcept +inline constexpr +auto alloy::core::operator*(const basic_angle& lhs, real rhs) + noexcept -> basic_angle { return basic_angle{ lhs.value() * rhs }; } template -inline constexpr alloy::core::basic_angle - alloy::core::operator*( core::real lhs, const basic_angle& rhs ) - noexcept +inline constexpr +auto alloy::core::operator*(real lhs, const basic_angle& rhs) + noexcept -> basic_angle { return basic_angle{ rhs.value() * lhs }; } template -inline constexpr alloy::core::basic_angle - alloy::core::operator/( const basic_angle& lhs, core::real rhs ) - noexcept +inline constexpr +auto alloy::core::operator/(const basic_angle& lhs, real rhs) + noexcept -> basic_angle { return basic_angle{ lhs.value() / rhs }; } @@ -541,19 +540,19 @@ ALLOY_COMPILER_DIAGNOSTIC_PUSH() ALLOY_COMPILER_GNULIKE_DIAGNOSTIC_IGNORE(-Wfloat-equal) template -inline constexpr bool - alloy::core::operator==( const basic_angle& lhs, - const basic_angle& rhs ) - noexcept +inline constexpr +auto alloy::core::operator==(const basic_angle& lhs, + const basic_angle& rhs) + noexcept -> bool { return lhs.value() == rhs.value(); } template -inline constexpr bool - alloy::core::operator!=( const basic_angle& lhs, - const basic_angle& rhs ) - noexcept +inline constexpr +auto alloy::core::operator!=(const basic_angle& lhs, + const basic_angle& rhs) + noexcept -> bool { return !(lhs==rhs); } @@ -561,37 +560,37 @@ inline constexpr bool ALLOY_COMPILER_DIAGNOSTIC_POP() template -inline constexpr bool - alloy::core::operator<( const basic_angle& lhs, - const basic_angle& rhs ) - noexcept +inline constexpr +auto alloy::core::operator<(const basic_angle& lhs, + const basic_angle& rhs) + noexcept -> bool { return lhs.value() < rhs.value(); } template -inline constexpr bool - alloy::core::operator>( const basic_angle& lhs, - const basic_angle& rhs ) - noexcept +inline constexpr +auto alloy::core::operator>(const basic_angle& lhs, + const basic_angle& rhs) + noexcept -> bool { return lhs.value() > rhs.value(); } template -inline constexpr bool - alloy::core::operator<=( const basic_angle& lhs, - const basic_angle& rhs ) - noexcept +inline constexpr +auto alloy::core::operator<=(const basic_angle& lhs, + const basic_angle& rhs) + noexcept -> bool { return lhs.value() <= rhs.value(); } template -inline constexpr bool - alloy::core::operator>=( const basic_angle& lhs, - const basic_angle& rhs ) - noexcept +inline constexpr +auto alloy::core::operator>=(const basic_angle& lhs, + const basic_angle& rhs) + noexcept -> bool { return lhs.value() >= rhs.value(); } @@ -599,20 +598,20 @@ inline constexpr bool //------------------------------------------------------------------------------ template -inline constexpr bool - alloy::core::almost_equal( const basic_angle& lhs, - const basic_angle& rhs ) - noexcept +inline constexpr +auto alloy::core::almost_equal(const basic_angle& lhs, + const basic_angle& rhs) + noexcept -> bool { return almost_equal( lhs.value(), rhs.value() ); } template -inline constexpr bool - alloy::core::almost_equal( const basic_angle& lhs, - const basic_angle& rhs, - core::real tolerance ) - noexcept +inline constexpr +auto alloy::core::almost_equal(const basic_angle& lhs, + const basic_angle& rhs, + real tolerance) + noexcept -> bool { return almost_equal( lhs.value(), rhs.value(), tolerance ); } @@ -622,33 +621,29 @@ inline constexpr bool //------------------------------------------------------------------------------ template -alloy::core::basic_angle - alloy::core::round( basic_angle angle ) - noexcept +auto alloy::core::round(basic_angle angle) + noexcept -> basic_angle { return basic_angle{ std::round(angle.value()) }; } template -alloy::core::basic_angle - alloy::core::ceil( basic_angle angle ) - noexcept +auto alloy::core::ceil(basic_angle angle) + noexcept -> basic_angle { return basic_angle{ std::ceil(angle.value()) }; } template -alloy::core::basic_angle - alloy::core::floor( basic_angle angle ) - noexcept +auto alloy::core::floor(basic_angle angle) + noexcept -> basic_angle { return basic_angle{ std::floor(angle.value()) }; } template -alloy::core::basic_angle - alloy::core::trunc( basic_angle angle ) - noexcept +auto alloy::core::trunc(basic_angle angle) + noexcept -> basic_angle { return basic_angle{ std::trunc(angle.value()) }; } @@ -656,9 +651,8 @@ alloy::core::basic_angle //------------------------------------------------------------------------------ template -alloy::core::basic_angle - alloy::core::abs( basic_angle angle ) - noexcept +auto alloy::core::abs(basic_angle angle) + noexcept -> basic_angle { return basic_angle{ std::abs(angle.value()) }; } @@ -670,9 +664,9 @@ alloy::core::basic_angle namespace alloy::core::detail { // case: From != To template - inline constexpr basic_angle - angle_cast( basic_angle from ) - noexcept + inline constexpr + auto angle_cast(basic_angle from) + noexcept -> basic_angle { using From = AngleUnitFrom; using To = AngleUnitTo; @@ -684,16 +678,17 @@ namespace alloy::core::detail { // case: From == To template - inline constexpr const basic_angle - angle_cast( basic_angle from ) - noexcept + inline constexpr + auto angle_cast(basic_angle from) + noexcept -> const basic_angle& { return from; } -} +} // namespace alloy::core::detail template -inline constexpr To alloy::core::casts::to_angle( From from ) +inline constexpr +auto alloy::core::casts::to_angle(From from) -> To { return detail::angle_cast( from ); } diff --git a/lib/alloy-core/include/alloy/core/math/angle/degree.hpp b/lib/alloy-core/include/alloy/core/math/angle/degree.hpp index f8725fe3..09354ef9 100644 --- a/lib/alloy-core/include/alloy/core/math/angle/degree.hpp +++ b/lib/alloy-core/include/alloy/core/math/angle/degree.hpp @@ -48,7 +48,7 @@ namespace alloy::core { struct degree_unit { - static constexpr core::real revolution() noexcept; + static constexpr auto revolution() noexcept -> core::real; }; //============================================================================ @@ -72,7 +72,7 @@ namespace alloy::core { /// \param angle the angle to convert /// \return the angle in degrees template - constexpr degree to_degree( basic_angle angle ) noexcept; + constexpr auto to_degree(basic_angle angle) noexcept -> degree; } // inline namespace casts @@ -105,7 +105,7 @@ namespace alloy::core { //============================================================================ inline namespace literals { - constexpr degree operator""_deg( long double x ) noexcept; + constexpr auto operator""_deg(long double x) noexcept -> degree; } // inline namespace literals } // namespace alloy::core @@ -114,8 +114,8 @@ namespace alloy::core { // struct : degree_unit //============================================================================== -inline constexpr alloy::core::real alloy::core::degree_unit::revolution() - noexcept +inline constexpr auto + alloy::core::degree_unit::revolution() noexcept -> alloy::core::real { return static_cast(360); } @@ -129,9 +129,9 @@ inline constexpr alloy::core::real alloy::core::degree_unit::revolution() //------------------------------------------------------------------------------ template -inline constexpr alloy::core::degree - alloy::core::casts::to_degree( basic_angle angle ) - noexcept +inline constexpr auto + alloy::core::casts::to_degree(basic_angle angle) noexcept + -> alloy::core::degree { return to_angle(angle); } @@ -140,9 +140,9 @@ inline constexpr alloy::core::degree // Literals //============================================================================== -inline constexpr alloy::core::degree - alloy::core::literals::operator ""_deg( long double x ) - noexcept +inline constexpr auto + alloy::core::literals::operator""_deg(long double x) noexcept + -> alloy::core::degree { return degree{ static_cast(x) }; } diff --git a/lib/alloy-core/include/alloy/core/math/angle/gradian.hpp b/lib/alloy-core/include/alloy/core/math/angle/gradian.hpp index 5d3753a6..31af3ba9 100644 --- a/lib/alloy-core/include/alloy/core/math/angle/gradian.hpp +++ b/lib/alloy-core/include/alloy/core/math/angle/gradian.hpp @@ -48,7 +48,7 @@ namespace alloy::core { struct gradian_unit { - static constexpr core::real revolution() noexcept; + static constexpr auto revolution() noexcept -> real; }; //============================================================================ @@ -72,7 +72,7 @@ namespace alloy::core { /// \param angle the angle to convert /// \return the angle in gradians template - constexpr gradian to_gradian( basic_angle angle ) noexcept; + constexpr auto to_gradian(basic_angle angle) noexcept -> gradian; } // inline namespace casts @@ -105,7 +105,7 @@ namespace alloy::core { //============================================================================ inline namespace literals { - constexpr gradian operator""_grad( long double x ) noexcept; + constexpr auto operator""_grad(long double x) noexcept -> gradian; } // inline namespace literals } // namespace alloy::core @@ -114,8 +114,9 @@ namespace alloy::core { // struct : gradian_unit //============================================================================== -inline constexpr alloy::core::real alloy::core::gradian_unit::revolution() - noexcept +inline constexpr +auto alloy::core::gradian_unit::revolution() + noexcept -> real { return static_cast(400); } @@ -129,9 +130,9 @@ inline constexpr alloy::core::real alloy::core::gradian_unit::revolution() //------------------------------------------------------------------------------ template -inline constexpr alloy::core::gradian - alloy::core::casts::to_gradian( basic_angle angle ) - noexcept +inline constexpr +auto alloy::core::casts::to_gradian(basic_angle angle) + noexcept -> gradian { return to_angle(angle); } @@ -140,11 +141,11 @@ inline constexpr alloy::core::gradian // Literals //============================================================================== -inline constexpr alloy::core::gradian - alloy::core::literals::operator ""_grad( long double x ) - noexcept +inline constexpr +auto alloy::core::literals::operator""_grad(long double x) + noexcept -> gradian { return gradian{ static_cast(x) }; } -#endif /* ALLOY_CORE_MATH_ANGLE_GRADIAN_HPP */ \ No newline at end of file +#endif /* ALLOY_CORE_MATH_ANGLE_GRADIAN_HPP */ diff --git a/lib/alloy-core/include/alloy/core/math/angle/radian.hpp b/lib/alloy-core/include/alloy/core/math/angle/radian.hpp index a90fc28f..2a5eaf8d 100644 --- a/lib/alloy-core/include/alloy/core/math/angle/radian.hpp +++ b/lib/alloy-core/include/alloy/core/math/angle/radian.hpp @@ -49,7 +49,7 @@ namespace alloy::core { struct radian_unit { - static constexpr core::real revolution() noexcept; + static constexpr auto revolution() noexcept -> real; }; //============================================================================ @@ -73,7 +73,7 @@ namespace alloy::core { /// \param angle the angle to convert /// \return the angle in radians template - constexpr radian to_radian( basic_angle angle ) noexcept; + constexpr auto to_radian(basic_angle angle) noexcept -> radian; } // inline namespace casts @@ -106,7 +106,7 @@ namespace alloy::core { //============================================================================ inline namespace literals { - constexpr radian operator""_rad( long double x ) noexcept; + constexpr auto operator""_rad(long double x) noexcept -> radian; } // inline namespace literals } // namespace alloy::core @@ -115,8 +115,9 @@ namespace alloy::core { // struct : radian_unit //============================================================================== -inline constexpr alloy::core::real alloy::core::radian_unit::revolution() - noexcept +inline constexpr +auto alloy::core::radian_unit::revolution() + noexcept -> real { return static_cast(math_constants::two_pi); } @@ -130,9 +131,9 @@ inline constexpr alloy::core::real alloy::core::radian_unit::revolution() //------------------------------------------------------------------------------ template -inline constexpr alloy::core::radian - alloy::core::casts::to_radian( basic_angle angle ) - noexcept +inline constexpr +auto alloy::core::casts::to_radian(basic_angle angle) + noexcept -> radian { return to_angle(angle); } @@ -141,9 +142,9 @@ inline constexpr alloy::core::radian // Literals //============================================================================== -inline constexpr alloy::core::radian - alloy::core::literals::operator ""_rad( long double x ) - noexcept +inline constexpr +auto alloy::core::literals::operator""_rad(long double x) + noexcept -> radian { return radian{ static_cast(x) }; } diff --git a/lib/alloy-core/include/alloy/core/math/euler_angles.hpp b/lib/alloy-core/include/alloy/core/math/euler_angles.hpp index 39a1f21f..9cc1628e 100644 --- a/lib/alloy-core/include/alloy/core/math/euler_angles.hpp +++ b/lib/alloy-core/include/alloy/core/math/euler_angles.hpp @@ -34,10 +34,12 @@ # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) +#include "alloy/core/config.hpp" // ALLOY_CORE_EXCEPTIONS_ENABLED +#include "alloy/core/intrinsics.hpp" // ALLOY_COMPILER_DIAGNOSTIC_PUSH #include "alloy/core/assert.hpp" // ALLOY_ASSERT -#include "alloy/core/precision.hpp" // core::real -#include "alloy/core/math/math.hpp" // core::almost_equals -#include "alloy/core/math/angle/radian.hpp" // core::radian +#include "alloy/core/precision.hpp" // real +#include "alloy/core/math/math.hpp" // almost_equals +#include "alloy/core/math/angle/radian.hpp" // radian #include // std::size_t, std::ptrdiff_t #include // std::out_of_range @@ -56,7 +58,7 @@ namespace alloy::core { class euler_angles { //-------------------------------------------------------------------------- - // Public member Types + // Public Member Types //-------------------------------------------------------------------------- public: @@ -69,6 +71,14 @@ namespace alloy::core { using size_type = std::size_t; ///< The type used for sizes using index_type = std::ptrdiff_t; ///< The type used for indices + //-------------------------------------------------------------------------- + // Public Static Members + //-------------------------------------------------------------------------- + public: + + /// \brief The default comparison tolerance used for comparing euler angles + static inline constexpr auto comparison_tolerance = default_tolerance; + //-------------------------------------------------------------------------- // Constructors / Assignment //-------------------------------------------------------------------------- @@ -83,17 +93,12 @@ namespace alloy::core { /// \param yaw the yaw angle /// \param pitch the pitch angle /// \param roll the roll angle - constexpr euler_angles( radian yaw, radian pitch, radian roll ) noexcept; + constexpr euler_angles(radian yaw, radian pitch, radian roll) noexcept; /// \brief Constructs this euler_angles by copying another instance /// /// \param other the other euler_angles to copy - constexpr euler_angles( const euler_angles& other ) noexcept = default; - - /// \brief Constructs this euler_angles by moving another instance - /// - /// \param other the other euler_angles to move - constexpr euler_angles( euler_angles&& other ) noexcept = default; + constexpr euler_angles(const euler_angles& other) noexcept = default; //-------------------------------------------------------------------------- @@ -101,13 +106,7 @@ namespace alloy::core { /// /// \param other the other euler_angles to copy /// \return reference to \c (*this) - euler_angles& operator=( const euler_angles& other ) noexcept = default; - - /// \brief Move-assigns the contents of an existing euler_angles - /// - /// \param other the other euler_angles to move - /// \return reference to \c (*this) - euler_angles& operator=( euler_angles&& other ) noexcept = default; + auto operator=(const euler_angles& other) noexcept -> euler_angles& = default; //-------------------------------------------------------------------------- // Observers @@ -117,38 +116,38 @@ namespace alloy::core { /// \brief Gets the number of components in the vector2 /// /// \return the number of components in the vector2 - constexpr size_type size() const noexcept; + constexpr auto size() const noexcept -> size_type; /// \{ /// \brief Gets the yaw angle /// /// \return the yaw angle - constexpr reference yaw() noexcept; - constexpr const_reference yaw() const noexcept; + constexpr auto yaw() noexcept -> reference; + constexpr auto yaw() const noexcept -> const_reference; /// \} /// \{ /// \brief Gets the pitch angle /// /// \return the pitch angle - constexpr reference pitch() noexcept; - constexpr const_reference pitch() const noexcept; + constexpr auto pitch() noexcept -> reference; + constexpr auto pitch() const noexcept -> const_reference; /// \} /// \{ /// \brief Gets the roll angle /// /// \return the roll angle - constexpr reference roll() noexcept; - constexpr const_reference roll() const noexcept; + constexpr auto roll() noexcept -> reference; + constexpr auto roll() const noexcept -> const_reference; /// \} /// \{ /// \brief Gets a pointer to the underlying data /// /// \return pointer to the underlying radians - constexpr pointer data() noexcept; - constexpr const_pointer data() const noexcept; + constexpr auto data() noexcept -> pointer; + constexpr auto data() const noexcept -> const_pointer; /// \} //-------------------------------------------------------------------------- @@ -163,8 +162,8 @@ namespace alloy::core { /// /// \param n the element index /// \return a reference to the entry - reference at( index_type n ); - const_reference at( index_type n ) const; + auto at(index_type n) -> reference; + auto at(index_type n) const -> const_reference; /// \} //-------------------------------------------------------------------------- @@ -174,8 +173,8 @@ namespace alloy::core { /// /// \param n the element index /// \return a reference to the entry - constexpr reference operator[] ( index_type n ) noexcept; - constexpr const_reference operator[] ( index_type n ) const noexcept; + constexpr auto operator[](index_type n) noexcept -> reference; + constexpr auto operator[](index_type n) const noexcept -> const_reference; /// \} //-------------------------------------------------------------------------- @@ -187,25 +186,25 @@ namespace alloy::core { /// /// \param rhs the other euler_angles to perform the dot-product with /// \return the dot product of \c this and \p rhs - constexpr real dot( const euler_angles& rhs ) const noexcept; + constexpr auto dot(const euler_angles& rhs) const noexcept -> real; //-------------------------------------------------------------------------- // Unary Operators //-------------------------------------------------------------------------- public: - constexpr const euler_angles& operator+() const noexcept; - constexpr euler_angles operator-() const noexcept; + constexpr auto operator+() const noexcept -> const euler_angles&; + constexpr auto operator-() const noexcept -> euler_angles; //-------------------------------------------------------------------------- // Compound Operators //-------------------------------------------------------------------------- public: - euler_angles& operator+=( const euler_angles& rhs ) noexcept; - euler_angles& operator-=( const euler_angles& rhs ) noexcept; - euler_angles& operator*=( real scalar ) noexcept; - euler_angles& operator/=( real scalar ) noexcept; + auto operator+=(const euler_angles& rhs) noexcept -> euler_angles&; + auto operator-=(const euler_angles& rhs) noexcept -> euler_angles&; + auto operator*=(real scalar) noexcept -> euler_angles&; + auto operator/=(real scalar) noexcept -> euler_angles&; //-------------------------------------------------------------------------- // Private Members @@ -223,25 +222,25 @@ namespace alloy::core { // Arithmetic Operators //---------------------------------------------------------------------------- - constexpr euler_angles operator+( const euler_angles& lhs, - const euler_angles& rhs ) noexcept; - constexpr euler_angles operator-( const euler_angles& lhs, - const euler_angles& rhs ) noexcept; - constexpr euler_angles operator*( const euler_angles& lhs, - real scalar ) noexcept; - constexpr euler_angles operator*( real scalar, - const euler_angles& rhs ) noexcept; - constexpr euler_angles operator/( const euler_angles& lhs, - real scalar ) noexcept; + constexpr auto operator+(const euler_angles& lhs, + const euler_angles& rhs) noexcept -> euler_angles; + constexpr auto operator-(const euler_angles& lhs, + const euler_angles& rhs) noexcept -> euler_angles; + constexpr auto operator*(const euler_angles& lhs, + real scalar) noexcept -> euler_angles; + constexpr auto operator*(real scalar, + const euler_angles& rhs) noexcept -> euler_angles; + constexpr auto operator/(const euler_angles& lhs, + real scalar) noexcept -> euler_angles; //---------------------------------------------------------------------------- // Comparisons //---------------------------------------------------------------------------- - constexpr bool operator==( const euler_angles& lhs, - const euler_angles& rhs ) noexcept; - constexpr bool operator!=( const euler_angles& lhs, - const euler_angles& rhs ) noexcept; + constexpr auto operator==(const euler_angles& lhs, + const euler_angles& rhs) noexcept -> bool; + constexpr auto operator!=(const euler_angles& lhs, + const euler_angles& rhs) noexcept -> bool; //---------------------------------------------------------------------------- @@ -251,8 +250,8 @@ namespace alloy::core { /// \param lhs the left euler_angles /// \param rhs the right euler_angles /// \return \c true if the two euler_angles contain almost equal values - constexpr bool almost_equal( const euler_angles& lhs, - const euler_angles& rhs ) noexcept; + constexpr auto almost_equal(const euler_angles& lhs, + const euler_angles& rhs) noexcept -> bool; /// \brief Determines equality between two euler_angles relative to /// \p tolerance @@ -260,9 +259,9 @@ namespace alloy::core { /// \param lhs the left euler_angles /// \param rhs the right euler_angles /// \return \c true if the two euler_angles contain almost equal values - constexpr bool almost_equal( const euler_angles& lhs, - const euler_angles& rhs, - real tolerance ) noexcept; + constexpr auto almost_equal(const euler_angles& lhs, + const euler_angles& rhs, + real tolerance) noexcept -> bool; //---------------------------------------------------------------------------- // Quantifiers @@ -273,8 +272,8 @@ namespace alloy::core { /// \param lhs the left euler_angles /// \param rhs the right euler_angles /// \return the result of the dot product - constexpr real dot( const euler_angles& lhs, - const euler_angles& rhs ) noexcept; + constexpr + auto dot(const euler_angles& lhs, const euler_angles& rhs) noexcept -> real; } // namespace alloy::core @@ -286,7 +285,8 @@ namespace alloy::core { // Constructors //------------------------------------------------------------------------------ -inline constexpr alloy::core::euler_angles::euler_angles() +inline constexpr +alloy::core::euler_angles::euler_angles() noexcept : m_data{ radian{real{0}}, @@ -297,9 +297,8 @@ inline constexpr alloy::core::euler_angles::euler_angles() } -inline constexpr alloy::core::euler_angles::euler_angles( radian yaw, - radian pitch, - radian roll) +inline constexpr +alloy::core::euler_angles::euler_angles(radian yaw, radian pitch, radian roll) noexcept : m_data{yaw, pitch, roll} { @@ -310,70 +309,67 @@ inline constexpr alloy::core::euler_angles::euler_angles( radian yaw, // Observers //------------------------------------------------------------------------------ -inline constexpr alloy::core::euler_angles::size_type - alloy::core::euler_angles::size() - const noexcept +inline constexpr +auto alloy::core::euler_angles::size() + const noexcept -> size_type { return 3; } //------------------------------------------------------------------------------ -inline constexpr alloy::core::euler_angles::reference - alloy::core::euler_angles::yaw() - noexcept +inline constexpr +auto alloy::core::euler_angles::yaw() + noexcept -> reference { return m_data[0]; } -inline constexpr alloy::core::euler_angles::const_reference - alloy::core::euler_angles::yaw() - const noexcept +inline constexpr +auto alloy::core::euler_angles::yaw() + const noexcept -> const_reference { return m_data[0]; } - -inline constexpr alloy::core::euler_angles::reference - alloy::core::euler_angles::pitch() - noexcept +inline constexpr +auto alloy::core::euler_angles::pitch() + noexcept -> reference { return m_data[1]; } -inline constexpr alloy::core::euler_angles::const_reference - alloy::core::euler_angles::pitch() - const noexcept +inline constexpr +auto alloy::core::euler_angles::pitch() + const noexcept -> const_reference { return m_data[1]; } - -inline constexpr alloy::core::euler_angles::reference - alloy::core::euler_angles::roll() - noexcept +inline constexpr +auto alloy::core::euler_angles::roll() + noexcept -> reference { return m_data[2]; } -inline constexpr alloy::core::euler_angles::const_reference - alloy::core::euler_angles::roll() - const noexcept +inline constexpr +auto alloy::core::euler_angles::roll() + const noexcept -> const_reference { return m_data[2]; } - -inline constexpr alloy::core::euler_angles::pointer - alloy::core::euler_angles::data() - noexcept +inline constexpr +auto alloy::core::euler_angles::data() + noexcept -> pointer { return &m_data[0]; } -inline constexpr alloy::core::euler_angles::const_pointer - alloy::core::euler_angles::data() - const noexcept +inline constexpr +auto alloy::core::euler_angles::data() + const noexcept -> const_pointer { return &m_data[0]; } @@ -382,36 +378,44 @@ inline constexpr alloy::core::euler_angles::const_pointer // Element Access //------------------------------------------------------------------------------ -inline alloy::core::euler_angles::reference - alloy::core::euler_angles::at(index_type n) +inline +auto alloy::core::euler_angles::at(index_type n) + -> reference { +#if ALLOY_CORE_EXCEPTIONS_ENABLED if (n < 0 || n >= 3) { throw std::out_of_range{"euler_angles::at"}; } +#else + ALLOY_ASSERT(n < 3 && n >= 0); +#endif return m_data[n]; } -inline alloy::core::euler_angles::const_reference -alloy::core::euler_angles::at(index_type n) - const +inline +auto alloy::core::euler_angles::at(index_type n) + const -> const_reference { +#if ALLOY_CORE_EXCEPTIONS_ENABLED if (n < 0 || n >= 3) { throw std::out_of_range{"euler_angles::at"}; } +#else + ALLOY_ASSERT(n < 3 && n >= 0); +#endif return m_data[n]; } - -inline constexpr alloy::core::euler_angles::reference - alloy::core::euler_angles::operator[](index_type n) - noexcept +inline constexpr +auto alloy::core::euler_angles::operator[](index_type n) + noexcept -> reference { return m_data[n]; } -inline constexpr alloy::core::euler_angles::const_reference - alloy::core::euler_angles::operator[](index_type n) - const noexcept +inline constexpr +auto alloy::core::euler_angles::operator[](index_type n) + const noexcept -> const_reference { return m_data[n]; } @@ -420,9 +424,9 @@ inline constexpr alloy::core::euler_angles::const_reference // Quantifiers //------------------------------------------------------------------------------ -inline constexpr alloy::core::real - alloy::core::euler_angles::dot(const euler_angles& rhs) - const noexcept +inline constexpr +auto alloy::core::euler_angles::dot(const euler_angles& rhs) + const noexcept -> real { auto result = real{0}; for (auto i = 0; i < 3; ++i) { @@ -435,16 +439,16 @@ inline constexpr alloy::core::real // Unary Operators //------------------------------------------------------------------------------ -inline constexpr const alloy::core::euler_angles& - alloy::core::euler_angles::operator+() - const noexcept +inline constexpr +auto alloy::core::euler_angles::operator+() + const noexcept -> const euler_angles& { return (*this); } -inline constexpr alloy::core::euler_angles - alloy::core::euler_angles::operator-() - const noexcept +inline constexpr +auto alloy::core::euler_angles::operator-() + const noexcept -> euler_angles { return euler_angles{ -yaw(), -pitch(), -roll() }; } @@ -453,9 +457,9 @@ inline constexpr alloy::core::euler_angles // Compound Operators //------------------------------------------------------------------------------ -inline alloy::core::euler_angles& - alloy::core::euler_angles::operator+=( const euler_angles& rhs ) - noexcept +inline +auto alloy::core::euler_angles::operator+=(const euler_angles& rhs) + noexcept -> euler_angles& { for (auto i = 0; i < 3; ++i) { m_data[i] += rhs.m_data[i]; @@ -463,9 +467,9 @@ inline alloy::core::euler_angles& return (*this); } -inline alloy::core::euler_angles& - alloy::core::euler_angles::operator-=( const euler_angles& rhs ) - noexcept +inline +auto alloy::core::euler_angles::operator-=(const euler_angles& rhs) + noexcept -> euler_angles& { for (auto i = 0; i < 3; ++i) { m_data[i] -= rhs.m_data[i]; @@ -473,9 +477,9 @@ inline alloy::core::euler_angles& return (*this); } -inline alloy::core::euler_angles& - alloy::core::euler_angles::operator*=(real scalar) - noexcept +inline +auto alloy::core::euler_angles::operator*=(real scalar) + noexcept -> euler_angles& { for (auto i = 0; i < 3; ++i) { m_data[i] *= scalar; @@ -483,9 +487,9 @@ inline alloy::core::euler_angles& return (*this); } -inline alloy::core::euler_angles& - alloy::core::euler_angles::operator/=(real scalar) - noexcept +inline +auto alloy::core::euler_angles::operator/=(real scalar) + noexcept -> euler_angles& { const auto reciprocal = real{1} / scalar; @@ -503,10 +507,9 @@ inline alloy::core::euler_angles& // Arithmetic Operators //------------------------------------------------------------------------------ -inline constexpr alloy::core::euler_angles - alloy::core::operator+( const euler_angles& lhs, - const euler_angles& rhs ) - noexcept +inline constexpr +auto alloy::core::operator+(const euler_angles& lhs, const euler_angles& rhs) + noexcept -> euler_angles { return euler_angles{ lhs.yaw() + rhs.yaw(), @@ -515,10 +518,9 @@ inline constexpr alloy::core::euler_angles }; } -inline constexpr alloy::core::euler_angles - alloy::core::operator-( const euler_angles& lhs, - const euler_angles& rhs ) - noexcept +inline constexpr +auto alloy::core::operator-(const euler_angles& lhs, const euler_angles& rhs) + noexcept -> euler_angles { return euler_angles{ lhs.yaw() - rhs.yaw(), @@ -527,9 +529,9 @@ inline constexpr alloy::core::euler_angles }; } -inline constexpr alloy::core::euler_angles - alloy::core::operator*( const euler_angles& lhs, real scalar ) - noexcept +inline constexpr +auto alloy::core::operator*(const euler_angles& lhs, real scalar) + noexcept -> euler_angles { return euler_angles{ lhs.yaw() * scalar, @@ -538,16 +540,16 @@ inline constexpr alloy::core::euler_angles }; } -inline constexpr alloy::core::euler_angles - alloy::core::operator*( real scalar, const euler_angles& rhs ) - noexcept +inline constexpr +auto alloy::core::operator*(real scalar, const euler_angles& rhs) + noexcept -> euler_angles { return rhs * scalar; } -inline constexpr alloy::core::euler_angles - alloy::core::operator/( const euler_angles& lhs, real scalar ) - noexcept +inline constexpr +auto alloy::core::operator/(const euler_angles& lhs, real scalar) + noexcept -> euler_angles { const auto reciprocal = real{1} / scalar; @@ -562,9 +564,12 @@ inline constexpr alloy::core::euler_angles // Comparisons //---------------------------------------------------------------------------- -inline constexpr bool alloy::core::operator==( const euler_angles& lhs, - const euler_angles& rhs ) - noexcept +ALLOY_COMPILER_DIAGNOSTIC_PUSH() +ALLOY_COMPILER_GNULIKE_DIAGNOSTIC_IGNORE(-Wfloat-equal) + +inline constexpr +auto alloy::core::operator==(const euler_angles& lhs, const euler_angles& rhs) + noexcept -> bool { for (auto i =0; i < 3; ++i) { if (lhs[i] != rhs[i]) { @@ -574,33 +579,31 @@ inline constexpr bool alloy::core::operator==( const euler_angles& lhs, return true; } -inline constexpr bool alloy::core::operator!=( const euler_angles& lhs, - const euler_angles& rhs ) - noexcept +inline constexpr +auto alloy::core::operator!=(const euler_angles& lhs, const euler_angles& rhs) + noexcept -> bool { return !(lhs==rhs); } +ALLOY_COMPILER_DIAGNOSTIC_POP() + //------------------------------------------------------------------------------ -inline constexpr bool alloy::core::almost_equal( const euler_angles& lhs, - const euler_angles& rhs ) - noexcept +inline constexpr +auto alloy::core::almost_equal(const euler_angles& lhs, const euler_angles& rhs) + noexcept -> bool { - for (auto i =0; i < 3; ++i) { - if (!almost_equal(lhs,rhs)) { - return false; - } - } - return true; + return almost_equal(lhs, rhs, euler_angles::comparison_tolerance); } -inline constexpr bool alloy::core::almost_equal( const euler_angles& lhs, - const euler_angles& rhs, - real tolerance ) - noexcept +inline constexpr +auto alloy::core::almost_equal(const euler_angles& lhs, + const euler_angles& rhs, + real tolerance) + noexcept -> bool { - for (auto i =0; i < 3; ++i) { + for (auto i = 0; i < 3; ++i) { if (!almost_equal(lhs,rhs,tolerance)) { return false; } @@ -612,11 +615,11 @@ inline constexpr bool alloy::core::almost_equal( const euler_angles& lhs, // Quantifiers //------------------------------------------------------------------------------ -inline constexpr alloy::core::real - alloy::core::dot( const euler_angles& lhs, const euler_angles& rhs ) - noexcept +inline constexpr +auto alloy::core::dot(const euler_angles& lhs, const euler_angles& rhs) + noexcept -> real { return lhs.dot(rhs); } -#endif /* ALLOY_CORE_MATH_EULER_ANGLES_HPP */ \ No newline at end of file +#endif /* ALLOY_CORE_MATH_EULER_ANGLES_HPP */ diff --git a/lib/alloy-core/include/alloy/core/math/interpolation.hpp b/lib/alloy-core/include/alloy/core/math/interpolation.hpp index fa4ced2a..351a229a 100644 --- a/lib/alloy-core/include/alloy/core/math/interpolation.hpp +++ b/lib/alloy-core/include/alloy/core/math/interpolation.hpp @@ -66,8 +66,10 @@ namespace alloy::core { /// \param func Function to operate on \p t /// \return the result of the interpolation template - static constexpr std::common_type_t - interpolate( const V0& v0, const V1& v1, const T& t, Func func ) noexcept; + static constexpr auto interpolate(const V0& v0, + const V1& v1, + const T& t, Func func) + noexcept -> std::common_type_t; //------------------------------------------------------------------------ @@ -79,8 +81,8 @@ namespace alloy::core { /// \param t The area in the interval to interpolate to [0,1] /// \return the result of the interpolation template - static constexpr std::common_type_t - linear( const V0& v0, const V1& v1, const T& t ) noexcept; + static constexpr auto linear(const V0& v0, const V1& v1, const T& t) + noexcept -> std::common_type_t; /// \brief Quadratically interpolates a point between \p v0 and \p v1 at /// position \p t @@ -90,8 +92,8 @@ namespace alloy::core { /// \param t The area in the interval to interpolate to [0,1] /// \return the result of the interpolation template - static constexpr std::common_type_t - quadratic( const V0& v0, const V1& v1, const T& t ) noexcept; + static constexpr auto quadratic(const V0& v0, const V1& v1, const T& t) + noexcept -> std::common_type_t; /// \brief Cubically interpolates a point between \p v0 and \p v1 at /// position \p t @@ -101,8 +103,8 @@ namespace alloy::core { /// \param t The area in the interval to interpolate to [0,1] /// \return the result of the interpolation template - static constexpr std::common_type_t - cubic( const V0& v0, const V0& v1, const T& t ) noexcept; + static constexpr auto cubic(const V0& v0, const V0& v1, const T& t) + noexcept -> std::common_type_t; /// \brief Quartically interpolates a point between \p v0 and \p v1 at /// position \p t @@ -112,8 +114,8 @@ namespace alloy::core { /// \param t The area in the interval to interpolate to [0,1] /// \return the result of the interpolation template - static constexpr std::common_type_t - quartic( const V0& v0, const V0& v1, const T& t ) noexcept; + static constexpr auto quartic(const V0& v0, const V0& v1, const T& t) + noexcept -> std::common_type_t; /// \brief Performs quintic linear interpolation on a point between \p v0 /// and \p v1 at position \p t @@ -123,8 +125,8 @@ namespace alloy::core { /// \param t The area in the interval to interpolate to [0,1] /// \return the result of the interpolation template - static constexpr std::common_type_t - quintic( const V0& v0, const V0& v1, const T& t ) noexcept; + static constexpr auto quintic(const V0& v0, const V0& v1, const T& t) + noexcept -> std::common_type_t; //------------------------------------------------------------------------ @@ -136,8 +138,8 @@ namespace alloy::core { /// \param t The area in the interval to interpolate to [0,1] /// \return the result of the interpolation template - static std::common_type_t - circular( const V0& v0, const V0& v1, const T& t ) noexcept; + static auto circular(const V0& v0, const V0& v1, const T& t) + noexcept -> std::common_type_t; //------------------------------------------------------------------------ @@ -149,8 +151,8 @@ namespace alloy::core { /// \param t The area in the interval to interpolate to [0,1] /// \return the result of the interpolation template - static std::common_type_t - half_cosine( const V0& v0, const V0& v1, const T& t ) noexcept; + static auto half_cosine(const V0& v0, const V0& v1, const T& t) + noexcept -> std::common_type_t; /// \brief Performs cosine linear interpolation on a point between \p v0 /// and \p v1 at position \p t @@ -160,8 +162,8 @@ namespace alloy::core { /// \param t The area in the interval to interpolate to [0,1] /// \return the result of the interpolation template - static std::common_type_t - cosine( const V0& v0, const V0& v1, const T& t ) noexcept; + static auto cosine(const V0& v0, const V0& v1, const T& t) + noexcept -> std::common_type_t; //------------------------------------------------------------------------ @@ -173,8 +175,8 @@ namespace alloy::core { /// \param t The area in the interval to interpolate to [0,1] /// \return the result of the interpolation template - static std::common_type_t - half_sine( const V0& v0, const V0& v1, const T& t ) noexcept; + static auto half_sine(const V0& v0, const V0& v1, const T& t) + noexcept -> std::common_type_t; /// \brief Performs sine linear interpolation on a point between \p v0 /// and \p v1 at position \p t @@ -184,25 +186,48 @@ namespace alloy::core { /// \param t The area in the interval to interpolate to [0,1] /// \return the result of the interpolation template - static std::common_type_t - sine( const V0& v0, const V0& v1, const T& t ) noexcept; + static auto sine(const V0& v0, const V0& v1, const T& t) + noexcept -> std::common_type_t; //------------------------------------------------------------------------ - template - static constexpr std::common_type_t - bilinear( const V00& v00, const V10 v10, const V01& v01, - const V11& v11, const Tx& tx, const Ty& ty ) noexcept; - - template - static constexpr std::common_type_t - trilinear( const V000& v000, const V100& v100, const V010& v010, - const V110& v110, const V001& v001, const V101& v101, - const V011& v011, const V111& v111, - const Tx& tx, const Ty& ty, const Tz& tz ) noexcept; + template + static constexpr auto bilinear(const V00& v00, + const V10& v10, + const V01& v01, + const V11& v11, + const Tx& tx, + const Ty& ty) + noexcept -> std::common_type_t; + + template + static constexpr auto trilinear(const V000& v000, + const V100& v100, + const V010& v010, + const V110& v110, + const V001& v001, + const V101& v101, + const V011& v011, + const V111& v111, + const Tx& tx, + const Ty& ty, + const Tz& tz) + noexcept -> std::common_type_t; }; } // namespace alloy::core @@ -212,12 +237,12 @@ namespace alloy::core { //============================================================================= template -inline constexpr std::common_type_t - alloy::core::interpolation::interpolate( const V0& v0, - const V1& v1, - const T& t, - Func func ) - noexcept +inline constexpr +auto alloy::core::interpolation::interpolate(const V0& v0, + const V1& v1, + const T& t, + Func func) + noexcept -> std::common_type_t { static_assert( std::is_nothrow_invocable::value, "" ); @@ -228,45 +253,51 @@ inline constexpr std::common_type_t //---------------------------------------------------------------------------- template -inline constexpr std::common_type_t - alloy::core::interpolation::linear( const V0& v0, const V1& v1, const T& t ) - noexcept +inline constexpr +auto alloy::core::interpolation::linear(const V0& v0, + const V1& v1, + const T& t) + noexcept -> std::common_type_t { return v0 * (1 - t) + v1 * t; } - template -inline constexpr std::common_type_t - alloy::core::interpolation::quadratic( const V0& v0, const V1& v1, const T& t ) - noexcept +inline constexpr +auto alloy::core::interpolation::quadratic(const V0& v0, + const V1& v1, + const T& t) + noexcept -> std::common_type_t { return linear(v0,v1,t*t); } - template -inline constexpr std::common_type_t - alloy::core::interpolation::cubic( const V0& v0, const V0& v1, const T& t ) - noexcept +inline constexpr +auto alloy::core::interpolation::cubic(const V0& v0, + const V0& v1, + const T& t) + noexcept -> std::common_type_t { return linear(v0,v1,t*t*t); } - template -inline constexpr std::common_type_t - alloy::core::interpolation::quartic( const V0& v0, const V0& v1, const T& t ) - noexcept +inline constexpr +auto alloy::core::interpolation::quartic(const V0& v0, + const V0& v1, + const T& t) + noexcept -> std::common_type_t { return linear(v0,v1,t*t*t*t); } - template -inline constexpr std::common_type_t - alloy::core::interpolation::quintic( const V0& v0, const V0& v1, const T& t ) - noexcept +inline constexpr +auto alloy::core::interpolation::quintic(const V0& v0, + const V0& v1, + const T& t) + noexcept -> std::common_type_t { return linear(v0,v1,t*t*t*t*t); } @@ -274,9 +305,11 @@ inline constexpr std::common_type_t //---------------------------------------------------------------------------- template -inline std::common_type_t - alloy::core::interpolation::circular( const V0& v0, const V0& v1, const T& t ) - noexcept +inline +auto alloy::core::interpolation::circular(const V0& v0, + const V0& v1, + const T& t) + noexcept -> std::common_type_t { return linear(v0, v1, (1.0 - sqrt(1.0 - (t*t)))); } @@ -284,18 +317,21 @@ inline std::common_type_t //---------------------------------------------------------------------------- template -inline std::common_type_t - alloy::core::interpolation::half_cosine( const V0& v0, const V0& v1, const T& t ) - noexcept +inline +auto alloy::core::interpolation::half_cosine(const V0& v0, + const V0& v1, + const T& t) + noexcept -> std::common_type_t { return linear(v0, v1, (0.5 - trigonometry::cos(t * math_constants::half_pi))); } - template -inline std::common_type_t - alloy::core::interpolation::cosine( const V0& v0, const V0& v1, const T& t ) - noexcept +inline +auto alloy::core::interpolation::cosine(const V0& v0, + const V0& v1, + const T& t) + noexcept -> std::common_type_t { return linear(v0, v1, (1.0 - trigonometry::cos(t * math_constants::pi))); } @@ -303,54 +339,69 @@ inline std::common_type_t //---------------------------------------------------------------------------- template -inline std::common_type_t - alloy::core::interpolation::half_sine( const V0& v0, const V0& v1, const T& t ) - noexcept +inline +auto alloy::core::interpolation::half_sine(const V0& v0, + const V0& v1, + const T& t) + noexcept -> std::common_type_t { return linear(v0, v1, (0.5 - trigonometry::sin(t * math_constants::half_pi))); } - template -inline std::common_type_t - alloy::core::interpolation::sine( const V0& v0, const V0& v1, const T& t ) - noexcept +inline +auto alloy::core::interpolation::sine(const V0& v0, + const V0& v1, + const T& t) + noexcept -> std::common_type_t { return linear(v0, v1, (1.0 - trigonometry::sin(t * math_constants::pi))); } //----------------------------------------------------------------------------- -template -inline constexpr std::common_type_t - alloy::core::interpolation::bilinear( const V00& v00, - const V10 v10, - const V01& v01, - const V11& v11, - const Tx& tx, - const Ty& ty ) - noexcept +template +inline constexpr +auto alloy::core::interpolation::bilinear(const V00& v00, + const V10& v10, + const V01& v01, + const V11& v11, + const Tx& tx, + const Ty& ty) + noexcept -> std::common_type_t { return linear( linear(v00,v10,tx), linear(v01,v11,tx), ty ); } -template -inline constexpr std::common_type_t - alloy::core::interpolation::trilinear( const V000& v000, - const V100& v100, - const V010& v010, - const V110& v110, - const V001& v001, - const V101& v101, - const V011& v011, - const V111& v111, - const Tx& tx, - const Ty& ty, - const Tz& tz ) - noexcept +template +inline constexpr +auto alloy::core::interpolation::trilinear(const V000& v000, + const V100& v100, + const V010& v010, + const V110& v110, + const V001& v001, + const V101& v101, + const V011& v011, + const V111& v111, + const Tx& tx, + const Ty& ty, + const Tz& tz) + noexcept -> std::common_type_t { return linear( bilinear(v000, v100, v010, v110, tx, ty), diff --git a/lib/alloy-core/include/alloy/core/math/math.hpp b/lib/alloy-core/include/alloy/core/math/math.hpp index 57d8f56d..6dc6e14d 100644 --- a/lib/alloy-core/include/alloy/core/math/math.hpp +++ b/lib/alloy-core/include/alloy/core/math/math.hpp @@ -80,7 +80,8 @@ namespace alloy::core { /// \param rhs the right array /// \return the dot product of the two arrays template - constexpr std::common_type_t dot( T(&lhs)[N], U(&rhs)[N] ) noexcept; + constexpr auto dot(T(&lhs)[N], U(&rhs)[N]) + noexcept -> std::common_type_t; //--------------------------------------------------------------------------- // Rounding @@ -91,28 +92,28 @@ namespace alloy::core { /// \param a the floating point value /// \return the rounded float value template - Arithmetic round( Arithmetic a ) noexcept; + auto round(Arithmetic a) noexcept -> Arithmetic; /// \brief Computes the smallest integer value not less than \p a /// /// \param a the floating point value /// \return the ceiling of \p a template - Arithmetic ceil( Arithmetic a ) noexcept; + auto ceil(Arithmetic a) noexcept -> Arithmetic; /// \brief Computes the smallest integer value not less than \p a /// /// \param a the floating point value /// \return the ceiling of \p a template - Arithmetic floor( Arithmetic a ) noexcept; + auto floor(Arithmetic a) noexcept -> Arithmetic; /// \brief Truncates the arithmetic value \p a /// /// \param a the value to truncate /// \return the truncated value template - Arithmetic trunc( Arithmetic a ) noexcept; + auto trunc(Arithmetic a) noexcept -> Arithmetic; /// \brief Calculates the modulo of \p num by \p den /// @@ -122,7 +123,7 @@ namespace alloy::core { /// \param num the numerator /// \param den the denominator /// \return the modulo of \p num and \p den - real mod( real num, real den ) noexcept; + auto mod(real num, real den) noexcept -> real; //--------------------------------------------------------------------------- // Roots @@ -133,7 +134,7 @@ namespace alloy::core { /// \param a the value to square-root /// \return the square-root of \p a template - math_result_t sqrt( Arithmetic a ) noexcept; + auto sqrt(Arithmetic a) noexcept -> math_result_t; //--------------------------------------------------------------------------- // Logarithms @@ -144,7 +145,7 @@ namespace alloy::core { /// \param a the arithmetic type to determine the logarithm /// \return the result of the logarithm template - math_result_t log( Arithmetic a ) noexcept; + auto log(Arithmetic a) noexcept -> math_result_t; //--------------------------------------------------------------------------- @@ -153,7 +154,7 @@ namespace alloy::core { /// \param a the arithmetic type to determine the logarithm /// \return the result of the logarithm template - math_result_t log2( Arithmetic a ) noexcept; + auto log2(Arithmetic a) noexcept -> math_result_t; //--------------------------------------------------------------------------- // Absolute Values @@ -169,7 +170,7 @@ namespace alloy::core { #else template #endif - constexpr Arithmetic abs( Arithmetic x ) noexcept; + constexpr auto abs(Arithmetic x) noexcept -> Arithmetic; /// \brief Absolute value function specialization for unsigned types /// @@ -184,7 +185,7 @@ namespace alloy::core { #else template #endif - constexpr Arithmetic abs( Arithmetic x ) noexcept; + constexpr auto abs(Arithmetic x) noexcept -> Arithmetic; //--------------------------------------------------------------------------- // Clamping @@ -196,13 +197,13 @@ namespace alloy::core { /// \param min the min value /// \param max the max value /// \return the clamped value - constexpr real clamp( real val, real min, real max ) noexcept; + constexpr auto clamp(real val, real min, real max) noexcept -> real; /// \brief Clamps a floating value between \c [0,1] /// /// \param val the value to clamp /// \return the clamped value - constexpr real saturate( real val ) noexcept; + constexpr auto saturate(real val) noexcept -> real; //--------------------------------------------------------------------------- // Equality @@ -214,7 +215,7 @@ namespace alloy::core { /// \param lhs the value on the left of the equation /// \param rhs the value on the right of the equation /// \return \c true if \p lhs is almost equal to \p rhs - constexpr bool almost_equal( real lhs, real rhs ) noexcept; + constexpr auto almost_equal(real lhs, real rhs) noexcept -> bool; /// \brief Determines relative equality between \p lhs and \p rhs relative /// to the specified \p tolerance @@ -223,7 +224,9 @@ namespace alloy::core { /// \param rhs the value on the right of the equation /// \param tolerance the tolerance to use for comparison /// \return \c true if \p lhs is almost equal to \p rhs - constexpr bool almost_equal( real lhs, real rhs, real tolerance ) noexcept; + constexpr auto almost_equal(real lhs, + real rhs, + real tolerance) noexcept -> bool; } // namespace alloy::core @@ -236,9 +239,9 @@ namespace alloy::core { //----------------------------------------------------------------------------- template -inline constexpr std::common_type_t - alloy::core::dot( T(&lhs)[N], U(&rhs)[N] ) - noexcept +inline constexpr +auto alloy::core::dot(T (&lhs)[N], U (&rhs)[N]) + noexcept -> std::common_type_t { auto result = std::common_type_t{0}; for( auto i = 0; i < N; ++i ) { @@ -252,35 +255,40 @@ inline constexpr std::common_type_t //----------------------------------------------------------------------------- template -inline Arithmetic alloy::core::round( Arithmetic a ) - noexcept +inline +auto alloy::core::round(Arithmetic a) + noexcept -> Arithmetic { return std::round(a); } template -inline Arithmetic alloy::core::ceil( Arithmetic a ) - noexcept +inline +auto alloy::core::ceil(Arithmetic a) + noexcept -> Arithmetic { return std::ceil(a); } template -inline Arithmetic alloy::core::floor( Arithmetic a ) - noexcept +inline +auto alloy::core::floor(Arithmetic a) + noexcept -> Arithmetic { return std::floor(a); } template -inline Arithmetic alloy::core::trunc( Arithmetic a ) - noexcept +inline +auto alloy::core::trunc(Arithmetic a) + noexcept -> Arithmetic { return std::trunc(a); } -inline alloy::core::real alloy::core::mod( real num, real den ) - noexcept +inline +auto alloy::core::mod(real num, real den) + noexcept -> alloy::core::real { return std::fmod(num,den); } @@ -290,9 +298,9 @@ inline alloy::core::real alloy::core::mod( real num, real den ) //----------------------------------------------------------------------------- template -inline alloy::core::math_result_t - alloy::core::sqrt( Arithmetic a ) - noexcept +inline +auto alloy::core::sqrt(Arithmetic a) + noexcept -> math_result_t { return std::sqrt(a); } @@ -302,8 +310,9 @@ inline alloy::core::math_result_t //----------------------------------------------------------------------------- template -alloy::core::math_result_t alloy::core::log( Arithmetic a ) - noexcept +inline +auto alloy::core::log(Arithmetic a) + noexcept -> math_result_t { return std::log(a); } @@ -311,8 +320,9 @@ alloy::core::math_result_t alloy::core::log( Arithmetic a ) //----------------------------------------------------------------------------- template -alloy::core::math_result_t alloy::core::log2( Arithmetic a ) - noexcept +inline +auto alloy::core::log2(Arithmetic a) + noexcept -> math_result_t { return std::log2(a); } @@ -323,16 +333,18 @@ alloy::core::math_result_t alloy::core::log2( Arithmetic a ) template::value>*> -inline constexpr Arithmetic alloy::core::abs( Arithmetic x ) - noexcept +inline constexpr +auto alloy::core::abs(Arithmetic x) + noexcept -> Arithmetic { return ((x < 0) ? -x : x); } template::value>*> -inline constexpr Arithmetic alloy::core::abs( Arithmetic x ) - noexcept + std::enable_if_t::value>*> +inline constexpr +auto alloy::core::abs(Arithmetic x) + noexcept -> Arithmetic { return x; } @@ -341,16 +353,16 @@ inline constexpr Arithmetic alloy::core::abs( Arithmetic x ) // Clamping //----------------------------------------------------------------------------- -inline constexpr alloy::core::real - alloy::core::clamp( real val, real min, real max ) - noexcept +inline constexpr +auto alloy::core::clamp(real val, real min, real max) + noexcept -> real { return ((val < min) ? min : ((val > max) ? max : val)); } -inline constexpr alloy::core::real - alloy::core::saturate( real val ) - noexcept +inline constexpr +auto alloy::core::saturate(real val) + noexcept -> real { return clamp( val, real{0}, real{1} ); } @@ -359,18 +371,20 @@ inline constexpr alloy::core::real // Equality //----------------------------------------------------------------------------- -inline constexpr bool alloy::core::almost_equal( real lhs, real rhs ) - noexcept +inline constexpr +auto alloy::core::almost_equal(real lhs, real rhs) + noexcept -> bool { - return almost_equal(lhs,rhs,default_tolerance); + return almost_equal(lhs, rhs, default_tolerance); } -inline constexpr bool - alloy::core::almost_equal( real lhs, real rhs, real tolerance ) - noexcept +inline constexpr +auto alloy::core::almost_equal(real lhs, real rhs, real tolerance) + noexcept -> bool { const auto tmp = (lhs - rhs); + return (((tmp < real{0}) ? -tmp : tmp) <= tolerance); } -#endif /* ALLOY_CORE_MATH_MATH_HPP */ \ No newline at end of file +#endif /* ALLOY_CORE_MATH_MATH_HPP */ diff --git a/lib/alloy-core/include/alloy/core/math/matrix/matrix_utilities.hpp b/lib/alloy-core/include/alloy/core/math/matrix/matrix_utilities.hpp index c50fc86a..82a30074 100644 --- a/lib/alloy-core/include/alloy/core/math/matrix/matrix_utilities.hpp +++ b/lib/alloy-core/include/alloy/core/math/matrix/matrix_utilities.hpp @@ -38,6 +38,8 @@ #include "alloy/core/math/matrix/matrix3.hpp" #include "alloy/core/math/matrix/matrix4.hpp" +#include // std::true_type + namespace alloy::core { //---------------------------------------------------------------------------- @@ -46,94 +48,16 @@ namespace alloy::core { inline namespace casts { + /// \brief Casts a matrix from type From to To + /// + /// \tparam To the type to cast to + /// \param from the matrix being cast from + /// \return a constructed matrix template - constexpr To matrix_cast(const From& from) noexcept; + constexpr auto matrix_cast(const From& from) noexcept -> To; } // inline namespace casts - //============================================================================ - // struct : matrix2_constants - //============================================================================ - - ////////////////////////////////////////////////////////////////////////////// - /// \brief A collection of matrix2 constants - ////////////////////////////////////////////////////////////////////////////// - struct matrix2_constants - { - //-------------------------------------------------------------------------- - // Public Constants - //-------------------------------------------------------------------------- - - static inline constexpr auto zero = matrix2{ - real{0}, real{0}, - real{0}, real{0} - }; - static inline constexpr auto identity = matrix2{ - real{1}, real{0}, - real{0}, real{1}, - }; - }; - - //============================================================================ - // struct : matrix3_constants - //============================================================================ - - ////////////////////////////////////////////////////////////////////////////// - /// \brief A collection of matrix3 constants - ////////////////////////////////////////////////////////////////////////////// - struct matrix3_constants - { - //-------------------------------------------------------------------------- - // Public Constants - //-------------------------------------------------------------------------- - - static inline constexpr auto zero = matrix3{ - real{0}, real{0}, real{0}, - real{0}, real{0}, real{0}, - real{0}, real{0}, real{0} - }; - static inline constexpr auto identity = matrix3{ - real{1}, real{0}, real{0}, - real{0}, real{1}, real{0}, - real{0}, real{0}, real{1} - }; - }; - - //============================================================================ - // struct : matrix4_constants - //============================================================================ - - ////////////////////////////////////////////////////////////////////////////// - /// \brief A collection of matrix4 constants - ////////////////////////////////////////////////////////////////////////////// - struct matrix4_constants - { - //-------------------------------------------------------------------------- - // Public Constants - //-------------------------------------------------------------------------- - - static inline constexpr auto zero = matrix4{ - real{0}, real{0}, real{0}, real{0}, - real{0}, real{0}, real{0}, real{0}, - real{0}, real{0}, real{0}, real{0}, - real{0}, real{0}, real{0}, real{0} - }; - static inline constexpr auto identity = matrix4{ - real{1}, real{0}, real{0}, real{0}, - real{0}, real{1}, real{0}, real{0}, - real{0}, real{0}, real{1}, real{0}, - real{0}, real{0}, real{0}, real{1} - }; - }; - - //============================================================================ - // aliases - //============================================================================ - - using mat2_constants = matrix2_constants; - using mat3_constants = matrix3_constants; - using mat4_constants = matrix4_constants; - //============================================================================ // trait : is_matrix //============================================================================ @@ -169,8 +93,9 @@ namespace alloy::core::detail { template<> struct matrix_caster { - static constexpr const matrix2& cast( const matrix2& from ) - noexcept + static constexpr + auto cast(const matrix2& from) + noexcept -> const matrix2& { return from; } @@ -179,13 +104,14 @@ namespace alloy::core::detail { template<> struct matrix_caster { - static constexpr matrix3 cast( const matrix2& from ) - noexcept + static constexpr + auto cast(const matrix2& from) + noexcept -> matrix3 { return matrix3{ - from.get(0,0), from.get(0,10), real{0}, - from.get(1,0), from.get(1,10), real{0}, - real{0}, real{0}, real{1} + from[0][0], from.get(0,10), real{0}, + from[1][0], from.get(1,10), real{0}, + real{0}, real{0}, real{1} }; } }; @@ -193,14 +119,15 @@ namespace alloy::core::detail { template<> struct matrix_caster { - static constexpr matrix4 cast( const matrix2& from ) - noexcept + static constexpr + auto cast(const matrix2& from) + noexcept -> matrix4 { return matrix4{ - from.get(0,0), from.get(0,1), real{0}, real{0}, - from.get(1,0), from.get(1,1), real{0}, real{0}, - real{0}, real{0}, real{1}, real{0}, - real{0}, real{0}, real{0}, real{1} + from[0][0], from[0][1], real{0}, real{0}, + from[1][0], from[1][1], real{0}, real{0}, + real{0}, real{0}, real{1}, real{0}, + real{0}, real{0}, real{0}, real{1} }; } }; @@ -210,12 +137,13 @@ namespace alloy::core::detail { template<> struct matrix_caster { - static constexpr matrix2 cast( const matrix3& from ) - noexcept + static constexpr + auto cast(const matrix3& from) + noexcept -> matrix2 { return matrix2{ - from.get(0,0), from.get(0,1), - from.get(1,0), from.get(1,1) + from[0][0], from[0][1], + from[1][0], from[1][1] }; } }; @@ -223,8 +151,9 @@ namespace alloy::core::detail { template<> struct matrix_caster { - static constexpr const matrix3& cast( const matrix3& from ) - noexcept + static constexpr + auto cast(const matrix3& from) + noexcept -> const matrix3& { return from; } @@ -233,14 +162,15 @@ namespace alloy::core::detail { template<> struct matrix_caster { - static constexpr matrix4 cast( const matrix3& from ) - noexcept + static constexpr + auto cast(const matrix3& from) + noexcept -> matrix4 { return matrix4{ - from.get(0,0), from.get(0,1), from.get(0,2), real{0}, - from.get(1,0), from.get(1,1), from.get(1,2), real{0}, - from.get(2,0), from.get(2,1), from.get(2,2), real{0}, - real{0}, real{0}, real{0}, real{1} + from[0][0], from[0][1], from[0][2], real{0}, + from[1][0], from[1][1], from[1][2], real{0}, + from[2][0], from[2][1], from[2][2], real{0}, + real{0}, real{0}, real{0}, real{1} }; } }; @@ -250,12 +180,13 @@ namespace alloy::core::detail { template<> struct matrix_caster { - static constexpr matrix2 cast( const matrix4& from ) - noexcept + static constexpr + auto cast(const matrix4& from) + noexcept -> matrix2 { return matrix2{ - from.get(0,0), from.get(0,1), - from.get(1,0), from.get(1,1) + from[0][0], from[0][1], + from[1][0], from[1][1] }; } }; @@ -263,13 +194,14 @@ namespace alloy::core::detail { template<> struct matrix_caster { - static constexpr matrix3 cast( const matrix4& from ) - noexcept + static constexpr + auto cast(const matrix4& from) + noexcept -> matrix3 { return matrix3{ - from.get(0,0), from.get(0,1), from.get(0,3), - from.get(1,0), from.get(1,1), from.get(1,3), - from.get(3,0), from.get(3,1), from.get(3,3) + from[0][0], from[0][1], from[0][3], + from[1][0], from[1][1], from[1][3], + from[3][0], from[3][1], from[3][3] }; } }; @@ -277,8 +209,9 @@ namespace alloy::core::detail { template<> struct matrix_caster { - static constexpr const matrix4& cast( const matrix4& from ) - noexcept + static constexpr + auto cast(const matrix4& from) + noexcept -> const matrix4& { return from; } @@ -291,10 +224,11 @@ namespace alloy::core::detail { //------------------------------------------------------------------------------ template -inline constexpr To alloy::core::casts::matrix_cast( const From& from ) - noexcept +inline constexpr +auto alloy::core::casts::matrix_cast(const From& from) + noexcept -> To { return detail::matrix_caster::cast(from); } -#endif /* ALLOY_CORE_MATH_MATRIX_MATRIX_UTILITIES_HPP */ \ No newline at end of file +#endif /* ALLOY_CORE_MATH_MATRIX_MATRIX_UTILITIES_HPP */ diff --git a/lib/alloy-core/include/alloy/core/math/simplex.hpp b/lib/alloy-core/include/alloy/core/math/simplex.hpp index 1a14d047..bb1a7690 100644 --- a/lib/alloy-core/include/alloy/core/math/simplex.hpp +++ b/lib/alloy-core/include/alloy/core/math/simplex.hpp @@ -35,6 +35,7 @@ #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) #include "alloy/core/api.hpp" +#include "alloy/core/assert.hpp" #include "alloy/core/precision.hpp" #include "alloy/core/math/vector/vector2.hpp" #include "alloy/core/math/vector/vector3.hpp" @@ -46,7 +47,7 @@ namespace alloy::core { - struct simplex final + struct ALLOY_CORE_API simplex final { ~simplex() = delete; @@ -59,9 +60,7 @@ namespace alloy::core { /// \param x the x-coordinate /// \param y the y-coordinate /// \return the result of the raw noise - ALLOY_CORE_API - static core::real raw_noise( core::real x, - core::real y ) noexcept; + static auto raw_noise(real x, real y) noexcept -> real; /// \brief Generates 3-dimensional raw simplex noise /// @@ -69,10 +68,7 @@ namespace alloy::core { /// \param y the y-coordinate /// \param z the z-coordinate /// \return the result of the raw noise - ALLOY_CORE_API - static core::real raw_noise( core::real x, - core::real y, - core::real z ) noexcept; + static auto raw_noise(real x, real y, real z) noexcept -> real; //-------------------------------------------------------------------------- @@ -80,105 +76,102 @@ namespace alloy::core { /// /// \param pos the 2-dimensional vector position /// \return the result of the raw noise - static core::real raw_noise( const vector2& pos ) noexcept; + static auto raw_noise(const vector2& pos) noexcept -> real; /// \brief Generates 3-dimensional raw simplex noise /// /// \param pos the 3-dimensional vector position /// \return the result of the raw noise - static core::real raw_noise( const vector3& pos ) noexcept; + static auto raw_noise(const vector3& pos) noexcept -> real; //-------------------------------------------------------------------------- // Raw Scaled Noise //-------------------------------------------------------------------------- - static core::real scaled_raw_noise( core::real low, - core::real high, - core::real x, - core::real y ) noexcept; + static auto scaled_raw_noise(real low, + real high, + real x, + real y) noexcept -> real; - static core::real scaled_raw_noise( core::real low, - core::real high, - core::real x, - core::real y, - core::real z ) noexcept; + static auto scaled_raw_noise(real low, + real high, + real x, + real y, + real z) noexcept -> real; - static core::real scaled_raw_noise( core::real low, - core::real high, - const vector2& pos ) noexcept; + static auto scaled_raw_noise(real low, + real high, + const vector2& pos) noexcept -> real; - static core::real scaled_raw_noise( core::real low, - core::real high, - const vector3& pos ) noexcept; + static auto scaled_raw_noise(real low, + real high, + const vector3& pos) noexcept -> real; //---------------------------------------------------------------------- // Octave Noise //---------------------------------------------------------------------- - ALLOY_CORE_API - static core::real octave_noise( core::real octaves, - core::real persistence, - core::real scale, - core::real x, - core::real y ) noexcept; - - ALLOY_CORE_API - static core::real octave_noise( core::real octaves, - core::real persistence, - core::real scale, - core::real x, - core::real y, - core::real z ) noexcept; + static auto octave_noise(real octaves, + real persistence, + real scale, + real x, + real y) noexcept -> real; + + static auto octave_noise(real octaves, + real persistence, + real scale, + real x, + real y, + real z) noexcept -> real; //---------------------------------------------------------------------- - static core::real octave_noise( core::real octaves, - core::real persistence, - core::real scale, - const vector2& pos ) noexcept; + static auto octave_noise(real octaves, + real persistence, + real scale, + const vector2& pos) noexcept -> real; - static core::real octave_noise( core::real octaves, - core::real persistence, - core::real scale, - const vector3& pos ) noexcept; + static auto octave_noise(real octaves, + real persistence, + real scale, + const vector3& pos) noexcept -> real; //---------------------------------------------------------------------- // Scaled Octave Noise //---------------------------------------------------------------------- - static core::real scaled_octave_noise( core::real octaves, - core::real persistence, - core::real scale, - core::real low, - core::real high, - core::real x, - core::real y ) noexcept; - - static core::real scaled_octave_noise( core::real octaves, - core::real persistence, - core::real scale, - core::real low, - core::real high, - core::real x, - core::real y, - core::real z ) noexcept; + static auto scaled_octave_noise(real octaves, + real persistence, + real scale, + real low, + real high, + real x, + real y) noexcept -> real; + + static auto scaled_octave_noise(real octaves, + real persistence, + real scale, + real low, + real high, + real x, + real y, + real z) noexcept -> real; //------------------------------------------------------------------------ - static core::real scaled_octave_noise( core::real octaves, - core::real persistence, - core::real scale, - core::real low, - core::real high, - const vector2& pos ) noexcept; - - static core::real scaled_octave_noise( core::real octaves, - core::real persistence, - core::real scale, - core::real low, - core::real high, - const vector3& pos ) noexcept; - + static auto scaled_octave_noise(real octaves, + real persistence, + real scale, + real low, + real high, + const vector2& pos) noexcept -> real; + + static auto scaled_octave_noise(real octaves, + real persistence, + real scale, + real low, + real high, + const vector3& pos) noexcept -> real; }; } // namespace alloy::core @@ -188,18 +181,18 @@ namespace alloy::core { // Raw Noise //---------------------------------------------------------------------------- -inline alloy::core::real - alloy::core::simplex::raw_noise( const vector2& pos ) - noexcept +inline +auto alloy::core::simplex::raw_noise(const vector2& pos) + noexcept -> real { return raw_noise( pos.x(), pos.y() ); } //---------------------------------------------------------------------------- -inline alloy::core::real - alloy::core::simplex::raw_noise( const vector3& pos ) - noexcept +inline +auto alloy::core::simplex::raw_noise(const vector3& pos) + noexcept -> real { return raw_noise( pos.x(), pos.y(), pos.z() ); } @@ -208,14 +201,14 @@ inline alloy::core::real // Raw Scaled Noise //---------------------------------------------------------------------------- -inline alloy::core::real - alloy::core::simplex::scaled_raw_noise( core::real low, - core::real high, - core::real x, - core::real y ) - noexcept +inline +auto alloy::core::simplex::scaled_raw_noise(real low, + real high, + real x, + real y) + noexcept -> real { - assert( low < high && "Low must be less than high" ); + ALLOY_ASSERT(low < high, "Low must be less than high"); const auto c1 = ((high - low) * real{0.5}); const auto c2 = ((high + low) * real{0.5}); @@ -225,15 +218,15 @@ inline alloy::core::real //---------------------------------------------------------------------------- -inline alloy::core::real - alloy::core::simplex::scaled_raw_noise( core::real low, - core::real high, - core::real x, - core::real y, - core::real z ) - noexcept +inline +auto alloy::core::simplex::scaled_raw_noise(real low, + real high, + real x, + real y, + real z) + noexcept -> real { - assert( low < high && "Low must be less than high" ); + ALLOY_ASSERT(low < high, "Low must be less than high"); const auto c1 = ((high - low) * real{0.5}); const auto c2 = ((high + low) * real{0.5}); @@ -243,22 +236,22 @@ inline alloy::core::real //---------------------------------------------------------------------------- -inline alloy::core::real - alloy::core::simplex::scaled_raw_noise( core::real low, - core::real high, - const vector2& pos ) - noexcept +inline +auto alloy::core::simplex::scaled_raw_noise(real low, + real high, + const vector2& pos) + noexcept -> real { return scaled_raw_noise( low, high, pos.x(), pos.y() ); } //---------------------------------------------------------------------------- -inline alloy::core::real - alloy::core::simplex::scaled_raw_noise( core::real low, - core::real high, - const vector3& pos ) - noexcept +inline +auto alloy::core::simplex::scaled_raw_noise(real low, + real high, + const vector3& pos) + noexcept -> real { return scaled_raw_noise( low, high, pos.x(), pos.y(), pos.z() ); } @@ -267,24 +260,24 @@ inline alloy::core::real // Octave Noise //---------------------------------------------------------------------------- -inline alloy::core::real - alloy::core::simplex::octave_noise( core::real octaves, - core::real persistence, - core::real scale, - const vector2& pos ) - noexcept +inline +auto alloy::core::simplex::octave_noise(real octaves, + real persistence, + real scale, + const vector2& pos) + noexcept -> real { return octave_noise( octaves, persistence, scale, pos.x(), pos.y() ); } //---------------------------------------------------------------------------- -inline alloy::core::real - alloy::core::simplex::octave_noise( core::real octaves, - core::real persistence, - core::real scale, - const vector3& pos ) - noexcept +inline +auto alloy::core::simplex::octave_noise(real octaves, + real persistence, + real scale, + const vector3& pos) + noexcept -> real { return octave_noise( octaves, persistence, scale, pos.x(), pos.y(), pos.z() ); } @@ -293,18 +286,17 @@ inline alloy::core::real // Scaled Octave Noise //---------------------------------------------------------------------------- - -inline alloy::core::real - alloy::core::simplex::scaled_octave_noise( core::real octaves, - core::real persistence, - core::real scale, - core::real low, - core::real high, - core::real x, - core::real y ) - noexcept +inline +auto alloy::core::simplex::scaled_octave_noise(real octaves, + real persistence, + real scale, + real low, + real high, + real x, + real y) + noexcept -> real { - assert( low < high && "Low must be less than high" ); + ALLOY_ASSERT(low < high, "Low must be less than high"); const auto c1 = ((high - low) * real{0.5}); const auto c2 = ((high + low) * real{0.5}); @@ -314,18 +306,18 @@ inline alloy::core::real //---------------------------------------------------------------------------- -inline alloy::core::real - alloy::core::simplex::scaled_octave_noise( core::real octaves, - core::real persistence, - core::real scale, - core::real low, - core::real high, - core::real x, - core::real y, - core::real z ) - noexcept +inline +auto alloy::core::simplex::scaled_octave_noise(real octaves, + real persistence, + real scale, + real low, + real high, + real x, + real y, + real z) + noexcept -> real { - assert( low < high && "Low must be less than high" ); + ALLOY_ASSERT(low < high, "Low must be less than high"); const auto c1 = ((high - low) * real{0.5}); const auto c2 = ((high + low) * real{0.5}); @@ -335,14 +327,14 @@ inline alloy::core::real //---------------------------------------------------------------------------- -inline alloy::core::real - alloy::core::simplex::scaled_octave_noise( core::real octaves, - core::real persistence, - core::real scale, - core::real low, - core::real high, - const vector2& pos ) - noexcept +inline +auto alloy::core::simplex::scaled_octave_noise(real octaves, + real persistence, + real scale, + real low, + real high, + const vector2& pos) + noexcept -> real { return scaled_octave_noise( octaves, persistence, scale, low, high, pos.x(), pos.y() ); @@ -350,14 +342,14 @@ inline alloy::core::real //---------------------------------------------------------------------------- -inline alloy::core::real - alloy::core::simplex::scaled_octave_noise( core::real octaves, - core::real persistence, - core::real scale, - core::real low, - core::real high, - const vector3& pos ) - noexcept +inline +auto alloy::core::simplex::scaled_octave_noise(real octaves, + real persistence, + real scale, + real low, + real high, + const vector3& pos) + noexcept -> real { return scaled_octave_noise( octaves, persistence, scale, low, high, pos.x(), pos.y(), pos.z() ); diff --git a/lib/alloy-core/include/alloy/core/math/trigonometry.hpp b/lib/alloy-core/include/alloy/core/math/trigonometry.hpp index 735031b7..5a0f53ef 100644 --- a/lib/alloy-core/include/alloy/core/math/trigonometry.hpp +++ b/lib/alloy-core/include/alloy/core/math/trigonometry.hpp @@ -49,7 +49,7 @@ namespace alloy::core { ////////////////////////////////////////////////////////////////////////////// /// \brief A static class that contains the standard trigonometric functions ////////////////////////////////////////////////////////////////////////////// - struct trigonometry + struct ALLOY_CORE_API trigonometry { trigonometry() = delete; ~trigonometry() = delete; @@ -62,8 +62,7 @@ namespace alloy::core { /// /// \param rad the angle /// \return the result of \c cos(rad) - ALLOY_CORE_API - static core::real cos( radian rad ) noexcept; + static auto cos(radian rad) noexcept -> real; /// \brief Calculates the cosine of the given \p angle /// @@ -73,7 +72,7 @@ namespace alloy::core { /// \param angle the angle /// \return the result of \c cos(angle) template - static core::real cos( basic_angle angle ) noexcept; + static auto cos(basic_angle angle) noexcept -> real; //-------------------------------------------------------------------------- @@ -81,8 +80,7 @@ namespace alloy::core { /// /// \param rad the angle /// \return the result of \c sin(rad) - ALLOY_CORE_API - static core::real sin( radian rad ) noexcept; + static auto sin(radian rad) noexcept -> real; /// \brief Calculates the sine of the given \p angle /// @@ -92,7 +90,7 @@ namespace alloy::core { /// \param angle the angle /// \return the result of \c sin(angle) template - static core::real sin( basic_angle angle ) noexcept; + static auto sin(basic_angle angle) noexcept -> real; //-------------------------------------------------------------------------- @@ -100,8 +98,7 @@ namespace alloy::core { /// /// \param rad the angle /// \return the result of \c tan(rad) - ALLOY_CORE_API - static core::real tan( radian rad ) noexcept; + static auto tan(radian rad) noexcept -> real; /// \brief Calculates the tangent of the given \ref gradian angle, \p grad /// @@ -111,7 +108,7 @@ namespace alloy::core { /// \param angle the angle /// \return the result of \c tan(angle) template - static core::real tan( basic_angle angle ) noexcept; + static auto tan(basic_angle angle) noexcept -> real; //-------------------------------------------------------------------------- @@ -123,7 +120,7 @@ namespace alloy::core { /// \param angle the angle /// \return the result of \c sec(angle) template - static core::real sec( basic_angle angle ) noexcept; + static auto sec(basic_angle angle) noexcept -> real; /// \brief Calculates the cosecant of the given \ref gradian angle, \p grad /// @@ -133,7 +130,7 @@ namespace alloy::core { /// \param angle the angle /// \return the result of \c csc(angle) template - static core::real csc( basic_angle angle ) noexcept; + static auto csc(basic_angle angle) noexcept -> real; /// \brief Calculates the cotangent of the given \ref gradian angle, \p grad /// @@ -143,7 +140,7 @@ namespace alloy::core { /// \param angle the angle /// \return the result of \c cot(angle) template - static core::real cot( basic_angle angle ) noexcept; + static auto cot(basic_angle angle) noexcept -> real; //-------------------------------------------------------------------------- // Inverse Trig @@ -153,35 +150,28 @@ namespace alloy::core { /// /// \param f the value /// \return the inverse cosine - ALLOY_CORE_API - static radian arccos( core::real f ) noexcept; + static auto arccos(real f) noexcept -> radian; /// \brief Calculates the inverse sine /// /// \param f the value /// \return the inverse sine - ALLOY_CORE_API - static radian arcsin( core::real f ) noexcept; + static auto arcsin(real f) noexcept -> radian; /// \brief Calculates the inverse tangent /// /// \param f the value /// \return the inverse tangent - ALLOY_CORE_API - static radian arctan( core::real f ) noexcept; + static auto arctan(real f) noexcept -> radian; /// \brief Calculates the inverse tangent 2 /// /// \param f1 the first value /// \param f2 the second value /// \return the inverse tangent 2 - ALLOY_CORE_API - static radian arctan2( core::real f1, core::real f2 ) noexcept; - + static auto arctan2(real f1, real f2) noexcept -> radian; }; - using trig = trigonometry; - } // namespace alloy::core //============================================================================== @@ -189,9 +179,9 @@ namespace alloy::core { //============================================================================== template -inline alloy::core::real - alloy::core::trigonometry::cos( basic_angle angle ) - noexcept +inline +auto alloy::core::trigonometry::cos(basic_angle angle) + noexcept -> real { return cos( to_radian(angle) ); } @@ -199,9 +189,9 @@ inline alloy::core::real //------------------------------------------------------------------------------ template -inline alloy::core::real - alloy::core::trigonometry::sin( basic_angle angle ) - noexcept +inline +auto alloy::core::trigonometry::sin(basic_angle angle) + noexcept -> real { return sin( to_radian(angle) ); } @@ -209,9 +199,9 @@ inline alloy::core::real //------------------------------------------------------------------------------ template -inline alloy::core::real - alloy::core::trigonometry::tan( basic_angle angle ) - noexcept +inline +auto alloy::core::trigonometry::tan(basic_angle angle) + noexcept -> real { return tan( to_radian(angle) ); } @@ -219,27 +209,27 @@ inline alloy::core::real //------------------------------------------------------------------------------ template -inline alloy::core::real - alloy::core::trigonometry::sec( basic_angle angle ) - noexcept +inline +auto alloy::core::trigonometry::sec(basic_angle angle) + noexcept -> real { return real{1} / cos( angle ); } template -inline alloy::core::real - alloy::core::trigonometry::csc( basic_angle angle ) - noexcept +inline +auto alloy::core::trigonometry::csc(basic_angle angle) + noexcept -> real { return real{1} / sin( angle ); } template -inline alloy::core::real - alloy::core::trigonometry::cot( basic_angle angle ) - noexcept +inline +auto alloy::core::trigonometry::cot(basic_angle angle) + noexcept -> real { return real{1} / tan( angle ); } -#endif /* ALLOY_CORE_MATH_TRIGONOMETRY_HPP */ \ No newline at end of file +#endif /* ALLOY_CORE_MATH_TRIGONOMETRY_HPP */ diff --git a/lib/alloy-core/src/alloy/core/math/simplex.cpp b/lib/alloy-core/src/alloy/core/math/simplex.cpp index 1e9a3d81..a5058c5a 100644 --- a/lib/alloy-core/src/alloy/core/math/simplex.cpp +++ b/lib/alloy-core/src/alloy/core/math/simplex.cpp @@ -1,76 +1,76 @@ #include "alloy/core/math/simplex.hpp" -namespace { - - // The gradients are the midpoints of the vertices of a cube. - constexpr int g_grad[12][3] = { - {1,1,0}, {-1,1,0}, {1,-1,0}, {-1,-1,0}, - {1,0,1}, {-1,0,1}, {1,0,-1}, {-1,0,-1}, - {0,1,1}, {0,-1,1}, {0,1,-1}, {0,-1,-1} - }; - - // Permutation table. The same list is repeated twice. - constexpr int g_permutation_table[512] = { - 151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142, - 8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117, - 35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71, - 134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41, - 55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208, 89, - 18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226, - 250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182, - 189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43, - 172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97, - 228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239, - 107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254, - 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180, - - 151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142, - 8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117, - 35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71, - 134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41, - 55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208, 89, - 18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226, - 250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182, - 189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43, - 172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97, - 228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239, - 107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254, - 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 - }; - - - constexpr alloy::core::real dot2( const int* a, - alloy::core::real x, - alloy::core::real y ) - noexcept - { - return static_cast(a[0]) * x + - static_cast(a[1]) * y; - } +namespace alloy::core { + namespace { + + // The gradients are the midpoints of the vertices of a cube. + constexpr int g_grad[12][3] = { + {1,1,0}, {-1,1,0}, {1,-1,0}, {-1,-1,0}, + {1,0,1}, {-1,0,1}, {1,0,-1}, {-1,0,-1}, + {0,1,1}, {0,-1,1}, {0,1,-1}, {0,-1,-1} + }; + + // Permutation table. The same list is repeated twice. + constexpr int g_permutation_table[512] = { + 151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142, + 8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117, + 35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71, + 134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41, + 55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208, 89, + 18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226, + 250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182, + 189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43, + 172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97, + 228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239, + 107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254, + 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180, + + 151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142, + 8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117, + 35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71, + 134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41, + 55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208, 89, + 18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226, + 250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182, + 189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43, + 172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97, + 228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239, + 107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254, + 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 + }; + + constexpr + auto dot2(const int* a, real x, real y) + noexcept -> real + { + return static_cast(a[0]) * x + + static_cast(a[1]) * y; + } - // constexpr alloy::core::real dot3( const int* a, - // alloy::core::real x, - // alloy::core::real y, - // alloy::core::real z ) - // noexcept - // { - // return a[0]*x + a[1]*y + a[2]*z; - // } - - constexpr int floor_f_to_i( alloy::core::real x ) - noexcept - { - return x > 0 ? static_cast(x) : static_cast(x) - 1; - } -} // anonymous namespace + // constexpr alloy::core::real dot3( const int* a, + // alloy::core::real x, + // alloy::core::real y, + // alloy::core::real z ) + // noexcept + // { + // return a[0]*x + a[1]*y + a[2]*z; + // } + + constexpr + auto floor_f_to_i(real x) + noexcept -> int + { + return x > 0 ? static_cast(x) : static_cast(x) - 1; + } + } // anonymous namespace +} // namespace alloy::core //------------------------------------------------------------------------------ // Raw Noise //------------------------------------------------------------------------------ -alloy::core::real - alloy::core::simplex::raw_noise(real x, real y) - noexcept +auto alloy::core::simplex::raw_noise(real x, real y) + noexcept -> real { static const auto s_sqrt3 = static_cast(sqrt( 3.0 )); static const auto s_skew = real{0.5} * (s_sqrt3 - real{1}); @@ -139,7 +139,7 @@ alloy::core::real n0 = real{0.0}; } else { t0 *= t0; - n0 = t0 * t0 * ::dot2( g_grad[gi0], x0, y0 ); + n0 = t0 * t0 * dot2( g_grad[gi0], x0, y0 ); } auto t1 = real{0.5} - x1*x1-y1*y1; @@ -147,7 +147,7 @@ alloy::core::real n1 = real{0.0}; } else { t1 *= t1; - n1 = static_cast(t1 * t1) * ::dot2( g_grad[gi1], x1, y1 ); + n1 = static_cast(t1 * t1) * dot2( g_grad[gi1], x1, y1 ); } auto t2 = real{0.5} - x2*x2-y2*y2; @@ -155,7 +155,7 @@ alloy::core::real n2 = real{0.0}; } else { t2 *= t2; - n2 = static_cast(t2 * t2) * ::dot2( g_grad[gi2], x2, y2 ); + n2 = static_cast(t2 * t2) * dot2( g_grad[gi2], x2, y2 ); } // Add contributions from each corner to get the final noise value. @@ -165,9 +165,8 @@ alloy::core::real return static_cast(result); } -alloy::core::real - alloy::core::simplex::raw_noise(real x, real y, real z ) - noexcept +auto alloy::core::simplex::raw_noise(real x, real y, real z) + noexcept -> real { // TODO(matthew rodusek) 2017-04-22: Implement return static_cast(x+y+z); @@ -177,13 +176,12 @@ alloy::core::real // Octave Noises //------------------------------------------------------------------------------ -alloy::core::real - alloy::core::simplex::octave_noise(real octaves, - real persistence, - real scale, - real x, - real y) - noexcept +auto alloy::core::simplex::octave_noise(real octaves, + real persistence, + real scale, + real x, + real y) + noexcept -> real { auto frequency = scale; @@ -203,14 +201,13 @@ alloy::core::real return static_cast(total / max_amplitude); } -alloy::core::real - alloy::core::simplex::octave_noise(real octaves, - real persistence, - real scale, - real x, - real y, - real z) - noexcept +auto alloy::core::simplex::octave_noise(real octaves, + real persistence, + real scale, + real x, + real y, + real z) + noexcept -> real { auto frequency = scale; diff --git a/lib/alloy-core/src/alloy/core/math/trigonometry.cpp b/lib/alloy-core/src/alloy/core/math/trigonometry.cpp index 8afb6e77..a3e9a5e1 100644 --- a/lib/alloy-core/src/alloy/core/math/trigonometry.cpp +++ b/lib/alloy-core/src/alloy/core/math/trigonometry.cpp @@ -10,20 +10,20 @@ // Trig //---------------------------------------------------------------------------- -alloy::core::real alloy::core::trigonometry::cos( radian rad ) - noexcept +auto alloy::core::trigonometry::cos(radian rad) + noexcept -> real { return std::cos( rad.value() ); } -alloy::core::real alloy::core::trigonometry::sin( radian rad ) - noexcept +auto alloy::core::trigonometry::sin(radian rad) + noexcept -> real { return std::sin( rad.value() ); } -alloy::core::real alloy::core::trigonometry::tan( radian rad ) - noexcept +auto alloy::core::trigonometry::tan(radian rad) + noexcept -> real { return std::tan( rad.value() ); } @@ -32,27 +32,26 @@ alloy::core::real alloy::core::trigonometry::tan( radian rad ) // Inverse Trig //---------------------------------------------------------------------------- -alloy::core::radian alloy::core::trigonometry::arccos( core::real f ) - noexcept +auto alloy::core::trigonometry::arccos(core::real f) + noexcept -> radian { return radian{ std::acos(f) }; } -alloy::core::radian alloy::core::trigonometry::arcsin( core::real f ) - noexcept +auto alloy::core::trigonometry::arcsin(core::real f) + noexcept -> radian { return radian{ std::asin(f) }; } -alloy::core::radian alloy::core::trigonometry::arctan( core::real f ) - noexcept +auto alloy::core::trigonometry::arctan(core::real f) + noexcept -> radian { return radian{ std::atan(f) }; } -alloy::core::radian alloy::core::trigonometry::arctan2( core::real f1, - core::real f2 ) - noexcept +auto alloy::core::trigonometry::arctan2(core::real f1, core::real f2) + noexcept -> radian { return radian{ std::atan2(f1,f2) }; }