Skip to content

Commit

Permalink
Implements a bunch of quaternion-specific functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jtlap committed Sep 10, 2023
1 parent cc1b64c commit 03915e5
Show file tree
Hide file tree
Showing 67 changed files with 4,241 additions and 105 deletions.
80 changes: 0 additions & 80 deletions include/kyosu/cayley.hpp

This file was deleted.

42 changes: 34 additions & 8 deletions include/kyosu/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
#include <kyosu/functions/csch.hpp>
#include <kyosu/functions/dec.hpp>
#include <kyosu/functions/dist.hpp>
#include <kyosu/functions/dot.hpp>
#include <kyosu/functions/exp.hpp>
#include <kyosu/functions/exp2.hpp>
#include <kyosu/functions/exp10.hpp>
#include <kyosu/functions/exp2.hpp>
#include <kyosu/functions/exp_i.hpp>
#include <kyosu/functions/exp_ipi.hpp>
#include <kyosu/functions/expm1.hpp>
#include <kyosu/functions/expmx2.hpp>
#include <kyosu/functions/expx2.hpp>
#include <kyosu/functions/exp_i.hpp>
#include <kyosu/functions/exp_ipi.hpp>
#include <kyosu/functions/floor.hpp>
#include <kyosu/functions/frac.hpp>
#include <kyosu/functions/hypot.hpp>
Expand All @@ -55,25 +56,25 @@
#include <kyosu/functions/is_not_nan.hpp>
#include <kyosu/functions/is_not_real.hpp>
#include <kyosu/functions/is_real.hpp>
#include <kyosu/functions/is_unitary.hpp>
#include <kyosu/functions/jpart.hpp>
#include <kyosu/functions/kpart.hpp>
#include <kyosu/functions/lerp.hpp>
#include <kyosu/functions/log.hpp>
#include <kyosu/functions/log_abs.hpp>
#include <kyosu/functions/log1p.hpp>
#include <kyosu/functions/log10.hpp>
#include <kyosu/functions/log1p.hpp>
#include <kyosu/functions/log_abs.hpp>
#include <kyosu/functions/log2.hpp>
#include <kyosu/functions/lpnorm.hpp>
#include <kyosu/functions/manhattan.hpp>
#include <kyosu/functions/minus.hpp>
#include <kyosu/functions/nearest.hpp>
#include <kyosu/functions/oneminus.hpp>
#include <kyosu/functions/pow.hpp>
#include <kyosu/functions/powm1.hpp>
#include <kyosu/functions/pow1p.hpp>
#include <kyosu/functions/pow_abs.hpp>
#include <kyosu/functions/powm1.hpp>
#include <kyosu/functions/pure.hpp>
#include <kyosu/functions/purepart.hpp>
#include <kyosu/functions/real.hpp>
#include <kyosu/functions/rec.hpp>
#include <kyosu/functions/reldist.hpp>
Expand All @@ -87,8 +88,9 @@
#include <kyosu/functions/sinpicospi.hpp>
#include <kyosu/functions/sinh.hpp>
#include <kyosu/functions/sinhcosh.hpp>
#include <kyosu/functions/sqr_abs.hpp>
#include <kyosu/functions/slerp.hpp>
#include <kyosu/functions/sqr.hpp>
#include <kyosu/functions/sqr_abs.hpp>
#include <kyosu/functions/sqrt.hpp>
#include <kyosu/functions/tan.hpp>
#include <kyosu/functions/tanpi.hpp>
Expand All @@ -102,3 +104,27 @@
#include <kyosu/complex/arg.hpp>
#include <kyosu/complex/is_imag.hpp>
#include <kyosu/complex/polar.hpp>
#include <kyosu/functions/from_polar.hpp>
#include <kyosu/functions/to_polar.hpp>

//======================================================================================================================
//! @brief Functions performing computations over quaternion complex or real elements only.
//======================================================================================================================


#include <kyosu/functions/from_angle_axis.hpp>
#include <kyosu/functions/from_cylindrical.hpp>
#include <kyosu/functions/from_euler.hpp>
#include <kyosu/functions/from_multipolar.hpp>
#include <kyosu/functions/from_semipolar.hpp>
#include <kyosu/functions/from_spherical.hpp>
#include <kyosu/functions/rot_angle.hpp>
#include <kyosu/functions/rot_axis.hpp>
#include <kyosu/functions/rotate_vec.hpp>
#include <kyosu/functions/to_angle_axis.hpp>
#include <kyosu/functions/to_cylindrical.hpp>
#include <kyosu/functions/to_euler.hpp>
#include <kyosu/functions/to_multipolar.hpp>
#include <kyosu/functions/to_rotation_matrix.hpp>
#include <kyosu/functions/to_semipolar.hpp>
#include <kyosu/functions/to_spherical.hpp>
81 changes: 81 additions & 0 deletions include/kyosu/functions/dot.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//======================================================================================================================
/*
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_dot : eve::elementwise
{
using callable_tag_type = callable_dot;

KYOSU_DEFERS_CALLABLE(dot_);

static KYOSU_FORCEINLINE auto deferred_call(auto
, eve::ordered_value auto const& v0
, eve::ordered_value auto const& v1) noexcept
{
return eve::dot(v0, v1);
}

KYOSU_FORCEINLINE auto operator()(auto const& target0, auto const& target1 ) const noexcept
-> decltype(eve::tag_invoke(*this, target0, target1))
{
return eve::tag_invoke(*this, target0, target1);
}

template<typename... T>
eve::unsupported_call<callable_dot(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//======================================================================================================================
//! @addtogroup functions
//! @{
//! @var dot
//! @brief Computes elementwise the dot product of the coordinates of the corresponding element.
//!
//! **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 dot(T0 z0, T1, z1) noexcept;
//! template<eve::ordered_value T0, kyosu::concepts::cayley_dickson T1> > constexpr auto dot(T0 z0, T1, z1) noexcept;
//! template<kyosu::concepts::cayley_dickson T0, eve::ordered_value T1 > constexpr auto dot(T0 z0, T1, z1) noexcept;
//! template<eve::ordered_value T0, ordered_value T1> > constexpr auto dot(T0 z0, T1, z1) noexcept;
///! }
//! @endcode
//!
//! **Parameters**
//!
//! * `z0, z1` : Value to process.
//!
//! **Return value**
//!
//! Returns the dot product of z0 and z1. If z0 and z1 are floating point this is equivalent to z0*z1.
//!
//! `dot(z0, z0)` is always semantically equivalent to `sqr_abs(z0)`.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/dot.cpp}
//! @}
//======================================================================================================================
inline constexpr tags::callable_dot dot = {};
}
90 changes: 90 additions & 0 deletions include/kyosu/functions/from_angle_axis.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//==================================================================================================
/*
KYOSU - Expressive Vector Engine
Copyright : KYOSU Project Contributors
SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#pragma once

#include <kyosu/details/invoke.hpp>
#include <kyosu/types/impl/quaternion/axis.hpp>
#include <kyosu/functions/to_quaternion.hpp>

namespace kyosu::tags
{
struct callable_from_angle_axis : eve::elementwise
{
using callable_tag_type = callable_from_angle_axis;

KYOSU_DEFERS_CALLABLE(from_angle_axis_);

template<eve::ordered_value V, eve::ordered_value U>
static KYOSU_FORCEINLINE auto deferred_call(auto
, V const & angle
, std::span<U, 3> axis) noexcept
{
auto q = to_quaternion(U(0), axis[0], axis[1], axis[2]);
auto [s, c] = eve::sincos(angle*eve::half(eve::as(angle)));
return c+s*q;
}

template<typename T0, typename T1>
KYOSU_FORCEINLINE auto operator()(T0 const& target0,
T1 const& target1
) const noexcept
-> decltype(eve::tag_invoke(*this, target0, target1))
{
return eve::tag_invoke(*this, target0, target1);
}

template<typename... T>
eve::unsupported_call<callable_from_angle_axis(T&&...)> operator()(T&&... x) const
requires(!requires { eve::tag_invoke(*this, KYOSU_FWD(x)...); }) = delete;
};
}

namespace kyosu
{
//================================================================================================
//! @addtogroup quaternion
//! @{
//! @var from_angle_axis
//!
//! @brief Callable object computing a quaternion from its angle_axis representation.
//!
//! This function build an unitary quaternion from an angle value and a 3 dimensionnal axis vector
//!
//! **Defined in header**
//!
//! @code
//! #include kyosu/module/quaternion.hpp>`
//! @endcode
//!
//! @groupheader{Callable Signatures}
//!
//! @code
//! namespace kyosu
//! {
//! auto from_angle_axis(auto angle, auto axis, auto norming = normalize) const noexcept;
//! }
//! @endcode
//!
//! **Parameters**
//!
//! * `angle` : rotation angle in radian
//! * `axis`` : rotation axis given by an std::span of dimension 3.
//! * normalize : can be assume_normalized or normalize in the second case axis is normalized.
//! if axis is already normalized use assume_normalized.
//!
//! **Return value**
//!
//! the quaternion value representing the rotation.
//!
//! @groupheader{Example}
//!
//! @godbolt{doc/quaternion/regular/conversions.cpp}
//! @}
//================================================================================================
inline constexpr tags::callable_from_angle_axis from_angle_axis = {};
}
Loading

0 comments on commit 03915e5

Please sign in to comment.