Skip to content

Commit

Permalink
Make minor improvements to vector, matrix, and quaternion classes. Re…
Browse files Browse the repository at this point in the history
…duce minimum CMake version to 3.27 so GitHub build will work.
  • Loading branch information
cjhoward committed Dec 14, 2023
1 parent 83676be commit f902df1
Show file tree
Hide file tree
Showing 7 changed files with 419 additions and 274 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds prohibited.")
endif()

cmake_minimum_required(VERSION 3.28)
cmake_minimum_required(VERSION 3.27)
include(FetchContent)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"cmakeMinimumRequired":
{
"major": 3,
"minor": 28,
"minor": 27,
"patch": 0
},
"configurePresets":
Expand Down
12 changes: 7 additions & 5 deletions src/engine/math/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <engine/math/constants.hpp>
#include <cmath>
#include <concepts>
#include <tuple>

// export module math.functions;
// import math.constants;
Expand All @@ -15,7 +16,7 @@

namespace math {

/// Mathematical functions
/// Mathematical functions.
namespace functions {

/// @name Basic operations
Expand Down Expand Up @@ -526,14 +527,15 @@ template <std::floating_point T>
* Splits a value into its integer and fractional components.
*
* @param x Value to split.
* @param[out] i Integer part of @p x.
*
* @return Fractional part of @p x.
* @return Tuple containing the fractional part of @p x, followed by the integer part of @p x.
*/
template <std::floating_point T>
[[nodiscard]] inline T modf(T x, T i)
[[nodiscard]] inline std::tuple<T, T> modf(T x)
{
return std::modf(x, &i);
std::tuple<T, T> result;
std::get<0>(result) = std::modf(x, &std::get<1>(result));
return result;
}

/// @}
Expand Down
51 changes: 0 additions & 51 deletions src/engine/math/matrix-functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,6 @@ template <class T, std::size_t N, std::size_t M>
template <class T, std::size_t N, std::size_t M>
[[nodiscard]] constexpr matrix<T, N, M> div(T a, const matrix<T, N, M>& b) noexcept;

/**
* Extracts the Ith column from a matrix.
*
* @tparam I Index of a column.
* @tparam T Element type.
* @tparam N Number of columns.
* @tparam M Number of rows.
*
* @param m Matrix from which to extract a column.
*
* @return Reference to the Ith column of @p m.
*/
/// @{
template<std::size_t I, class T, std::size_t N, std::size_t M>
[[nodiscard]] constexpr typename matrix<T, N, M>::column_type& get(matrix<T, N, M>& m) noexcept;
template<std::size_t I, class T, std::size_t N, std::size_t M>
[[nodiscard]] constexpr typename matrix<T, N, M>::column_type&& get(matrix<T, N, M>&& m) noexcept;
template<std::size_t I, class T, std::size_t N, std::size_t M>
[[nodiscard]] constexpr const typename matrix<T, N, M>::column_type& get(const matrix<T, N, M>& m) noexcept;
template<std::size_t I, class T, std::size_t N, std::size_t M>
[[nodiscard]] constexpr const typename matrix<T, N, M>::column_type&& get(const matrix<T, N, M>&& m) noexcept;
/// @}

/**
* Calculates the inverse of a square matrix.
*
Expand Down Expand Up @@ -445,34 +422,6 @@ constexpr matrix<T, N, M> div(T a, const matrix<T, N, M>& b) noexcept
return div(a, b, std::make_index_sequence<N>{});
}

template<std::size_t I, class T, std::size_t N, std::size_t M>
inline constexpr typename matrix<T, N, M>::column_type& get(matrix<T, N, M>& m) noexcept
{
static_assert(I < N);
return m.columns[I];
}

template<std::size_t I, class T, std::size_t N, std::size_t M>
inline constexpr typename matrix<T, N, M>::column_type&& get(matrix<T, N, M>&& m) noexcept
{
static_assert(I < N);
return std::move(m.columns[I]);
}

template<std::size_t I, class T, std::size_t N, std::size_t M>
inline constexpr const typename matrix<T, N, M>::column_type& get(const matrix<T, N, M>& m) noexcept
{
static_assert(I < N);
return m.columns[I];
}

template<std::size_t I, class T, std::size_t N, std::size_t M>
inline constexpr const typename matrix<T, N, M>::column_type&& get(const matrix<T, N, M>&& m) noexcept
{
static_assert(I < N);
return std::move(m.columns[I]);
}

/// @private
template <class T>
constexpr matrix<T, 2, 2> inverse(const matrix<T, 2, 2>& m) noexcept
Expand Down
Loading

0 comments on commit f902df1

Please sign in to comment.