-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
156 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//====================================================================================================================== | ||
/* | ||
Kyosu - Complex Without Complexes | ||
Copyright : KYOSU Contributors & Maintainers | ||
SPDX-License-Identifier: BSL-1.0 | ||
*/ | ||
//====================================================================================================================== | ||
#pragma once | ||
|
||
#include <kyosu/details/invoke.hpp> | ||
|
||
namespace kyosu::tags | ||
{ | ||
struct callable_lerp : eve::elementwise | ||
{ | ||
using callable_tag_type = callable_lerp; | ||
|
||
KYOSU_DEFERS_CALLABLE(lerp_); | ||
|
||
static KYOSU_FORCEINLINE auto deferred_call(auto | ||
, eve::ordered_value auto const& v0 | ||
, eve::ordered_value auto const& v1 | ||
, eve::ordered_value auto const& t) noexcept | ||
{ | ||
return eve::lerp(v0, v1, t); | ||
} | ||
|
||
KYOSU_FORCEINLINE auto operator()(auto const& target0, auto const& target1, auto const & target2) const noexcept | ||
-> decltype(eve::tag_invoke(*this, target0, target1, target2)) | ||
{ | ||
return eve::tag_invoke(*this, target0, target1, target2); | ||
} | ||
|
||
template<typename... T> | ||
eve::unsupported_call<callable_lerp(T&&...)> operator()(T&&... x) const | ||
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete; | ||
}; | ||
} | ||
|
||
namespace kyosu | ||
{ | ||
//====================================================================================================================== | ||
//! @addtogroup functions | ||
//! @{ | ||
//! @var lerp | ||
//! @brief Computes the linear interpolation. | ||
//! | ||
//! **Defined in Header** | ||
//! | ||
//! @code | ||
//! #include <kyosu/functions.hpp> | ||
//! @endcode | ||
//! | ||
//! @groupheader{Callable Signatures} | ||
//! | ||
//! @code | ||
//! namespace kyosu | ||
//! { | ||
//! template<kyosu::concepts::cayley_dickson T0, kyosu::concepts::cayley_dickson T1 > constexpr auto lerp(T0 z0, T1, z1, auto eve::ordered_value t) noexcept; | ||
//! template<eve::ordered_value T0, kyosu::concepts::cayley_dickson T1> > constexpr auto lerp(T0 z0, T1, z1, auto eve::ordered_value t) noexcept; | ||
//! template<kyosu::concepts::cayley_dickson T0, eve::ordered_value T1 > constexpr auto lerp(T0 z0, T1, z1, auto eve::ordered_value t) noexcept; | ||
//! template<eve::ordered_value T0, ordered_value T1> > constexpr auto lerp(T0 z0, T1, z1, auto eve::ordered_value t) noexcept; | ||
///! } | ||
//! @endcode | ||
//! | ||
//! **Parameters** | ||
//! | ||
//! * `z0, z1` : Value to process. | ||
//! * `t` : floating value interpolation coefficient. | ||
//! | ||
//! **Return value** | ||
//! | ||
//! The value of the interpolation (or extrapolation) between `z0` and `z1` is returned. | ||
//! The call is semantically equivalent to `z0+t*(z1-z0)`. | ||
//! | ||
//! @groupheader{Example} | ||
//! | ||
//! @godbolt{doc/lerp.cpp} | ||
//! @} | ||
//====================================================================================================================== | ||
inline constexpr tags::callable_lerp lerp = {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//====================================================================================================================== | ||
/* | ||
Kyosu - Complex Without Complexes | ||
Copyright : KYOSU Contributors & Maintainers | ||
SPDX-License-Identifier: BSL-1.0 | ||
*/ | ||
//====================================================================================================================== | ||
#include <kyosu/kyosu.hpp> | ||
#include <test.hpp> | ||
|
||
TTS_CASE_WITH ( "Check kyosu::lerp over real" | ||
, kyosu::real_types | ||
, tts::generate(tts::between(-10,10) | ||
,tts::between(-10,10) | ||
,tts::between(0, 1) | ||
) | ||
) | ||
(auto r0, auto r1, auto t) | ||
{ | ||
TTS_EQUAL(kyosu::lerp(r0, r1, t), eve::lerp(r0, r1, t)); | ||
}; | ||
|
||
TTS_CASE_WITH ( "Check kyosu::lerp over complex" | ||
, kyosu::real_types | ||
, tts::generate(tts::between(-10,10), tts::between(-10,10) | ||
,tts::between(-10,10), tts::between(-10,10) | ||
,tts::between(0, 1) | ||
) | ||
) | ||
(auto r0, auto i0, auto r1, auto i1, auto t) | ||
{ | ||
auto c0 = kyosu::to_complex(r0,i0); | ||
auto c1 = kyosu::to_complex(r1,i1); | ||
TTS_RELATIVE_EQUAL(kyosu::lerp(c0, c1, t), c0+t*(c1-c0), 1e-7); | ||
}; | ||
|
||
TTS_CASE_WITH ( "Check kyosu::lerp over quaternion" | ||
, kyosu::real_types | ||
, tts::generate ( tts::between(-10,10), tts::between(-10,10) | ||
, tts::between(-10,10), tts::between(-10,10) | ||
, tts::between(-10,10), tts::between(-10,10) | ||
, tts::between(-10,10), tts::between(-10,10) | ||
,tts::between(0, 1) | ||
) | ||
) | ||
<typename T>(T r0, T i0, T j0, T k0, T r1, T i1, T j1, T k1, auto t) | ||
{ | ||
using type = kyosu::as_quaternion_t<T>; | ||
auto q0 = type(r0,i0,j0,k0); | ||
auto q1 = type(r1,i1,j1,k1); | ||
TTS_RELATIVE_EQUAL(kyosu::lerp(q0, q1, t), q0+t*(q1-q0) , 1e-7); | ||
}; |