Beatmup
Beatmup::Fixed< rtype, precision, optype > Struct Template Reference

Fixed-point number. More...

#include <fixed_point.h>

Public Types

typedef rtype underlying_type
 

Public Member Functions

 Fixed ()
 
 Fixed (const Fixed &another)
 
 Fixed (float value)
 
Fixedoperator= (const float value)
 
Fixedoperator= (const rtype value)
 
Fixed operator+ (const Fixed &another) const
 
Fixed operator- (const Fixed &another) const
 
Fixed operator* (const Fixed &another) const
 
Fixed operator/ (const Fixed &another) const
 
 operator float () const
 
uint8_t asTexture () const
 

Static Public Member Functions

static Fixed interpret (const underlying_type value)
 
static float min ()
 
static float max ()
 

Protected Member Functions

 Fixed (const rtype value)
 

Static Protected Member Functions

static rtype clamp (const float val, const rtype min, const rtype max)
 
static rtype fromFloat (const float val)
 

Protected Attributes

rtype value
 

Detailed Description

template<typename rtype, const int precision, typename optype>
struct Beatmup::Fixed< rtype, precision, optype >

Fixed-point number.

Template Parameters
rtypeDatatype used to store the values
precisionNumber of bits to represent the fractional part
optypeDatatype used in arithmetic operations

Definition at line 33 of file fixed_point.h.

Member Typedef Documentation

◆ underlying_type

template<typename rtype , const int precision, typename optype >
typedef rtype Beatmup::Fixed< rtype, precision, optype >::underlying_type

Definition at line 47 of file fixed_point.h.

Constructor & Destructor Documentation

◆ Fixed() [1/4]

template<typename rtype , const int precision, typename optype >
Beatmup::Fixed< rtype, precision, optype >::Fixed ( const rtype  value)
inlineprotected

Definition at line 44 of file fixed_point.h.

44 : value(((optype)value) << precision) {}

◆ Fixed() [2/4]

template<typename rtype , const int precision, typename optype >
Beatmup::Fixed< rtype, precision, optype >::Fixed ( )
inline

Definition at line 49 of file fixed_point.h.

49 : value(0) {}

◆ Fixed() [3/4]

template<typename rtype , const int precision, typename optype >
Beatmup::Fixed< rtype, precision, optype >::Fixed ( const Fixed< rtype, precision, optype > &  another)
inline

Definition at line 51 of file fixed_point.h.

51 : value(another.value) {}

◆ Fixed() [4/4]

template<typename rtype , const int precision, typename optype >
Beatmup::Fixed< rtype, precision, optype >::Fixed ( float  value)
inline

Definition at line 53 of file fixed_point.h.

53 : value(fromFloat(value)) {}
static rtype fromFloat(const float val)
Definition: fixed_point.h:40

Member Function Documentation

◆ clamp()

template<typename rtype , const int precision, typename optype >
static rtype Beatmup::Fixed< rtype, precision, optype >::clamp ( const float  val,
const rtype  min,
const rtype  max 
)
inlinestaticprotected

Definition at line 36 of file fixed_point.h.

36  {
37  return val <= min ? min : val >= max ? max : (rtype)roundf_fast(val);
38  }
static float max()
Definition: fixed_point.h:111
#define roundf_fast(X)
rounding (nearest integer)
Definition: utils.hpp:22
return(jlong) new Beatmup jlong jstring jint val

◆ fromFloat()

template<typename rtype , const int precision, typename optype >
static rtype Beatmup::Fixed< rtype, precision, optype >::fromFloat ( const float  val)
inlinestaticprotected

Definition at line 40 of file fixed_point.h.

40  {
42  }
CustomPoint< numeric > min(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:724
CustomPoint< numeric > max(const CustomPoint< numeric > &a, const CustomPoint< numeric > &b)
Definition: geometry.h:728
static rtype clamp(const float val, const rtype min, const rtype max)
Definition: fixed_point.h:36

◆ operator=() [1/2]

template<typename rtype , const int precision, typename optype >
Fixed& Beatmup::Fixed< rtype, precision, optype >::operator= ( const float  value)
inline

Definition at line 55 of file fixed_point.h.

55  {
56  this->value = fromFloat(value);
57  return *this;
58  }

◆ operator=() [2/2]

template<typename rtype , const int precision, typename optype >
Fixed& Beatmup::Fixed< rtype, precision, optype >::operator= ( const rtype  value)
inline

Definition at line 60 of file fixed_point.h.

60  {
61  this->value = ((optype)value) << precision;
62  return *this;
63  }

◆ operator+()

template<typename rtype , const int precision, typename optype >
Fixed Beatmup::Fixed< rtype, precision, optype >::operator+ ( const Fixed< rtype, precision, optype > &  another) const
inline

Definition at line 65 of file fixed_point.h.

65  {
66  return Fixed::interpret( static_cast<rtype>(value + another.value) );
67  }
static Fixed interpret(const underlying_type value)
Definition: fixed_point.h:93

◆ operator-()

template<typename rtype , const int precision, typename optype >
Fixed Beatmup::Fixed< rtype, precision, optype >::operator- ( const Fixed< rtype, precision, optype > &  another) const
inline

Definition at line 69 of file fixed_point.h.

69  {
70  return Fixed::interpret( static_cast<rtype>(value - another.value) );
71  }

◆ operator*()

template<typename rtype , const int precision, typename optype >
Fixed Beatmup::Fixed< rtype, precision, optype >::operator* ( const Fixed< rtype, precision, optype > &  another) const
inline

Definition at line 73 of file fixed_point.h.

73  {
74  return Fixed::interpret( static_cast<rtype>(((optype)value * another.value) >> precision) );
75  }

◆ operator/()

template<typename rtype , const int precision, typename optype >
Fixed Beatmup::Fixed< rtype, precision, optype >::operator/ ( const Fixed< rtype, precision, optype > &  another) const
inline

Definition at line 77 of file fixed_point.h.

77  {
78  return Fixed::interpret( static_cast<rtype>(((optype)value << precision) / another.value) );
79  }

◆ operator float()

template<typename rtype , const int precision, typename optype >
Beatmup::Fixed< rtype, precision, optype >::operator float ( ) const
inline

Definition at line 82 of file fixed_point.h.

82  {
83  return (float)value / (float)(1 << precision);
84  }

◆ asTexture()

template<typename rtype , const int precision, typename optype >
uint8_t Beatmup::Fixed< rtype, precision, optype >::asTexture ( ) const
inline

Definition at line 87 of file fixed_point.h.

87  {
88  const optype v = (((optype)value) * 255) >> precision;
89  return v <= 0 ? 0 : v >= 255 ? 255 : (uint8_t)v;
90  }
JNIEnv jlong jfloat jfloat jfloat v

◆ interpret()

template<typename rtype , const int precision, typename optype >
static Fixed Beatmup::Fixed< rtype, precision, optype >::interpret ( const underlying_type  value)
inlinestatic

Definition at line 93 of file fixed_point.h.

93  {
94  Fixed result;
95  result.value = value;
96  return result;
97  }
Beatmup::IntPoint result

◆ min()

template<typename rtype , const int precision, typename optype >
static float Beatmup::Fixed< rtype, precision, optype >::min ( )
inlinestatic
Returns
min representable value.

Definition at line 103 of file fixed_point.h.

103  {
105  }

◆ max()

template<typename rtype , const int precision, typename optype >
static float Beatmup::Fixed< rtype, precision, optype >::max ( )
inlinestatic
Returns
max representable value.

Definition at line 111 of file fixed_point.h.

111  {
113  }

Member Data Documentation

◆ value

template<typename rtype , const int precision, typename optype >
rtype Beatmup::Fixed< rtype, precision, optype >::value
protected

Definition at line 35 of file fixed_point.h.


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