diff --git a/headers/vmath.hpp/vmath_fwd.hpp b/headers/vmath.hpp/vmath_fwd.hpp index 30ff35f..627567b 100644 --- a/headers/vmath.hpp/vmath_fwd.hpp +++ b/headers/vmath.hpp/vmath_fwd.hpp @@ -34,6 +34,14 @@ namespace vmath_hpp using vec2f = vec; using vec3f = vec; using vec4f = vec; + + using vec2d = vec; + using vec3d = vec; + using vec4d = vec; + + using vec2u = vec; + using vec3u = vec; + using vec4u = vec; } namespace vmath_hpp @@ -52,4 +60,12 @@ namespace vmath_hpp using mat2f = mat; using mat3f = mat; using mat4f = mat; + + using mat2d = mat; + using mat3d = mat; + using mat4d = mat; + + using mat2u = mat; + using mat3u = mat; + using mat4u = mat; } diff --git a/headers/vmath.hpp/vmath_mat.hpp b/headers/vmath.hpp/vmath_mat.hpp index 2acbdbd..6379025 100644 --- a/headers/vmath.hpp/vmath_mat.hpp +++ b/headers/vmath.hpp/vmath_mat.hpp @@ -171,17 +171,17 @@ namespace vmath_hpp } constexpr value_type& at(size_type index) { - if ( index < Size ) { - return rows[index]; + if ( index >= Size ) { + throw std::out_of_range("mat::at"); } - throw std::out_of_range("mat::at"); + return rows[index]; } constexpr const value_type& at(size_type index) const { - if ( index < Size ) { - return rows[index]; + if ( index >= Size ) { + throw std::out_of_range("mat::at"); } - throw std::out_of_range("mat::at"); + return rows[index]; } }; diff --git a/headers/vmath.hpp/vmath_vec.hpp b/headers/vmath.hpp/vmath_vec.hpp index 7f2afec..0486be1 100644 --- a/headers/vmath.hpp/vmath_vec.hpp +++ b/headers/vmath.hpp/vmath_vec.hpp @@ -28,10 +28,10 @@ namespace vmath_hpp::detail : data{x, y} {} constexpr explicit vec_base(const vec_base& xy) - : data{xy.x(), xy.y()} {} + : data{xy.data[0], xy.data[1]} {} constexpr explicit vec_base(const vec_base& xy) - : data{xy.x(), xy.y()} {} + : data{xy.data[0], xy.data[1]} {} constexpr T& x() noexcept { return data[0]; } constexpr const T& x() const noexcept { return data[0]; } @@ -54,11 +54,14 @@ namespace vmath_hpp::detail constexpr vec_base(T x, T y, T z) : data{x, y, z} {} - constexpr explicit vec_base(const vec_base& xy, T z) - : data{xy.x(), xy.y(), z} {} + constexpr vec_base(const vec_base& xy, T z) + : data{xy.data[0], xy.data[1], z} {} + + constexpr vec_base(T x, const vec_base& yz) + : data{x, yz.data[0], yz.data[1]} {} constexpr explicit vec_base(const vec_base& xyz) - : data{xyz.x(), xyz.y(), xyz.z()} {} + : data{xyz.data[0], xyz.data[1], xyz.data[2]} {} constexpr T& x() noexcept { return data[0]; } constexpr const T& x() const noexcept { return data[0]; } @@ -84,11 +87,23 @@ namespace vmath_hpp::detail constexpr vec_base(T x, T y, T z, T w) : data{x, y, z, w} {} - constexpr explicit vec_base(const vec_base& xy, T z, T w) - : data{xy.x(), xy.y(), z, w} {} + constexpr vec_base(const vec_base& xy, T z, T w) + : data{xy.data[0], xy.data[1], z, w} {} - constexpr explicit vec_base(const vec_base& xyz, T w) - : data{xyz.x(), xyz.y(), xyz.z(), w} {} + constexpr vec_base(T x, const vec_base& yz, T w) + : data{x, yz.data[0], yz.data[1], w} {} + + constexpr vec_base(T x, T y, const vec_base& zw) + : data{x, y, zw.data[0], zw.data[1]} {} + + constexpr vec_base(const vec_base& xy, const vec_base& zw) + : data{xy.data[0], xy.data[1], zw.data[0], zw.data[1]} {} + + constexpr vec_base(const vec_base& xyz, T w) + : data{xyz.data[0], xyz.data[1], xyz.data[2], w} {} + + constexpr vec_base(T x, const vec_base& yzw) + : data{x, yzw.data[0], yzw.data[1], yzw.data[2]} {} constexpr T& x() noexcept { return data[0]; } constexpr const T& x() const noexcept { return data[0]; } @@ -173,17 +188,17 @@ namespace vmath_hpp } constexpr reference at(size_type index) { - if ( index < Size ) { - return data[index]; + if ( index >= Size ) { + throw std::out_of_range("vec::at"); } - throw std::out_of_range("vec::at"); + return data[index]; } constexpr const_reference at(size_type index) const { - if ( index < Size ) { - return data[index]; + if ( index >= Size ) { + throw std::out_of_range("vec::at"); } - throw std::out_of_range("vec::at"); + return data[index]; } }; diff --git a/untests/vmath_vec_tests.cpp b/untests/vmath_vec_tests.cpp index 6ba6642..18534d9 100644 --- a/untests/vmath_vec_tests.cpp +++ b/untests/vmath_vec_tests.cpp @@ -44,14 +44,27 @@ TEST_CASE("vmath/vec") { STATIC_REQUIRE(v2 == vec2i(1,2)); } { + STATIC_REQUIRE(vec2i(1) == vec2i(1,1)); + STATIC_REQUIRE(vec2i(1,2) == vec2i(1,2)); + STATIC_REQUIRE(vec2i(vec2i(1,2)) == vec2i(1,2)); STATIC_REQUIRE(vec2i(vec3i(1,2,3)) == vec2i(1,2)); STATIC_REQUIRE(vec2i(vec4i(1,2,3,4)) == vec2i(1,2)); + STATIC_REQUIRE(vec3i(1) == vec3i(1,1,1)); + STATIC_REQUIRE(vec3i(1,2,3) == vec3i(1,2,3)); STATIC_REQUIRE(vec3i(vec2i(1,2),3) == vec3i(1,2,3)); + STATIC_REQUIRE(vec3i(1,vec2i(2,3)) == vec3i(1,2,3)); + STATIC_REQUIRE(vec3i(vec3i(1,2,3)) == vec3i(1,2,3)); STATIC_REQUIRE(vec3i(vec4i(1,2,3,4)) == vec3i(1,2,3)); + STATIC_REQUIRE(vec4i(1) == vec4i(1,1,1,1)); + STATIC_REQUIRE(vec4i(1,2,3,4) == vec4i(1,2,3,4)); STATIC_REQUIRE(vec4i(vec2i(1,2),3,4) == vec4i(1,2,3,4)); + STATIC_REQUIRE(vec4i(1,vec2i(2,3),4) == vec4i(1,2,3,4)); + STATIC_REQUIRE(vec4i(1,2,vec2i(3,4)) == vec4i(1,2,3,4)); + STATIC_REQUIRE(vec4i(vec2i(1,2),vec2i(3,4)) == vec4i(1,2,3,4)); STATIC_REQUIRE(vec4i(vec3i(1,2,3),4) == vec4i(1,2,3,4)); + STATIC_REQUIRE(vec4i(1,vec3i(2,3,4)) == vec4i(1,2,3,4)); } }