/******************************************************************************* * This file is part of the "https://github.com/blackmatov/vmath.hpp" * For conditions of distribution and use, see copyright notice in LICENSE.md * Copyright (C) 2020, by Matvey Cherevko (blackmatov@gmail.com) ******************************************************************************/ #include #include #include namespace vmath_tests { using namespace vmath_hpp; template < typename T > inline constexpr T epsilon = std::numeric_limits::epsilon() * 100; template < typename T > struct approx { T value; explicit constexpr approx(T v) : value(v) {} }; template < typename T > struct approx2 { vec value; constexpr explicit approx2(T v) : value(v) {} constexpr explicit approx2(T x, T y) : value(x, y) {} constexpr explicit approx2(const vec& v) : value(v) {} }; template < typename T > struct approx3 { vec value; constexpr explicit approx3(T v) : value(v) {} constexpr explicit approx3(T x, T y, T z) : value(x, y, z) {} constexpr explicit approx3(const vec& v) : value(v) {} }; template < typename T > struct approx4 { vec value; constexpr explicit approx4(T v) : value(v) {} constexpr explicit approx4(T x, T y, T z, T w) : value(x, y, z, w) {} constexpr explicit approx4(const vec& v) : value(v) {} }; template < typename T > struct approx2x2 { mat value; constexpr explicit approx2x2(const mat& v) : value(v) {} }; template < typename T > struct approx3x3 { mat value; constexpr explicit approx3x3(const mat& v) : value(v) {} }; template < typename T > struct approx4x4 { mat value; constexpr explicit approx4x4(const mat& v) : value(v) {} }; // // // template < typename T > approx2(const vec&) -> approx2; template < typename T > approx3(const vec&) -> approx3; template < typename T > approx4(const vec&) -> approx4; template < typename T > approx2x2(const mat&) -> approx2x2; template < typename T > approx3x3(const mat&) -> approx3x3; template < typename T > approx4x4(const mat&) -> approx4x4; // // // template < typename T > constexpr bool operator==(const T& l, const approx& r) { return equal_to(l, r.value, epsilon); } template < typename T > constexpr bool operator==(const vec& l, const approx2& r) { return all(equal_to(l, r.value, epsilon)); } template < typename T > constexpr bool operator==(const vec& l, const approx3& r) { return all(equal_to(l, r.value, epsilon)); } template < typename T > constexpr bool operator==(const vec& l, const approx4& r) { return all(equal_to(l, r.value, epsilon)); } template < typename T > constexpr bool operator==(const mat& l, const approx2x2& r) { return l[0] == approx2(r.value[0]) && l[1] == approx2(r.value[1]); } template < typename T > constexpr bool operator==(const mat& l, const approx3x3& r) { return l[0] == approx3(r.value[0]) && l[1] == approx3(r.value[1]) && l[2] == approx3(r.value[2]); } template < typename T > constexpr bool operator==(const mat& l, const approx4x4& r) { return l[0] == approx4(r.value[0]) && l[1] == approx4(r.value[1]) && l[2] == approx4(r.value[2]) && l[3] == approx4(r.value[3]); } }