Skip to content

Commit

Permalink
Fix: Make vectors and matrices trivially copyable
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda committed Jan 25, 2025
1 parent d4b2836 commit 8f0d3ba
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions include/fastgltf/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ namespace fastgltf::math {
return ret;
}

constexpr vec(const vec<T, N>& other) noexcept : _data(other._data) {}
constexpr vec<T, N>& operator=(const vec<T, N>& other) noexcept {
_data = other._data;
return *this;
}
constexpr vec(const vec&) noexcept = default;
constexpr vec& operator=(const vec& other) noexcept = default;

template <typename U, std::enable_if_t<!std::is_same_v<T, U>, bool> = true>
constexpr explicit vec(const vec<U, N>& other) noexcept {
Expand Down Expand Up @@ -643,6 +640,8 @@ namespace fastgltf::math {
copy_values(tuple, std::make_integer_sequence<std::size_t, sizeof...(Args)>());
}

constexpr mat(const mat& other) = default;

/** Truncates the matrix to a smaller one, discarding the additional rows and/or colums */
template <std::size_t Q, std::size_t P, std::enable_if_t<N < Q && M < P, bool> = true>
constexpr explicit mat(const mat<T, Q, P>& other) noexcept {
Expand Down Expand Up @@ -753,6 +752,11 @@ namespace fastgltf::math {
}
};

static_assert(std::is_trivially_copyable_v<mat<float, 4, 4>>);
static_assert(std::is_trivially_copyable_v<vec<float, 4>>);
static_assert(std::is_trivially_copyable_v<std::array<vec<float, 4>, 4>>);
static_assert(std::is_trivially_copyable_v<std::array<float, 4>>);

/** Transposes the given matrix */
FASTGLTF_EXPORT template <typename T, std::size_t N, std::size_t M>
[[nodiscard]] auto transpose(const mat<T, N, M>& m) noexcept {
Expand Down

0 comments on commit 8f0d3ba

Please sign in to comment.