Commit 1296d248 authored by Aaron Grabowy's avatar Aaron Grabowy
Browse files

Updated from develop

parents 24aa8407 3bfbb704
......@@ -5,6 +5,10 @@
namespace
{
struct assertion_not_handled
{
};
using assertion_handler_t = void (*)(tg::detail::assertion_info const&);
thread_local assertion_handler_t s_current_handler = nullptr;
......@@ -28,6 +32,8 @@ void tg::detail::assertion_failed(assertion_info const& info)
s_current_handler(info);
else
default_assertion_handler(info);
throw assertion_not_handled{};
}
void tg::set_assertion_handler(void (*handler)(detail::assertion_info const&)) { s_current_handler = handler; }
#pragma once
#include <typed-geometry/types/size.hh>
#include <typed-geometry/detail/macros.hh>
#include <typed-geometry/detail/scalar_traits.hh>
#include <typed-geometry/types/size.hh>
namespace tg
{
......
#pragma once
#include <typed-geometry/detail/scalar_traits.hh>
#include <typed-geometry/types/objects/triangle.hh>
#include <typed-geometry/types/size.hh>
#include <typed-geometry/detail/scalar_traits.hh>
namespace tg
{
......
#pragma once
#include <typed-geometry/types/size.hh>
#include <typed-geometry/types/vec.hh>
#include <typed-geometry/detail/macros.hh>
#include <typed-geometry/detail/scalar_traits.hh>
#include <typed-geometry/types/size.hh>
#include <typed-geometry/types/vec.hh>
namespace tg
{
......
#pragma once
#include <typed-geometry/feature/assert.hh>
#include <typed-geometry/detail/utility.hh>
#include <typed-geometry/feature/assert.hh>
namespace tg
{
......
......@@ -45,7 +45,7 @@ struct assertion_info
int line;
};
TG_COLD_FUNC TG_DONT_INLINE void assertion_failed(assertion_info const& info);
[[noreturn]] TG_COLD_FUNC TG_DONT_INLINE void assertion_failed(assertion_info const& info);
}
} // namespace tg
......
#pragma once
#include <typed-geometry/functions/random/random.hh>
#include <typed-geometry/functions/random/gaussian.hh>
#include <typed-geometry/functions/random/random.hh>
#include <typed-geometry/functions/random/random_choice.hh>
#include <typed-geometry/functions/random/uniform.hh>
......@@ -27,10 +27,26 @@ static constexpr T nan = NAN;
template <class T>
static constexpr T inf = INFINITY;
// Workaround for compiler discrepancies when using `static` or `inline` on variable template specializations
namespace detail
{
template <class T>
static constexpr T epsilon = type_error::unsupported_type<T>::value;
struct epsilon_t : type_error::unsupported_type<T>::value
{
};
template <>
constexpr float epsilon<float> = 1.19209290E-07F; // FLT_EPSILON
struct epsilon_t<float>
{
static constexpr float value = 1.19209290E-07F; // FLT_EPSILON
};
template <>
constexpr double epsilon<double> = 2.2204460492503131e-16; // DBL_EPSILON
struct epsilon_t<double>
{
static constexpr float value = 2.2204460492503131e-16; // DBL_EPSILON
};
}
template <class T>
static constexpr T epsilon = detail::epsilon_t<T>::value;
}
......@@ -12,7 +12,7 @@
namespace tg::detail
{
template<>
template <>
inline u128 mul(u64 lhs, u64 rhs)
{
u128 res;
......@@ -25,7 +25,7 @@ inline u128 mul(u64 lhs, u64 rhs)
return res;
}
template<>
template <>
inline u128 mul(u128 lhs, u64 rhs)
{
u128 res;
......@@ -40,7 +40,7 @@ inline u128 mul(u128 lhs, u64 rhs)
return res;
}
template<>
template <>
inline u128 mul(u64 lhs, u128 rhs)
{
u128 res;
......@@ -55,7 +55,7 @@ inline u128 mul(u64 lhs, u128 rhs)
return res;
}
template<>
template <>
inline u128 mul(u128 lhs, u128 rhs)
{
u128 res;
......@@ -72,7 +72,7 @@ inline u128 mul(u128 lhs, u128 rhs)
return res;
}
template<>
template <>
inline u192 mul(u128 lhs, u64 rhs)
{
u192 res;
......@@ -92,7 +92,7 @@ inline u192 mul(u128 lhs, u64 rhs)
return res;
}
template<>
template <>
inline u192 mul(u192 lhs, u64 rhs)
{
u192 res;
......@@ -114,7 +114,7 @@ inline u192 mul(u192 lhs, u64 rhs)
return res;
}
template<>
template <>
inline u192 mul(u64 lhs, u128 rhs)
{
u192 res;
......@@ -134,7 +134,7 @@ inline u192 mul(u64 lhs, u128 rhs)
return res;
}
template<>
template <>
inline u192 mul(u128 lhs, u128 rhs)
{
u192 res;
......@@ -160,7 +160,7 @@ inline u192 mul(u128 lhs, u128 rhs)
return res;
}
template<>
template <>
inline u192 mul(u192 lhs, u128 rhs)
{
u192 res;
......@@ -188,7 +188,7 @@ inline u192 mul(u192 lhs, u128 rhs)
return res;
}
template<>
template <>
inline u192 mul(u64 lhs, u192 rhs)
{
u192 res;
......@@ -210,7 +210,7 @@ inline u192 mul(u64 lhs, u192 rhs)
return res;
}
template<>
template <>
inline u192 mul(u128 lhs, u192 rhs)
{
u192 res;
......@@ -238,7 +238,7 @@ inline u192 mul(u128 lhs, u192 rhs)
return res;
}
template<>
template <>
inline u192 mul(u192 lhs, u192 rhs)
{
u192 res;
......@@ -268,7 +268,7 @@ inline u192 mul(u192 lhs, u192 rhs)
return res;
}
template<>
template <>
inline u256 mul(u192 lhs, u64 rhs)
{
u256 res;
......@@ -295,7 +295,7 @@ inline u256 mul(u192 lhs, u64 rhs)
return res;
}
template<>
template <>
inline u256 mul(u256 lhs, u64 rhs)
{
u256 res;
......@@ -324,7 +324,7 @@ inline u256 mul(u256 lhs, u64 rhs)
return res;
}
template<>
template <>
inline u256 mul(u128 lhs, u128 rhs)
{
u256 res;
......@@ -356,7 +356,7 @@ inline u256 mul(u128 lhs, u128 rhs)
return res;
}
template<>
template <>
inline u256 mul(u192 lhs, u128 rhs)
{
u256 res;
......@@ -394,7 +394,7 @@ inline u256 mul(u192 lhs, u128 rhs)
return res;
}
template<>
template <>
inline u256 mul(u256 lhs, u128 rhs)
{
u256 res;
......@@ -434,7 +434,7 @@ inline u256 mul(u256 lhs, u128 rhs)
return res;
}
template<>
template <>
inline u256 mul(u64 lhs, u192 rhs)
{
u256 res;
......@@ -461,7 +461,7 @@ inline u256 mul(u64 lhs, u192 rhs)
return res;
}
template<>
template <>
inline u256 mul(u128 lhs, u192 rhs)
{
u256 res;
......@@ -499,7 +499,7 @@ inline u256 mul(u128 lhs, u192 rhs)
return res;
}
template<>
template <>
inline u256 mul(u192 lhs, u192 rhs)
{
u256 res;
......@@ -543,7 +543,7 @@ inline u256 mul(u192 lhs, u192 rhs)
return res;
}
template<>
template <>
inline u256 mul(u256 lhs, u192 rhs)
{
u256 res;
......@@ -589,7 +589,7 @@ inline u256 mul(u256 lhs, u192 rhs)
return res;
}
template<>
template <>
inline u256 mul(u64 lhs, u256 rhs)
{
u256 res;
......@@ -618,7 +618,7 @@ inline u256 mul(u64 lhs, u256 rhs)
return res;
}
template<>
template <>
inline u256 mul(u128 lhs, u256 rhs)
{
u256 res;
......@@ -658,7 +658,7 @@ inline u256 mul(u128 lhs, u256 rhs)
return res;
}
template<>
template <>
inline u256 mul(u192 lhs, u256 rhs)
{
u256 res;
......@@ -704,7 +704,7 @@ inline u256 mul(u192 lhs, u256 rhs)
return res;
}
template<>
template <>
inline u256 mul(u256 lhs, u256 rhs)
{
u256 res;
......
#pragma once
#include <typed-geometry/functions/basic/scalar_math.hh>
#include <typed-geometry/detail/utility.hh>
#include <typed-geometry/functions/basic/scalar_math.hh>
#include <typed-geometry/types/mat.hh>
namespace tg
......
#pragma once
#include <typed-geometry/detail/operators/ops_mat.hh>
#include <typed-geometry/detail/scalar_traits.hh>
#include <typed-geometry/types/mat.hh>
#include <typed-geometry/types/vec.hh>
#include <typed-geometry/detail/operators/ops_mat.hh>
#include "determinant.hh"
namespace tg
......
......@@ -89,17 +89,23 @@ template <class ScalarT>
}
template <class ScalarT>
[[nodiscard]] constexpr mat<4, 4, ScalarT> look_at(pos<3, ScalarT> const& eye, dir<3, ScalarT> const& fwd, vec<3, ScalarT> const& ref_up)
[[deprecated("use explicit _opengl or _directx version")]] [[nodiscard]] constexpr mat<4, 4, ScalarT> look_at(pos<3, ScalarT> const& eye,
dir<3, ScalarT> const& fwd,
vec<3, ScalarT> const& ref_up)
{
return look_at_opengl(eye, fwd, ref_up);
}
template <class ScalarT>
[[nodiscard]] constexpr mat<4, 4, ScalarT> look_at(pos<3, ScalarT> const& eye, pos<3, ScalarT> const& target, vec<3, ScalarT> const& ref_up)
[[deprecated("use explicit _opengl or _directx version")]] [[nodiscard]] constexpr mat<4, 4, ScalarT> look_at(pos<3, ScalarT> const& eye,
pos<3, ScalarT> const& target,
vec<3, ScalarT> const& ref_up)
{
return look_at_opengl(eye, normalize(target - eye), ref_up);
}
template <class ScalarT>
[[nodiscard]] constexpr mat<4, 4, ScalarT> look_at(pos<3, ScalarT> const& eye, vec<3, ScalarT> const& fwd, vec<3, ScalarT> const& ref_up)
[[deprecated("use explicit _opengl or _directx version")]] [[nodiscard]] constexpr mat<4, 4, ScalarT> look_at(pos<3, ScalarT> const& eye,
vec<3, ScalarT> const& fwd,
vec<3, ScalarT> const& ref_up)
{
return look_at_opengl(eye, normalize(fwd), ref_up);
}
......
......@@ -18,4 +18,20 @@ mat<4, 4, T> orthographic(T left, T right, T bottom, T top, T zNear, T zFar)
m[3][3] = T(1);
return m;
}
// right-handed, xy: -1..1, z: 1..0
template <typename T>
mat<4, 4, T> orthographic_reverse_z(T left, T right, T bottom, T top, T zNear, T zFar)
{
mat<4, 4, T> m;
m[0][0] = T(2) / (right - left);
m[1][1] = T(2) / (top - bottom);
m[2][2] = T(1) / (zFar - zNear);
m[3][0] = -(right + left) / (right - left);
m[3][1] = -(top + bottom) / (top - bottom);
m[3][2] = zFar / (zFar - zNear);
m[3][3] = T(1);
return m;
}
}
......@@ -10,7 +10,7 @@ namespace tg
{
/// aspect ratio is width / height
template <class ScalarT>
[[nodiscard]] mat<4, 4, ScalarT> perspective_reverse_z(angle_t<ScalarT> horizontal_fov, ScalarT aspect_ratio, ScalarT near_plane)
[[nodiscard]] mat<4, 4, ScalarT> perspective_reverse_z_opengl(angle_t<ScalarT> horizontal_fov, ScalarT aspect_ratio, ScalarT near_plane)
{
TG_CONTRACT(near_plane > 0);
TG_CONTRACT(aspect_ratio > 0);
......@@ -31,6 +31,25 @@ template <class ScalarT>
return m;
}
template <class ScalarT>
[[nodiscard]] mat<4, 4, ScalarT> perspective_reverse_z_directx(angle_t<ScalarT> horizontal_fov, ScalarT aspect_ratio, ScalarT near_plane)
{
TG_CONTRACT(near_plane > 0);
TG_CONTRACT(aspect_ratio > 0);
TG_CONTRACT(horizontal_fov > degree(0));
TG_CONTRACT(horizontal_fov < degree(180));
auto const tan_half_hfov = tan(horizontal_fov / ScalarT(2));
auto m = mat<4, 4, ScalarT>::zero;
m[0][0] = ScalarT(1) / (aspect_ratio * tan_half_hfov);
m[1][1] = ScalarT(1) / tan_half_hfov;
m[2][3] = ScalarT(1);
m[3][2] = near_plane;
return m;
}
template <class ScalarT>
[[nodiscard]] mat<4, 4, ScalarT> perspective_directx(angle_t<ScalarT> horizontal_fov, ScalarT aspect_ratio, ScalarT near_plane, ScalarT far_plane)
{
......@@ -85,8 +104,19 @@ template <class ScalarT>
}
template <class ScalarT>
[[nodiscard]] mat<4, 4, ScalarT> perspective(angle_t<ScalarT> horizontal_fov, ScalarT aspect_ratio, ScalarT near_plane, ScalarT far_plane)
[[deprecated("use explicit _opengl or _directx version")]] [[nodiscard]] mat<4, 4, ScalarT> perspective(angle_t<ScalarT> horizontal_fov,
ScalarT aspect_ratio,
ScalarT near_plane,
ScalarT far_plane)
{
return perspective_opengl(horizontal_fov, aspect_ratio, near_plane, far_plane);
}
template <class ScalarT>
[[deprecated("use explicit _opengl or _directx version")]] [[nodiscard]] mat<4, 4, ScalarT> perspective_reverse_z(angle_t<ScalarT> horizontal_fov,
ScalarT aspect_ratio,
ScalarT near_plane)
{
return perspective_reverse_z_opengl(horizontal_fov, aspect_ratio, near_plane);
}
}
#pragma once
#include <typed-geometry/functions/vector/interpolate.hh>
#include <typed-geometry/functions/vector/distance.hh>
#include <typed-geometry/functions/tests/triangle_tests.hh>
#include <typed-geometry/functions/vector/distance.hh>
#include <typed-geometry/functions/vector/interpolate.hh>
#include <typed-geometry/types/objects/sphere.hh>
#include <typed-geometry/types/objects/triangle.hh>
......
......@@ -189,8 +189,7 @@ template <class ScalarT>
auto limit = eps;
if (eps != ScalarT(0))
{
auto aMax = abs(A0) >= abs(A1) ? (abs(A0) >= abs(A2) ? A0 : A2)
: (abs(A1) >= abs(A2) ? A1 : A2);
auto aMax = abs(A0) >= abs(A1) ? (abs(A0) >= abs(A2) ? A0 : A2) : (abs(A1) >= abs(A2) ? A1 : A2);
limit = -std::copysign(eps, aMax) * sign(eps);
}
......
......@@ -90,7 +90,7 @@ template <int D, class ScalarT>
auto res = p;
auto projectionNeeded = true;
auto closestDist = max<ScalarT>();
auto closestDim = 0; // Will be overwritten
auto closestDim = 0; // Will be overwritten
auto closestDimVal = ScalarT(0); // Will be overwritten
for (auto i = 0; i < D; ++i)
{
......
#pragma once
#include <typed-geometry/functions/objects/distance.hh>
#include <typed-geometry/types/objects/sphere.hh>
#include <typed-geometry/types/objects/triangle.hh>
namespace tg
{
template <class ScalarT>
[[nodiscard]] sphere<2, ScalarT> circumcircle(triangle<2, ScalarT> const& t)
{
auto const& a = t.pos0;
auto const& b = t.pos1;
auto const& c = t.pos2;
auto const d = ScalarT(2) * (a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y));
auto const a_len_sqr = distance_sqr_to_origin(a);
auto const b_len_sqr = distance_sqr_to_origin(b);
auto const c_len_sqr = distance_sqr_to_origin(c);
auto const x = (a_len_sqr * (b.y - c.y) + b_len_sqr * (c.y - a.y) + c_len_sqr * (a.y - b.y)) / d;
auto const y = (a_len_sqr * (c.x - b.x) + b_len_sqr * (a.x - c.x) + c_len_sqr * (b.x - a.x)) / d;
auto const center = pos<2, ScalarT>(x, y);
auto const r = distance(center, a);
return {center, r};
}
}
......@@ -5,6 +5,7 @@
#include <typed-geometry/functions/basic/constants.hh>
#include <typed-geometry/functions/basic/scalar_math.hh>
#include <typed-geometry/functions/basic/minmax.hh>
#include <typed-geometry/functions/vector/cross.hh>
#include <typed-geometry/functions/vector/dot.hh>
......@@ -31,7 +32,7 @@ template <int D, class ScalarT, class = enable_if<is_floating_point<ScalarT>>>
template <int D, class ScalarT>
[[nodiscard]] constexpr bool are_orthogonal(vec<D, ScalarT> const& a, vec<D, ScalarT> const& b, ScalarT eps = 100 * D * tg::epsilon<ScalarT>)
{
return abs(dot(a, b)) < eps;
return abs(dot(a, b)) < max(max_element(abs(a)), max_element(abs(b))) * eps;
}
template <int D, class ScalarT>
......
#pragma once
#include <typed-geometry/functions/basic/scalar_math.hh>
#include <typed-geometry/detail/operators/ops_vec.hh>
#include <typed-geometry/detail/scalar_traits.hh>
#include <typed-geometry/functions/basic/scalar_math.hh>
#include <typed-geometry/types/objects/segment.hh>
#include <typed-geometry/types/vec.hh>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment