mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-13 20:17:58 +07:00
add ctors without initialization
This commit is contained in:
66
README.md
66
README.md
@@ -85,10 +85,11 @@ class vec_base;
|
||||
template < typename T >
|
||||
class vec_base<T, 2> {
|
||||
public:
|
||||
T x = T{0};
|
||||
T y = T{0};
|
||||
T x, y;
|
||||
|
||||
vec_base();
|
||||
explicit vec_base(uninit_t);
|
||||
|
||||
vec_base() = default;
|
||||
explicit vec_base(T v);
|
||||
vec_base(T x, T y);
|
||||
};
|
||||
@@ -96,11 +97,11 @@ public:
|
||||
template < typename T >
|
||||
class vec_base<T, 3> {
|
||||
public:
|
||||
T x = T{0};
|
||||
T y = T{0};
|
||||
T z = T{0};
|
||||
T x, y, z;
|
||||
|
||||
vec_base();
|
||||
explicit vec_base(uninit_t);
|
||||
|
||||
vec_base() = default;
|
||||
explicit vec_base(T v);
|
||||
vec_base(T x, T y, T z);
|
||||
vec_base(const vec_base<T, 2>& xy, T z);
|
||||
@@ -112,12 +113,11 @@ public:
|
||||
template < typename T >
|
||||
class vec_base<T, 4> {
|
||||
public:
|
||||
T x = T{0};
|
||||
T y = T{0};
|
||||
T z = T{0};
|
||||
T w = T{0};
|
||||
T x, y, z, w;
|
||||
|
||||
vec_base();
|
||||
explicit vec_base(uninit_t);
|
||||
|
||||
vec_base() = default;
|
||||
explicit vec_base(T v);
|
||||
vec_base(T x, T y, T z, T w);
|
||||
vec_base(const vec_base<T, 2>& xy, T z, T w);
|
||||
@@ -151,10 +151,6 @@ public:
|
||||
|
||||
static inline size_t size = Size;
|
||||
|
||||
vec() = default;
|
||||
vec(const vec&) = default;
|
||||
vec& operator=(const vec&) = default;
|
||||
|
||||
void swap(vec& other);
|
||||
|
||||
iterator begin();
|
||||
@@ -221,12 +217,11 @@ template < typename T >
|
||||
class mat_base<T, 2> {
|
||||
public:
|
||||
using row_type = vec<T, 2>;
|
||||
row_type rows[2];
|
||||
|
||||
row_type rows[2] = {
|
||||
row_type{T{1}, T{0}},
|
||||
row_type{T{0}, T{1}}};
|
||||
mat_base();
|
||||
explicit mat_base(uninit_t);
|
||||
|
||||
mat_base() = default;
|
||||
explicit mat_base(T d);
|
||||
explicit mat_base(const row_type& d);
|
||||
|
||||
@@ -243,13 +238,11 @@ template < typename T >
|
||||
class mat_base<T, 3> {
|
||||
public:
|
||||
using row_type = vec<T, 3>;
|
||||
row_type rows[3];
|
||||
|
||||
row_type rows[3] = {
|
||||
row_type{T{1}, T{0}, T{0}},
|
||||
row_type{T{0}, T{1}, T{0}},
|
||||
row_type{T{0}, T{0}, T{1}}};
|
||||
mat_base();
|
||||
explicit mat_base(uninit_t);
|
||||
|
||||
mat_base() = default;
|
||||
explicit mat_base(T d);
|
||||
explicit mat_base(const row_type& d);
|
||||
|
||||
@@ -276,14 +269,11 @@ template < typename T >
|
||||
class mat_base<T, 4> {
|
||||
public:
|
||||
using row_type = vec<T, 4>;
|
||||
row_type rows[4];
|
||||
|
||||
row_type rows[4] = {
|
||||
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}}};
|
||||
mat_base();
|
||||
explicit mat_base(uninit_t);
|
||||
|
||||
mat_base() = default;
|
||||
explicit mat_base(T d);
|
||||
explicit mat_base(const row_type& d);
|
||||
|
||||
@@ -332,10 +322,6 @@ public:
|
||||
|
||||
static inline size_t size = Size;
|
||||
|
||||
mat() = default;
|
||||
mat(const mat&) = default;
|
||||
mat& operator=(const mat&) = default;
|
||||
|
||||
void swap(mat& other);
|
||||
|
||||
iterator begin();
|
||||
@@ -398,10 +384,12 @@ using ptrdiff4x4_t = mat<ptrdiff_t, 4>;
|
||||
template < typename T >
|
||||
class qua_base {
|
||||
public:
|
||||
vec<T, 3> v = vec<T, 3>{T{0}};
|
||||
T s = T{1};
|
||||
vec<T, 3> v;
|
||||
T s;
|
||||
|
||||
qua_base();
|
||||
explicit qua_base(uninit_t);
|
||||
|
||||
qua_base(T vx, T vy, T vz, T s);
|
||||
qua_base(const vec<T, 3>& v, T s);
|
||||
|
||||
@@ -432,10 +420,6 @@ public:
|
||||
|
||||
static inline size_t size = 4;
|
||||
|
||||
qua() = default;
|
||||
qua(const qua&) = default;
|
||||
qua& operator=(const qua&) = default;
|
||||
|
||||
void swap(qua& other);
|
||||
|
||||
iterator begin();
|
||||
|
||||
@@ -38,6 +38,12 @@
|
||||
#define VMATH_HPP_THROW_IF(pred, ...)\
|
||||
( (pred) ? VMATH_HPP_THROW(__VA_ARGS__) : (void)0 )
|
||||
|
||||
namespace vmath_hpp
|
||||
{
|
||||
struct uninit_t { explicit uninit_t() = default; };
|
||||
inline constexpr uninit_t uninit{};
|
||||
}
|
||||
|
||||
namespace vmath_hpp
|
||||
{
|
||||
template < typename T, std::size_t Size >
|
||||
|
||||
@@ -20,29 +20,31 @@ namespace vmath_hpp::detail
|
||||
class mat_base<T, 2> {
|
||||
public:
|
||||
using row_type = vec<T, 2>;
|
||||
|
||||
row_type rows[2] = {
|
||||
row_type{T{1}, T{0}},
|
||||
row_type{T{0}, T{1}}};
|
||||
row_type rows[2];
|
||||
public:
|
||||
constexpr mat_base() = default;
|
||||
constexpr mat_base()
|
||||
: rows{
|
||||
{T{1}, T{0}},
|
||||
{T{0}, T{1}}} {}
|
||||
|
||||
constexpr explicit mat_base(uninit_t) {}
|
||||
|
||||
constexpr explicit mat_base(T d)
|
||||
: rows{
|
||||
row_type{d, T{0}},
|
||||
row_type{T{0}, d}} {}
|
||||
{d, T{0}},
|
||||
{T{0}, d}} {}
|
||||
|
||||
constexpr explicit mat_base(const row_type& d)
|
||||
: rows{
|
||||
row_type{d[0], T{0}},
|
||||
row_type{T{0}, d[1]}} {}
|
||||
{d[0], T{0}},
|
||||
{T{0}, d[1]}} {}
|
||||
|
||||
constexpr mat_base(
|
||||
T m11, T m12,
|
||||
T m21, T m22)
|
||||
: rows{
|
||||
row_type{m11, m12},
|
||||
row_type{m21, m22}} {}
|
||||
{m11, m12},
|
||||
{m21, m22}} {}
|
||||
|
||||
constexpr mat_base(
|
||||
const row_type& row0,
|
||||
@@ -54,34 +56,36 @@ namespace vmath_hpp::detail
|
||||
class mat_base<T, 3> {
|
||||
public:
|
||||
using row_type = vec<T, 3>;
|
||||
|
||||
row_type rows[3] = {
|
||||
row_type{T{1}, T{0}, T{0}},
|
||||
row_type{T{0}, T{1}, T{0}},
|
||||
row_type{T{0}, T{0}, T{1}}};
|
||||
row_type rows[3];
|
||||
public:
|
||||
constexpr mat_base() = default;
|
||||
constexpr mat_base()
|
||||
: rows{
|
||||
{T{1}, T{0}, T{0}},
|
||||
{T{0}, T{1}, T{0}},
|
||||
{T{0}, T{0}, T{1}}} {}
|
||||
|
||||
constexpr explicit mat_base(uninit_t) {}
|
||||
|
||||
constexpr explicit mat_base(T d)
|
||||
: rows{
|
||||
row_type{d, T{0}, T{0}},
|
||||
row_type{T{0}, d, T{0}},
|
||||
row_type{T{0}, T{0}, d}} {}
|
||||
{d, T{0}, T{0}},
|
||||
{T{0}, d, T{0}},
|
||||
{T{0}, T{0}, d}} {}
|
||||
|
||||
constexpr explicit mat_base(const row_type& d)
|
||||
: rows{
|
||||
row_type{d[0], T{0}, T{0}},
|
||||
row_type{T{0}, d[1], T{0}},
|
||||
row_type{T{0}, T{0}, d[2]}} {}
|
||||
{d[0], T{0}, T{0}},
|
||||
{T{0}, d[1], T{0}},
|
||||
{T{0}, T{0}, d[2]}} {}
|
||||
|
||||
constexpr mat_base(
|
||||
T m11, T m12, T m13,
|
||||
T m21, T m22, T m23,
|
||||
T m31, T m32, T m33)
|
||||
: rows{
|
||||
row_type{m11, m12, m13},
|
||||
row_type{m21, m22, m23},
|
||||
row_type{m31, m32, m33}} {}
|
||||
{m11, m12, m13},
|
||||
{m21, m22, m23},
|
||||
{m31, m32, m33}} {}
|
||||
|
||||
constexpr mat_base(
|
||||
const row_type& row0,
|
||||
@@ -93,16 +97,16 @@ namespace vmath_hpp::detail
|
||||
const mat_base<T, 2>& m,
|
||||
const vec_base<T, 2>& v)
|
||||
: rows{
|
||||
row_type{m.rows[0], T{0}},
|
||||
row_type{m.rows[1], T{0}},
|
||||
row_type{v, T{1}}} {}
|
||||
{m.rows[0], T{0}},
|
||||
{m.rows[1], T{0}},
|
||||
{v, T{1}}} {}
|
||||
|
||||
constexpr explicit mat_base(
|
||||
const mat_base<T, 2>& other)
|
||||
: rows{
|
||||
row_type{other.rows[0], T{0}},
|
||||
row_type{other.rows[1], T{0}},
|
||||
row_type{T{0}, T{0}, T{1}}} {}
|
||||
{other.rows[0], T{0}},
|
||||
{other.rows[1], T{0}},
|
||||
{T{0}, T{0}, T{1}}} {}
|
||||
|
||||
constexpr explicit operator mat<T, 2>() const {
|
||||
return {
|
||||
@@ -115,28 +119,30 @@ namespace vmath_hpp::detail
|
||||
class mat_base<T, 4> {
|
||||
public:
|
||||
using row_type = vec<T, 4>;
|
||||
|
||||
row_type rows[4] = {
|
||||
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}}};
|
||||
row_type rows[4];
|
||||
public:
|
||||
constexpr mat_base() = default;
|
||||
constexpr mat_base()
|
||||
: rows{
|
||||
{T{1}, T{0}, T{0}, T{0}},
|
||||
{T{0}, T{1}, T{0}, T{0}},
|
||||
{T{0}, T{0}, T{1}, T{0}},
|
||||
{T{0}, T{0}, T{0}, T{1}}} {}
|
||||
|
||||
constexpr explicit mat_base(uninit_t) {}
|
||||
|
||||
constexpr explicit mat_base(T d)
|
||||
: rows{
|
||||
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}} {}
|
||||
{d, T{0}, T{0}, T{0}},
|
||||
{T{0}, d, T{0}, T{0}},
|
||||
{T{0}, T{0}, d, T{0}},
|
||||
{T{0}, T{0}, T{0}, d}} {}
|
||||
|
||||
constexpr explicit mat_base(const row_type& d)
|
||||
: rows{
|
||||
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]}} {}
|
||||
{d[0], T{0}, T{0}, T{0}},
|
||||
{T{0}, d[1], T{0}, T{0}},
|
||||
{T{0}, T{0}, d[2], T{0}},
|
||||
{T{0}, T{0}, T{0}, d[3]}} {}
|
||||
|
||||
constexpr mat_base(
|
||||
T m11, T m12, T m13, T m14,
|
||||
@@ -144,10 +150,10 @@ namespace vmath_hpp::detail
|
||||
T m31, T m32, T m33, T m34,
|
||||
T m41, T m42, T m43, T m44)
|
||||
: rows{
|
||||
row_type{m11, m12, m13, m14},
|
||||
row_type{m21, m22, m23, m24},
|
||||
row_type{m31, m32, m33, m34},
|
||||
row_type{m41, m42, m43, m44}} {}
|
||||
{m11, m12, m13, m14},
|
||||
{m21, m22, m23, m24},
|
||||
{m31, m32, m33, m34},
|
||||
{m41, m42, m43, m44}} {}
|
||||
|
||||
constexpr mat_base(
|
||||
const row_type& row0,
|
||||
@@ -160,26 +166,26 @@ namespace vmath_hpp::detail
|
||||
const mat_base<T, 3>& m,
|
||||
const vec_base<T, 3>& v)
|
||||
: rows{
|
||||
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}}} {}
|
||||
{m.rows[0], T{0}},
|
||||
{m.rows[1], T{0}},
|
||||
{m.rows[2], T{0}},
|
||||
{v, T{1}}} {}
|
||||
|
||||
constexpr explicit mat_base(
|
||||
const mat_base<T, 2>& other)
|
||||
: rows{
|
||||
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}}} {}
|
||||
{other.rows[0], T{0}, T{0}},
|
||||
{other.rows[1], T{0}, T{0}},
|
||||
{T{0}, T{0}, T{1}, T{0}},
|
||||
{T{0}, T{0}, T{0}, T{1}}} {}
|
||||
|
||||
constexpr explicit mat_base(
|
||||
const mat_base<T, 3>& other)
|
||||
: rows{
|
||||
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}}} {}
|
||||
{other.rows[0], T{0}},
|
||||
{other.rows[1], T{0}},
|
||||
{other.rows[2], T{0}},
|
||||
{T{0}, T{0}, T{0}, T{1}}} {}
|
||||
|
||||
constexpr explicit operator mat<T, 2>() const {
|
||||
return {
|
||||
@@ -223,10 +229,6 @@ namespace vmath_hpp
|
||||
using base_type::mat_base;
|
||||
using base_type::rows;
|
||||
|
||||
constexpr mat() = default;
|
||||
constexpr mat(const mat&) = default;
|
||||
constexpr mat& operator=(const mat&) = default;
|
||||
|
||||
void swap(mat& other) noexcept(std::is_nothrow_swappable_v<T>) {
|
||||
for ( std::size_t i = 0; i < Size; ++i ) {
|
||||
using std::swap;
|
||||
|
||||
@@ -16,10 +16,13 @@ namespace vmath_hpp::detail
|
||||
template < typename T >
|
||||
class qua_base {
|
||||
public:
|
||||
vec<T, 3> v = vec<T, 3>{T{0}};
|
||||
T s = T{1};
|
||||
vec<T, 3> v;
|
||||
T s;
|
||||
public:
|
||||
constexpr qua_base() = default;
|
||||
constexpr qua_base()
|
||||
: v{T{0}}, s{1} {}
|
||||
|
||||
constexpr explicit qua_base(uninit_t) {}
|
||||
|
||||
constexpr qua_base(T vx, T vy, T vz, T s)
|
||||
: v{vx, vy, vz}, s{s} {}
|
||||
@@ -84,10 +87,6 @@ namespace vmath_hpp
|
||||
using base_type::qua_base;
|
||||
using base_type::operator[];
|
||||
|
||||
constexpr qua() = default;
|
||||
constexpr qua(const qua&) = default;
|
||||
constexpr qua& operator=(const qua&) = default;
|
||||
|
||||
void swap(qua& other) noexcept(std::is_nothrow_swappable_v<T>) {
|
||||
for ( std::size_t i = 0; i < size; ++i ) {
|
||||
using std::swap;
|
||||
|
||||
@@ -16,10 +16,12 @@ namespace vmath_hpp::detail
|
||||
template < typename T >
|
||||
class vec_base<T, 2> {
|
||||
public:
|
||||
T x = T{0};
|
||||
T y = T{0};
|
||||
T x, y;
|
||||
public:
|
||||
constexpr vec_base() = default;
|
||||
constexpr vec_base()
|
||||
: x{0}, y{0} {}
|
||||
|
||||
constexpr explicit vec_base(uninit_t) {}
|
||||
|
||||
constexpr explicit vec_base(T v)
|
||||
: x{v}, y{v} {}
|
||||
@@ -47,11 +49,12 @@ namespace vmath_hpp::detail
|
||||
template < typename T >
|
||||
class vec_base<T, 3> {
|
||||
public:
|
||||
T x = T{0};
|
||||
T y = T{0};
|
||||
T z = T{0};
|
||||
T x, y, z;
|
||||
public:
|
||||
constexpr vec_base() = default;
|
||||
constexpr vec_base()
|
||||
: x{0}, y{0}, z{0} {}
|
||||
|
||||
constexpr explicit vec_base(uninit_t) {}
|
||||
|
||||
constexpr explicit vec_base(T v)
|
||||
: x{v}, y{v}, z{v} {}
|
||||
@@ -91,12 +94,12 @@ namespace vmath_hpp::detail
|
||||
template < typename T >
|
||||
class vec_base<T, 4> {
|
||||
public:
|
||||
T x = T{0};
|
||||
T y = T{0};
|
||||
T z = T{0};
|
||||
T w = T{0};
|
||||
T x, y, z, w;
|
||||
public:
|
||||
constexpr vec_base() = default;
|
||||
constexpr vec_base()
|
||||
: x{0}, y{0}, z{0}, w{0} {}
|
||||
|
||||
constexpr explicit vec_base(uninit_t) {}
|
||||
|
||||
constexpr explicit vec_base(T v)
|
||||
: x{v}, y{v}, z{v}, w{v} {}
|
||||
@@ -177,10 +180,6 @@ namespace vmath_hpp
|
||||
using base_type::vec_base;
|
||||
using base_type::operator[];
|
||||
|
||||
constexpr vec() = default;
|
||||
constexpr vec(const vec&) = default;
|
||||
constexpr vec& operator=(const vec&) = default;
|
||||
|
||||
void swap(vec& other) noexcept(std::is_nothrow_swappable_v<T>) {
|
||||
for ( std::size_t i = 0; i < Size; ++i ) {
|
||||
using std::swap;
|
||||
|
||||
@@ -40,6 +40,22 @@ TEST_CASE("vmath/mat") {
|
||||
}
|
||||
|
||||
SUBCASE("ctors") {
|
||||
{
|
||||
mat<int, 2> m2;
|
||||
CHECK(m2.rows[0] == int2(1,0));
|
||||
CHECK(m2.rows[1] == int2(0,1));
|
||||
|
||||
mat<int, 3> m3;
|
||||
CHECK(m3.rows[0] == int3(1,0,0));
|
||||
CHECK(m3.rows[1] == int3(0,1,0));
|
||||
CHECK(m3.rows[2] == int3(0,0,1));
|
||||
|
||||
mat<int, 4> m4;
|
||||
CHECK(m4.rows[0] == int4(1,0,0,0));
|
||||
CHECK(m4.rows[1] == int4(0,1,0,0));
|
||||
CHECK(m4.rows[2] == int4(0,0,1,0));
|
||||
CHECK(m4.rows[3] == int4(0,0,0,1));
|
||||
}
|
||||
{
|
||||
STATIC_CHECK(int2x2()[0] == int2(1,0));
|
||||
STATIC_CHECK(int2x2()[1] == int2(0,1));
|
||||
|
||||
@@ -30,6 +30,11 @@ TEST_CASE("vmath/qua") {
|
||||
}
|
||||
|
||||
SUBCASE("ctors") {
|
||||
{
|
||||
qua<int> q;
|
||||
CHECK(q.v == int3(0,0,0));
|
||||
CHECK(q.s == 1);
|
||||
}
|
||||
{
|
||||
STATIC_CHECK(qfloat{}.v == uapprox3(0.f));
|
||||
STATIC_CHECK(qfloat{}.s == uapprox(1.f));
|
||||
|
||||
@@ -40,6 +40,22 @@ TEST_CASE("vmath/vec") {
|
||||
}
|
||||
|
||||
SUBCASE("ctors") {
|
||||
{
|
||||
vec<int, 2> i2;
|
||||
CHECK(i2.x == 0);
|
||||
CHECK(i2.y == 0);
|
||||
|
||||
vec<int, 3> i3;
|
||||
CHECK(i3.x == 0);
|
||||
CHECK(i3.y == 0);
|
||||
CHECK(i3.z == 0);
|
||||
|
||||
vec<int, 4> i4;
|
||||
CHECK(i4.x == 0);
|
||||
CHECK(i4.y == 0);
|
||||
CHECK(i4.z == 0);
|
||||
CHECK(i4.w == 0);
|
||||
}
|
||||
{
|
||||
STATIC_CHECK(int2().x == 0);
|
||||
STATIC_CHECK(int2().y == 0);
|
||||
|
||||
Reference in New Issue
Block a user