mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-16 22:19:51 +07:00
basic types non-arithmetic T support
This commit is contained in:
@@ -20,21 +20,22 @@ namespace vmath_hpp::detail
|
||||
class mat_base<T, 2> {
|
||||
public:
|
||||
using row_type = vec<T, 2>;
|
||||
|
||||
row_type rows[2] = {
|
||||
{1, 0},
|
||||
{0, 1}};
|
||||
row_type{T{1}, T{0}},
|
||||
row_type{T{0}, T{1}}};
|
||||
public:
|
||||
constexpr mat_base() = default;
|
||||
|
||||
constexpr explicit mat_base(T d)
|
||||
: rows{
|
||||
row_type{d, 0},
|
||||
row_type{0, d}} {}
|
||||
row_type{d, T{0}},
|
||||
row_type{T{0}, d}} {}
|
||||
|
||||
constexpr explicit mat_base(const row_type& d)
|
||||
: rows{
|
||||
row_type{d[0], 0},
|
||||
row_type{0, d[1]}} {}
|
||||
row_type{d[0], T{0}},
|
||||
row_type{T{0}, d[1]}} {}
|
||||
|
||||
constexpr mat_base(
|
||||
T m11, T m12,
|
||||
@@ -65,24 +66,25 @@ namespace vmath_hpp::detail
|
||||
class mat_base<T, 3> {
|
||||
public:
|
||||
using row_type = vec<T, 3>;
|
||||
|
||||
row_type rows[3] = {
|
||||
{1, 0, 0},
|
||||
{0, 1, 0},
|
||||
{0, 0, 1}};
|
||||
row_type{T{1}, T{0}, T{0}},
|
||||
row_type{T{0}, T{1}, T{0}},
|
||||
row_type{T{0}, T{0}, T{1}}};
|
||||
public:
|
||||
constexpr mat_base() = default;
|
||||
|
||||
constexpr explicit mat_base(T d)
|
||||
: rows{
|
||||
row_type{d, 0, 0},
|
||||
row_type{0, d, 0},
|
||||
row_type{0, 0, d}} {}
|
||||
row_type{d, T{0}, T{0}},
|
||||
row_type{T{0}, d, T{0}},
|
||||
row_type{T{0}, T{0}, d}} {}
|
||||
|
||||
constexpr explicit mat_base(const row_type& d)
|
||||
: rows{
|
||||
row_type{d[0], 0, 0},
|
||||
row_type{0, d[1], 0},
|
||||
row_type{0, 0, d[2]}} {}
|
||||
row_type{d[0], T{0}, T{0}},
|
||||
row_type{T{0}, d[1], T{0}},
|
||||
row_type{T{0}, T{0}, d[2]}} {}
|
||||
|
||||
constexpr mat_base(
|
||||
T m11, T m12, T m13,
|
||||
@@ -103,16 +105,16 @@ namespace vmath_hpp::detail
|
||||
const mat_base<T, 2>& m,
|
||||
const vec_base<T, 2>& v)
|
||||
: rows{
|
||||
row_type{m.rows[0], 0},
|
||||
row_type{m.rows[1], 0},
|
||||
row_type{v, 1}} {}
|
||||
row_type{m.rows[0], T{0}},
|
||||
row_type{m.rows[1], T{0}},
|
||||
row_type{v, T{1}}} {}
|
||||
|
||||
constexpr explicit mat_base(
|
||||
const mat_base<T, 2>& other)
|
||||
: rows{
|
||||
row_type{other.rows[0], 0},
|
||||
row_type{other.rows[1], 0},
|
||||
row_type{0, 0, 1}} {}
|
||||
row_type{other.rows[0], T{0}},
|
||||
row_type{other.rows[1], T{0}},
|
||||
row_type{T{0}, T{0}, T{1}}} {}
|
||||
|
||||
constexpr explicit mat_base(
|
||||
const mat_base<T, 4>& other)
|
||||
@@ -126,27 +128,28 @@ namespace vmath_hpp::detail
|
||||
class mat_base<T, 4> {
|
||||
public:
|
||||
using row_type = vec<T, 4>;
|
||||
|
||||
row_type rows[4] = {
|
||||
{1, 0, 0, 0},
|
||||
{0, 1, 0, 0},
|
||||
{0, 0, 1, 0},
|
||||
{0, 0, 0, 1}};
|
||||
row_type{T{1}, T{0}, T{0}, T{0}},
|
||||
row_type{T{0}, T{1}, T{0}, T{0}},
|
||||
row_type{T{0}, T{0}, T{1}, T{0}},
|
||||
row_type{T{0}, T{0}, T{0}, T{1}}};
|
||||
public:
|
||||
constexpr mat_base() = default;
|
||||
|
||||
constexpr explicit mat_base(T d)
|
||||
: rows{
|
||||
row_type{d, 0, 0, 0},
|
||||
row_type{0, d, 0, 0},
|
||||
row_type{0, 0, d, 0},
|
||||
row_type{0, 0, 0, d}} {}
|
||||
row_type{d, T{0}, T{0}, T{0}},
|
||||
row_type{T{0}, d, T{0}, T{0}},
|
||||
row_type{T{0}, T{0}, d, T{0}},
|
||||
row_type{T{0}, T{0}, T{0}, d}} {}
|
||||
|
||||
constexpr explicit mat_base(const row_type& d)
|
||||
: rows{
|
||||
row_type{d[0], 0, 0, 0},
|
||||
row_type{0, d[1], 0, 0},
|
||||
row_type{0, 0, d[2], 0},
|
||||
row_type{0, 0, 0, d[3]}} {}
|
||||
row_type{d[0], T{0}, T{0}, T{0}},
|
||||
row_type{T{0}, d[1], T{0}, T{0}},
|
||||
row_type{T{0}, T{0}, d[2], T{0}},
|
||||
row_type{T{0}, T{0}, T{0}, d[3]}} {}
|
||||
|
||||
constexpr mat_base(
|
||||
T m11, T m12, T m13, T m14,
|
||||
@@ -170,26 +173,26 @@ namespace vmath_hpp::detail
|
||||
const mat_base<T, 3>& m,
|
||||
const vec_base<T, 3>& v)
|
||||
: rows{
|
||||
row_type{m.rows[0], 0},
|
||||
row_type{m.rows[1], 0},
|
||||
row_type{m.rows[2], 0},
|
||||
row_type{v, 1}} {}
|
||||
row_type{m.rows[0], T{0}},
|
||||
row_type{m.rows[1], T{0}},
|
||||
row_type{m.rows[2], T{0}},
|
||||
row_type{v, T{1}}} {}
|
||||
|
||||
constexpr explicit mat_base(
|
||||
const mat_base<T, 2>& other)
|
||||
: rows{
|
||||
row_type{other.rows[0], 0, 0},
|
||||
row_type{other.rows[1], 0, 0},
|
||||
row_type{0, 0, 1, 0},
|
||||
row_type{0, 0, 0, 1}} {}
|
||||
row_type{other.rows[0], T{0}, T{0}},
|
||||
row_type{other.rows[1], T{0}, T{0}},
|
||||
row_type{T{0}, T{0}, T{1}, T{0}},
|
||||
row_type{T{0}, T{0}, T{0}, T{1}}} {}
|
||||
|
||||
constexpr explicit mat_base(
|
||||
const mat_base<T, 3>& other)
|
||||
: rows{
|
||||
row_type{other.rows[0], 0},
|
||||
row_type{other.rows[1], 0},
|
||||
row_type{other.rows[2], 0},
|
||||
row_type{0, 0, 0, 1}} {}
|
||||
row_type{other.rows[0], T{0}},
|
||||
row_type{other.rows[1], T{0}},
|
||||
row_type{other.rows[2], T{0}},
|
||||
row_type{T{0}, T{0}, T{0}, T{1}}} {}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -253,14 +256,6 @@ namespace vmath_hpp
|
||||
return &rows[0];
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr reference operator[](std::size_t index) noexcept {
|
||||
return rows[index];
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const_reference operator[](std::size_t index) const noexcept {
|
||||
return rows[index];
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr reference at(std::size_t index) {
|
||||
VMATH_HPP_THROW_IF(index >= size, std::out_of_range("mat::at"));
|
||||
return rows[index];
|
||||
@@ -270,6 +265,14 @@ namespace vmath_hpp
|
||||
VMATH_HPP_THROW_IF(index >= size, std::out_of_range("mat::at"));
|
||||
return rows[index];
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr reference operator[](std::size_t index) noexcept {
|
||||
return rows[index];
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const_reference operator[](std::size_t index) const noexcept {
|
||||
return rows[index];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user