Blender V4.3
blender::math::AngleFraction< T > Struct Template Reference

#include <BLI_math_angle_types.hh>

Public Member Functions

T degree () const
 
T radian () const
 
AngleFraction wrapped () const
 
AngleFraction wrapped_around (const AngleFraction &reference) const
 
AngleFractionoperator+= (const AngleFraction &b)
 
AngleFractionoperator-= (const AngleFraction &b)
 
AngleFractionoperator*= (const AngleFraction &b)
 
AngleFractionoperator/= (const AngleFraction &b)
 
AngleFractionoperator*= (const int64_t &b)
 
AngleFractionoperator/= (const int64_t &b)
 
 operator AngleCartesianBase< T > () const
 

Static Public Member Functions

static AngleFraction identity ()
 
static AngleFraction pi ()
 
static AngleFraction tau ()
 

Friends

AngleFraction operator+ (const AngleFraction &a, const AngleFraction &b)
 
AngleFraction operator- (const AngleFraction &a, const AngleFraction &b)
 
AngleFraction operator* (const AngleFraction &a, const AngleFraction &b)
 
AngleFraction operator/ (const AngleFraction &a, const AngleFraction &b)
 
AngleFraction operator* (const AngleFraction &a, const int64_t &b)
 
AngleFraction operator/ (const AngleFraction &a, const int64_t &b)
 
AngleFraction operator* (const int64_t &a, const AngleFraction &b)
 
AngleFraction operator/ (const int64_t &a, const AngleFraction &b)
 
AngleFraction operator+ (const AngleFraction &a)
 
AngleFraction operator- (const AngleFraction &a)
 
bool operator== (const AngleFraction &a, const AngleFraction &b)
 
bool operator!= (const AngleFraction &a, const AngleFraction &b)
 
std::ostream & operator<< (std::ostream &stream, const AngleFraction &rot)
 

Detailed Description

template<typename T = float>
struct blender::math::AngleFraction< T >

A blender::math::AngleFraction<T> stores a radian angle as quotient.

  • Storage : 2 * sizeof(int64_t)
  • Range : [-INT64_MAX..INT64_MAX] but angle must be expressed as fraction (be in Q subset).
  • Fast : Everything not slow.
  • Slow : cos(), sin(), tan() for angles not optimized.

It offers the best accuracy for fractions of Pi radian angles. For instance sin(AngleFraction::tau() * n - AngleFraction::pi() / 2) will exactly return -1 for any n within [-INT_MAX..INT_MAX]. This holds true even with very high radian values.

Arithmetic operators are relatively cheap (4 operations for addition, 2 for multiplication) but not as cheap as a AngleRadian. Another nice property is that the cos() and sin() functions give symmetric results around the circle.

NOTE: Prefer converting to blender::math::AngleCartesianBase<T> if both cos() and sin() are needed. This will save some computation.

Any operation becomes undefined if either the numerator or the denominator overflows.

The T template parameter only serves as type for the computed values like cos() or radian().

Definition at line 375 of file BLI_math_angle_types.hh.

Member Function Documentation

◆ degree()

template<typename T = float>
T blender::math::AngleFraction< T >::degree ( ) const
inline

Conversions.

Definition at line 411 of file BLI_math_angle_types.hh.

References T.

◆ identity()

template<typename T = float>
static AngleFraction blender::math::AngleFraction< T >::identity ( )
inlinestatic

Static functions.

Definition at line 393 of file BLI_math_angle_types.hh.

Referenced by blender::math::angle_between(), and blender::tests::TEST().

◆ operator AngleCartesianBase< T >()

◆ operator*=() [1/2]

template<typename T = float>
AngleFraction & blender::math::AngleFraction< T >::operator*= ( const AngleFraction< T > & b)
inline

Definition at line 551 of file BLI_math_angle_types.hh.

References b.

◆ operator*=() [2/2]

template<typename T = float>
AngleFraction & blender::math::AngleFraction< T >::operator*= ( const int64_t & b)
inline

Definition at line 561 of file BLI_math_angle_types.hh.

References b.

◆ operator+=()

template<typename T = float>
AngleFraction & blender::math::AngleFraction< T >::operator+= ( const AngleFraction< T > & b)
inline

Definition at line 541 of file BLI_math_angle_types.hh.

References b.

◆ operator-=()

template<typename T = float>
AngleFraction & blender::math::AngleFraction< T >::operator-= ( const AngleFraction< T > & b)
inline

Definition at line 546 of file BLI_math_angle_types.hh.

References b.

◆ operator/=() [1/2]

template<typename T = float>
AngleFraction & blender::math::AngleFraction< T >::operator/= ( const AngleFraction< T > & b)
inline

Definition at line 556 of file BLI_math_angle_types.hh.

References b.

◆ operator/=() [2/2]

template<typename T = float>
AngleFraction & blender::math::AngleFraction< T >::operator/= ( const int64_t & b)
inline

Definition at line 566 of file BLI_math_angle_types.hh.

References b.

◆ pi()

template<typename T = float>
static AngleFraction blender::math::AngleFraction< T >::pi ( )
inlinestatic

Definition at line 398 of file BLI_math_angle_types.hh.

Referenced by blender::math::angle_between(), and blender::tests::TEST().

◆ radian()

template<typename T = float>
T blender::math::AngleFraction< T >::radian ( ) const
inline

◆ tau()

template<typename T = float>
static AngleFraction blender::math::AngleFraction< T >::tau ( )
inlinestatic

Definition at line 403 of file BLI_math_angle_types.hh.

Referenced by blender::tests::TEST().

◆ wrapped()

template<typename T = float>
AngleFraction blender::math::AngleFraction< T >::wrapped ( ) const
inline

Methods. Return the angle wrapped inside [-pi..pi] interval. Basically (angle + pi) % 2pi - pi.

Definition at line 460 of file BLI_math_angle_types.hh.

References blender::math::abs(), and blender::math::mod_periodic().

Referenced by blender::math::AngleFraction< T >::operator AngleCartesianBase< T >(), and blender::math::AngleFraction< T >::wrapped_around().

◆ wrapped_around()

template<typename T = float>
AngleFraction blender::math::AngleFraction< T >::wrapped_around ( const AngleFraction< T > & reference) const
inline

Return the angle wrapped inside [-pi..pi] interval around a reference . Basically (angle - reference + pi) % 2pi - pi + reference . This means the interpolation between the returned value and reference will always take the shortest path.

Definition at line 475 of file BLI_math_angle_types.hh.

References blender::math::AngleFraction< T >::wrapped().

Friends And Related Symbol Documentation

◆ operator!=

template<typename T = float>
bool operator!= ( const AngleFraction< T > & a,
const AngleFraction< T > & b )
friend

Definition at line 582 of file BLI_math_angle_types.hh.

◆ operator* [1/3]

template<typename T = float>
AngleFraction operator* ( const AngleFraction< T > & a,
const AngleFraction< T > & b )
friend

Definition at line 501 of file BLI_math_angle_types.hh.

◆ operator* [2/3]

template<typename T = float>
AngleFraction operator* ( const AngleFraction< T > & a,
const int64_t & b )
friend

Definition at line 511 of file BLI_math_angle_types.hh.

◆ operator* [3/3]

template<typename T = float>
AngleFraction operator* ( const int64_t & a,
const AngleFraction< T > & b )
friend

Definition at line 521 of file BLI_math_angle_types.hh.

◆ operator+ [1/2]

template<typename T = float>
AngleFraction operator+ ( const AngleFraction< T > & a)
friend

Definition at line 531 of file BLI_math_angle_types.hh.

◆ operator+ [2/2]

template<typename T = float>
AngleFraction operator+ ( const AngleFraction< T > & a,
const AngleFraction< T > & b )
friend

Operators. We only allow operations on fractions of pi. So we cannot implement things like AngleFraction::pi() + 1 or AngleFraction::pi() * 0.5.

Definition at line 487 of file BLI_math_angle_types.hh.

◆ operator- [1/2]

template<typename T = float>
AngleFraction operator- ( const AngleFraction< T > & a)
friend

Definition at line 536 of file BLI_math_angle_types.hh.

◆ operator- [2/2]

template<typename T = float>
AngleFraction operator- ( const AngleFraction< T > & a,
const AngleFraction< T > & b )
friend

Definition at line 496 of file BLI_math_angle_types.hh.

◆ operator/ [1/3]

template<typename T = float>
AngleFraction operator/ ( const AngleFraction< T > & a,
const AngleFraction< T > & b )
friend

Definition at line 506 of file BLI_math_angle_types.hh.

◆ operator/ [2/3]

template<typename T = float>
AngleFraction operator/ ( const AngleFraction< T > & a,
const int64_t & b )
friend

Definition at line 516 of file BLI_math_angle_types.hh.

◆ operator/ [3/3]

template<typename T = float>
AngleFraction operator/ ( const int64_t & a,
const AngleFraction< T > & b )
friend

Definition at line 526 of file BLI_math_angle_types.hh.

◆ operator<<

template<typename T = float>
std::ostream & operator<< ( std::ostream & stream,
const AngleFraction< T > & rot )
friend

Definition at line 587 of file BLI_math_angle_types.hh.

◆ operator==

template<typename T = float>
bool operator== ( const AngleFraction< T > & a,
const AngleFraction< T > & b )
friend

Definition at line 571 of file BLI_math_angle_types.hh.


The documentation for this struct was generated from the following file: