mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-14 20:31:25 +07:00
qua without fold details
This commit is contained in:
@@ -77,7 +77,7 @@ namespace vmath_hpp::detail
|
|||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
[[nodiscard]] std::size_t hash(const qua<T>& q) noexcept {
|
[[nodiscard]] std::size_t hash(const qua<T>& q) noexcept {
|
||||||
return fold_join(hash_combiner{}, std::size_t{}, q);
|
return hash(vec{q});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ namespace vmath_hpp
|
|||||||
|
|
||||||
template < typename To, typename From >
|
template < typename To, typename From >
|
||||||
[[nodiscard]] constexpr qua<To> cast_to(const qua<From>& q) {
|
[[nodiscard]] constexpr qua<To> cast_to(const qua<From>& q) {
|
||||||
return detail::map_join([](From x){ return cast_to<To>(x); }, q);
|
return qua(cast_to<To>(vec{q}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,57 +11,15 @@
|
|||||||
#include "vmath_vec.hpp"
|
#include "vmath_vec.hpp"
|
||||||
#include "vmath_vec_fun.hpp"
|
#include "vmath_vec_fun.hpp"
|
||||||
|
|
||||||
namespace vmath_hpp::detail
|
|
||||||
{
|
|
||||||
template < typename T >
|
|
||||||
class qua_base {
|
|
||||||
public:
|
|
||||||
T x{0}, y{0}, z{0}, w{1};
|
|
||||||
public:
|
|
||||||
constexpr qua_base() = default;
|
|
||||||
|
|
||||||
constexpr explicit qua_base(T w)
|
|
||||||
: x{0}, y{0}, z{0}, w{w} {}
|
|
||||||
|
|
||||||
constexpr qua_base(T x, T y, T z, T w)
|
|
||||||
: x{x}, y{y}, z{z}, w{w} {}
|
|
||||||
|
|
||||||
constexpr qua_base(const vec<T, 3>& xyz, T w)
|
|
||||||
: x{xyz[0]}, y{xyz[1]}, z{xyz[2]}, w{w} {}
|
|
||||||
|
|
||||||
constexpr qua_base(const vec<T, 4>& xyzw)
|
|
||||||
: x{xyzw[0]}, y{xyzw[1]}, z{xyzw[2]}, w{xyzw[3]} {}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr T& operator[](std::size_t index) noexcept {
|
|
||||||
switch ( index ) {
|
|
||||||
default:
|
|
||||||
case 0: return x;
|
|
||||||
case 1: return y;
|
|
||||||
case 2: return z;
|
|
||||||
case 3: return w;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr const T& operator[](std::size_t index) const noexcept {
|
|
||||||
switch ( index ) {
|
|
||||||
default:
|
|
||||||
case 0: return x;
|
|
||||||
case 1: return y;
|
|
||||||
case 2: return z;
|
|
||||||
case 3: return w;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace vmath_hpp
|
namespace vmath_hpp
|
||||||
{
|
{
|
||||||
template < typename T >
|
template < typename T >
|
||||||
class qua final : public detail::qua_base<T> {
|
class qua final {
|
||||||
|
public:
|
||||||
|
vec<T, 3> v{0};
|
||||||
|
T s{1};
|
||||||
public:
|
public:
|
||||||
using self_type = qua;
|
using self_type = qua;
|
||||||
using base_type = detail::qua_base<T>;
|
|
||||||
public:
|
|
||||||
using component_type = T;
|
using component_type = T;
|
||||||
|
|
||||||
using pointer = component_type*;
|
using pointer = component_type*;
|
||||||
@@ -77,13 +35,26 @@ namespace vmath_hpp
|
|||||||
|
|
||||||
static constexpr std::size_t size = 4;
|
static constexpr std::size_t size = 4;
|
||||||
public:
|
public:
|
||||||
using base_type::qua_base;
|
|
||||||
using base_type::operator[];
|
|
||||||
|
|
||||||
constexpr qua() = default;
|
constexpr qua() = default;
|
||||||
constexpr qua(const qua&) = default;
|
constexpr qua(const qua&) = default;
|
||||||
constexpr qua& operator=(const qua&) = default;
|
constexpr qua& operator=(const qua&) = default;
|
||||||
|
|
||||||
|
constexpr qua(T vx, T vy, T vz, T s)
|
||||||
|
: v{vx, vy, vz}
|
||||||
|
, s{s} {}
|
||||||
|
|
||||||
|
constexpr qua(const vec<T, 3>& v, T s)
|
||||||
|
: v{v}
|
||||||
|
, s{s} {}
|
||||||
|
|
||||||
|
constexpr explicit qua(const vec<T, 4>& vs)
|
||||||
|
: v{vs[0], vs[1], vs[2]}
|
||||||
|
, s{vs[3]} {}
|
||||||
|
|
||||||
|
constexpr explicit operator vec<T, 4>() const {
|
||||||
|
return {(*this).v, (*this).s};
|
||||||
|
}
|
||||||
|
|
||||||
void swap(qua& other) noexcept(std::is_nothrow_swappable_v<T>) {
|
void swap(qua& other) noexcept(std::is_nothrow_swappable_v<T>) {
|
||||||
for ( std::size_t i = 0; i < size; ++i ) {
|
for ( std::size_t i = 0; i < size; ++i ) {
|
||||||
using std::swap;
|
using std::swap;
|
||||||
@@ -114,6 +85,26 @@ namespace vmath_hpp
|
|||||||
return &(*this)[0];
|
return &(*this)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr reference operator[](std::size_t index) noexcept {
|
||||||
|
switch ( index ) {
|
||||||
|
default:
|
||||||
|
case 0: return v.x;
|
||||||
|
case 1: return v.y;
|
||||||
|
case 2: return v.z;
|
||||||
|
case 3: return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr const_reference operator[](std::size_t index) const noexcept {
|
||||||
|
switch ( index ) {
|
||||||
|
default:
|
||||||
|
case 0: return v.x;
|
||||||
|
case 1: return v.y;
|
||||||
|
case 2: return v.z;
|
||||||
|
case 3: return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr reference at(std::size_t index) {
|
[[nodiscard]] constexpr reference at(std::size_t index) {
|
||||||
if ( index >= size ) {
|
if ( index >= size ) {
|
||||||
throw std::out_of_range("qua::at");
|
throw std::out_of_range("qua::at");
|
||||||
@@ -132,10 +123,12 @@ namespace vmath_hpp
|
|||||||
|
|
||||||
namespace vmath_hpp
|
namespace vmath_hpp
|
||||||
{
|
{
|
||||||
// qua
|
// vec
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
qua(T) -> qua<T>;
|
vec(const qua<T>&) -> vec<T, 4>;
|
||||||
|
|
||||||
|
// qua
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
qua(T, T, T, T) -> qua<T>;
|
qua(T, T, T, T) -> qua<T>;
|
||||||
|
|||||||
@@ -11,153 +11,8 @@
|
|||||||
#include "vmath_fun.hpp"
|
#include "vmath_fun.hpp"
|
||||||
#include "vmath_qua.hpp"
|
#include "vmath_qua.hpp"
|
||||||
|
|
||||||
namespace vmath_hpp::detail::impl
|
#include "vmath_vec.hpp"
|
||||||
{
|
#include "vmath_vec_fun.hpp"
|
||||||
template < typename A, typename F, std::size_t... Is >
|
|
||||||
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
|
|
||||||
auto map_join_impl(
|
|
||||||
F&& f,
|
|
||||||
const qua<A>& a,
|
|
||||||
std::index_sequence<Is...>
|
|
||||||
) -> qua<decltype(f(
|
|
||||||
std::declval<A>()))>
|
|
||||||
{
|
|
||||||
return { f(a[Is])... };
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename A, typename B, typename F, std::size_t... Is >
|
|
||||||
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
|
|
||||||
auto map_join_impl(
|
|
||||||
F&& f,
|
|
||||||
const qua<A>& a,
|
|
||||||
const qua<B>& b,
|
|
||||||
std::index_sequence<Is...>
|
|
||||||
) -> qua<decltype(f(
|
|
||||||
std::declval<A>(),
|
|
||||||
std::declval<B>()))>
|
|
||||||
{
|
|
||||||
return { f(a[Is], b[Is])... };
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename A, typename B, typename C, typename F, std::size_t... Is >
|
|
||||||
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
|
|
||||||
auto map_join_impl(
|
|
||||||
F&& f,
|
|
||||||
const qua<A>& a,
|
|
||||||
const qua<B>& b,
|
|
||||||
const qua<C>& c,
|
|
||||||
std::index_sequence<Is...>
|
|
||||||
) -> qua<decltype(f(
|
|
||||||
std::declval<A>(),
|
|
||||||
std::declval<B>(),
|
|
||||||
std::declval<C>()))>
|
|
||||||
{
|
|
||||||
return { f(a[Is], b[Is], c[Is])... };
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename A, typename B, typename F, std::size_t... Is >
|
|
||||||
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
|
|
||||||
auto fold_join_impl(
|
|
||||||
F&& f,
|
|
||||||
A init,
|
|
||||||
const qua<B>& b,
|
|
||||||
std::index_sequence<Is...>
|
|
||||||
) -> A {
|
|
||||||
return ((init = f(std::move(init), b[Is])), ...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename A, typename B, typename C, typename F, std::size_t... Is >
|
|
||||||
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
|
|
||||||
auto fold_join_impl(
|
|
||||||
F&& f,
|
|
||||||
A init,
|
|
||||||
const qua<B>& b,
|
|
||||||
const qua<C>& c,
|
|
||||||
std::index_sequence<Is...>
|
|
||||||
) -> A {
|
|
||||||
return ((init = f(std::move(init), b[Is], c[Is])), ...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename A, typename F, std::size_t I, std::size_t... Is >
|
|
||||||
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
|
|
||||||
auto fold1_join_impl(
|
|
||||||
F&& f,
|
|
||||||
const qua<A>& a,
|
|
||||||
std::index_sequence<I, Is...>
|
|
||||||
) -> A {
|
|
||||||
A init = a[I];
|
|
||||||
return ((init = f(std::move(init), a[Is])), ...);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace vmath_hpp::detail
|
|
||||||
{
|
|
||||||
template < typename A, typename F >
|
|
||||||
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
|
|
||||||
auto map_join(
|
|
||||||
F&& f,
|
|
||||||
const qua<A>& a
|
|
||||||
) {
|
|
||||||
return impl::map_join_impl(
|
|
||||||
std::forward<F>(f), a, std::make_index_sequence<4>{});
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename A, typename B, typename F >
|
|
||||||
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
|
|
||||||
auto map_join(
|
|
||||||
F&& f,
|
|
||||||
const qua<A>& a,
|
|
||||||
const qua<B>& b
|
|
||||||
) {
|
|
||||||
return impl::map_join_impl(
|
|
||||||
std::forward<F>(f), a, b, std::make_index_sequence<4>{});
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename A, typename B, typename C, typename F >
|
|
||||||
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
|
|
||||||
auto map_join(
|
|
||||||
F&& f,
|
|
||||||
const qua<A>& a,
|
|
||||||
const qua<B>& b,
|
|
||||||
const qua<C>& c
|
|
||||||
) {
|
|
||||||
return impl::map_join_impl(
|
|
||||||
std::forward<F>(f), a, b, c, std::make_index_sequence<4>{});
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename A, typename B, typename F >
|
|
||||||
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
|
|
||||||
auto fold_join(
|
|
||||||
F&& f,
|
|
||||||
A init,
|
|
||||||
const qua<B>& b
|
|
||||||
) {
|
|
||||||
return impl::fold_join_impl(
|
|
||||||
std::forward<F>(f), std::move(init), b, std::make_index_sequence<4>{});
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename A, typename B, typename C, typename F >
|
|
||||||
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
|
|
||||||
auto fold_join(
|
|
||||||
F&& f,
|
|
||||||
A init,
|
|
||||||
const qua<B>& b,
|
|
||||||
const qua<C>& c
|
|
||||||
) {
|
|
||||||
return impl::fold_join_impl(
|
|
||||||
std::forward<F>(f), std::move(init), b, c, std::make_index_sequence<4>{});
|
|
||||||
}
|
|
||||||
|
|
||||||
template < typename A, typename F >
|
|
||||||
[[nodiscard]] constexpr VMATH_HPP_FORCE_INLINE
|
|
||||||
auto fold1_join(
|
|
||||||
F&& f,
|
|
||||||
const qua<A>& a
|
|
||||||
) {
|
|
||||||
return impl::fold1_join_impl(
|
|
||||||
std::forward<F>(f), a, std::make_index_sequence<4>{});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Operators
|
// Operators
|
||||||
@@ -176,14 +31,14 @@ namespace vmath_hpp
|
|||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
[[nodiscard]] constexpr qua<T> operator-(const qua<T>& xs) {
|
[[nodiscard]] constexpr qua<T> operator-(const qua<T>& xs) {
|
||||||
return map_join([](T x){ return -x; }, xs);
|
return qua(-vec<T, 4>{xs});
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator+
|
// operator+
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
[[nodiscard]] constexpr qua<T> operator+(const qua<T>& xs, const qua<T>& ys) {
|
[[nodiscard]] constexpr qua<T> operator+(const qua<T>& xs, const qua<T>& ys) {
|
||||||
return map_join([](T x, T y){ return x + y; }, xs, ys);
|
return qua(vec{xs} + vec{ys});
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator+=
|
// operator+=
|
||||||
@@ -197,7 +52,7 @@ namespace vmath_hpp
|
|||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
[[nodiscard]] constexpr qua<T> operator-(const qua<T>& xs, const qua<T>& ys) {
|
[[nodiscard]] constexpr qua<T> operator-(const qua<T>& xs, const qua<T>& ys) {
|
||||||
return map_join([](T x, T y){ return x - y; }, xs, ys);
|
return qua(vec{xs} - vec{ys});
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator-=
|
// operator-=
|
||||||
@@ -211,32 +66,23 @@ namespace vmath_hpp
|
|||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
[[nodiscard]] constexpr bool operator==(const qua<T>& xs, const qua<T>& ys) {
|
[[nodiscard]] constexpr bool operator==(const qua<T>& xs, const qua<T>& ys) {
|
||||||
return fold_join([](bool acc, T x, T y){
|
return vec{xs} == vec{ys};
|
||||||
return acc && x == y;
|
|
||||||
}, true, xs, ys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator!=
|
// operator!=
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
[[nodiscard]] constexpr bool operator!=(const qua<T>& xs, const qua<T>& ys) {
|
[[nodiscard]] constexpr bool operator!=(const qua<T>& xs, const qua<T>& ys) {
|
||||||
return fold_join([](bool acc, T x, T y){
|
return vec{xs} != vec{ys};
|
||||||
return acc || x != y;
|
|
||||||
}, false, xs, ys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator<
|
// operator<
|
||||||
|
|
||||||
template < typename T >
|
template < typename T >
|
||||||
[[nodiscard]] constexpr bool operator<(const qua<T>& xs, const qua<T>& ys) {
|
[[nodiscard]] constexpr bool operator<(const qua<T>& xs, const qua<T>& ys) {
|
||||||
for ( std::size_t i = 0; i < 4; ++i ) {
|
return vec{xs} < vec{ys};
|
||||||
if ( xs[i] < ys[i] ) {
|
}
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
if ( ys[i] < xs[i] ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,32 +14,6 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("vmath/qua_fun") {
|
TEST_CASE("vmath/qua_fun") {
|
||||||
SUBCASE("Detail") {
|
|
||||||
STATIC_REQUIRE(map_join([](const int& x){
|
|
||||||
return x * 2;
|
|
||||||
}, qua(1,2,3,4)) == qua(2,4,6,8));
|
|
||||||
|
|
||||||
STATIC_REQUIRE(map_join([](const int& x, const int& y){
|
|
||||||
return x + y;
|
|
||||||
}, qua(1,2,3,4), qua(2,3,4,5)) == qua(3,5,7,9));
|
|
||||||
|
|
||||||
STATIC_REQUIRE(map_join([](const int& x, const int& y, const int& z){
|
|
||||||
return x + y + z;
|
|
||||||
}, qua(1,2,3,4), qua(2,3,4,5), qua(3,4,5,6)) == qua(6,9,12,15));
|
|
||||||
|
|
||||||
STATIC_REQUIRE(fold_join([](int acc, const int& x){
|
|
||||||
return acc + x;
|
|
||||||
}, 0, qua(1,2,3,4)) == 10);
|
|
||||||
|
|
||||||
STATIC_REQUIRE(fold_join([](int acc, const int& x, const int& y){
|
|
||||||
return acc + x + y;
|
|
||||||
}, 0, qua(1,2,3,4), qua(2,3,4,5)) == 24);
|
|
||||||
|
|
||||||
STATIC_REQUIRE(fold1_join([](const int& acc, const int& x){
|
|
||||||
return acc + x;
|
|
||||||
}, qua{1,2,3,4}) == 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
SUBCASE("Operators") {
|
SUBCASE("Operators") {
|
||||||
STATIC_REQUIRE(+qua(1,-2,3,-4) == qua(1,-2,3,-4));
|
STATIC_REQUIRE(+qua(1,-2,3,-4) == qua(1,-2,3,-4));
|
||||||
STATIC_REQUIRE(-qua(1,-2,3,-4) == qua(-1,2,-3,4));
|
STATIC_REQUIRE(-qua(1,-2,3,-4) == qua(-1,2,-3,4));
|
||||||
|
|||||||
@@ -23,35 +23,26 @@ TEST_CASE("vmath/qua") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SUBCASE("guides") {
|
SUBCASE("guides") {
|
||||||
STATIC_REQUIRE(qua{1}.size == 4);
|
|
||||||
STATIC_REQUIRE(qua{1,2,3,4}.size == 4);
|
STATIC_REQUIRE(qua{1,2,3,4}.size == 4);
|
||||||
STATIC_REQUIRE(qua{{1,2,3},4}.size == 4);
|
STATIC_REQUIRE(qua{{1,2,3},4}.size == 4);
|
||||||
STATIC_REQUIRE(qua{vec{1,2,3},4}.size == 4);
|
STATIC_REQUIRE(qua{vec{1,2,3},4}.size == 4);
|
||||||
STATIC_REQUIRE(qua{{1,2,3,4}}.size == 4);
|
STATIC_REQUIRE(qua{{1,2,3,4}}.size == 4);
|
||||||
STATIC_REQUIRE(qua{vec{1,2,3,4}}.size == 4);
|
STATIC_REQUIRE(qua(vec{1,2,3,4}).size == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
SUBCASE("ctors") {
|
SUBCASE("ctors") {
|
||||||
{
|
{
|
||||||
STATIC_REQUIRE(fqua{}.x == 0.f);
|
STATIC_REQUIRE(fqua{}.v == uapprox3(0.f));
|
||||||
STATIC_REQUIRE(fqua{}.y == 0.f);
|
STATIC_REQUIRE(fqua{}.s == uapprox(1.f));
|
||||||
STATIC_REQUIRE(fqua{}.z == 0.f);
|
|
||||||
STATIC_REQUIRE(fqua{}.w == 1.f);
|
|
||||||
|
|
||||||
STATIC_REQUIRE(fqua{1,2,3,4}.x == 1.f);
|
STATIC_REQUIRE(fqua{1,2,3,4}.v == uapprox3(1.f,2.f,3.f));
|
||||||
STATIC_REQUIRE(fqua{1,2,3,4}.y == 2.f);
|
STATIC_REQUIRE(fqua{1,2,3,4}.s == uapprox(4.f));
|
||||||
STATIC_REQUIRE(fqua{1,2,3,4}.z == 3.f);
|
|
||||||
STATIC_REQUIRE(fqua{1,2,3,4}.w == 4.f);
|
|
||||||
|
|
||||||
STATIC_REQUIRE(fqua{{1,2,3},4}.x == 1.f);
|
STATIC_REQUIRE(fqua{{1,2,3},4}.v == uapprox3(1.f,2.f,3.f));
|
||||||
STATIC_REQUIRE(fqua{{1,2,3},4}.y == 2.f);
|
STATIC_REQUIRE(fqua{{1,2,3},4}.s == uapprox(4.f));
|
||||||
STATIC_REQUIRE(fqua{{1,2,3},4}.z == 3.f);
|
|
||||||
STATIC_REQUIRE(fqua{{1,2,3},4}.w == 4.f);
|
|
||||||
|
|
||||||
STATIC_REQUIRE(fqua{{1,2,3,4}}.x == 1.f);
|
STATIC_REQUIRE(fqua{{1,2,3,4}}.v == uapprox3(1.f,2.f,3.f));
|
||||||
STATIC_REQUIRE(fqua{{1,2,3,4}}.y == 2.f);
|
STATIC_REQUIRE(fqua{{1,2,3,4}}.s == uapprox(4.f));
|
||||||
STATIC_REQUIRE(fqua{{1,2,3,4}}.z == 3.f);
|
|
||||||
STATIC_REQUIRE(fqua{{1,2,3,4}}.w == 4.f);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
constexpr fqua q(1,2,3,4);
|
constexpr fqua q(1,2,3,4);
|
||||||
@@ -64,9 +55,9 @@ TEST_CASE("vmath/qua") {
|
|||||||
STATIC_REQUIRE(q2 == fqua(1,2,3,4));
|
STATIC_REQUIRE(q2 == fqua(1,2,3,4));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
STATIC_REQUIRE(fqua(2) == fqua(0,0,0,2));
|
|
||||||
STATIC_REQUIRE(fqua(1,2,3,4) == fqua(1,2,3,4));
|
STATIC_REQUIRE(fqua(1,2,3,4) == fqua(1,2,3,4));
|
||||||
STATIC_REQUIRE(fqua(float3(1,2,3),4) == fqua(1,2,3,4));
|
STATIC_REQUIRE(fqua(float3(1,2,3),4) == fqua(1,2,3,4));
|
||||||
|
STATIC_REQUIRE(fqua(float4(1,2,3,4)) == fqua(1,2,3,4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,24 +176,20 @@ TEST_CASE("vmath/qua") {
|
|||||||
|
|
||||||
SUBCASE("operator[]") {
|
SUBCASE("operator[]") {
|
||||||
{
|
{
|
||||||
STATIC_REQUIRE(fqua(1,2,3,4).x == 1);
|
STATIC_REQUIRE(qua(1,2,3,4).v == vec(1,2,3));
|
||||||
STATIC_REQUIRE(fqua(1,2,3,4).y == 2);
|
STATIC_REQUIRE(qua(1,2,3,4).s == 4);
|
||||||
STATIC_REQUIRE(fqua(1,2,3,4).z == 3);
|
|
||||||
STATIC_REQUIRE(fqua(1,2,3,4).w == 4);
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
STATIC_REQUIRE(fqua(1,2,3,4)[0] == 1);
|
STATIC_REQUIRE(qua(1,2,3,4)[0] == 1);
|
||||||
STATIC_REQUIRE(fqua(1,2,3,4)[1] == 2);
|
STATIC_REQUIRE(qua(1,2,3,4)[1] == 2);
|
||||||
STATIC_REQUIRE(fqua(1,2,3,4)[2] == 3);
|
STATIC_REQUIRE(qua(1,2,3,4)[2] == 3);
|
||||||
STATIC_REQUIRE(fqua(1,2,3,4)[3] == 4);
|
STATIC_REQUIRE(qua(1,2,3,4)[3] == 4);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
fqua v;
|
qua<int> v;
|
||||||
v.x = 1;
|
v.v = vec(1,2,3);
|
||||||
v.y = 2;
|
v.s = 4;
|
||||||
v.z = 3;
|
REQUIRE(v == qua(1,2,3,4));
|
||||||
v.w = 4;
|
|
||||||
REQUIRE(v == fqua(1,2,3,4));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user