Krita Source Code Documentation
Loading...
Searching...
No Matches
KisFixedPoint Class Reference

#include <kis_fixed_point_maths.h>

+ Inheritance diagram for KisFixedPoint:

Public Member Functions

KisFixedPointdec256Frac ()
 
KisFixedPointfrom256Frac (qint32 v)
 
KisFixedPointinc256Frac ()
 
bool isInteger () const
 
 KisFixedPoint ()
 
 KisFixedPoint (int iValue)
 
 KisFixedPoint (qreal fValue)
 
KisFixedPointoperator*= (const KisFixedPoint &x)
 
KisFixedPointoperator+= (const KisFixedPoint &x)
 
KisFixedPointoperator-= (const KisFixedPoint &x)
 
KisFixedPointoperator/= (const KisFixedPoint &x)
 
bool operator< (const KisFixedPoint &x) const
 
bool operator== (const KisFixedPoint &x) const
 
qint32 to256Frac () const
 
qreal toFloat () const
 
qint32 toInt () const
 
qint32 toIntCeil () const
 
qint32 toIntFloor () const
 
qint32 toIntRound () const
 

Private Attributes

qint32 d
 

Friends

KisFixedPoint operator- (KisFixedPoint x)
 
QDebug operator<< (QDebug dbg, const KisFixedPoint &v)
 

Detailed Description

Definition at line 13 of file kis_fixed_point_maths.h.

Constructor & Destructor Documentation

◆ KisFixedPoint() [1/3]

KisFixedPoint::KisFixedPoint ( )
inline

Definition at line 16 of file kis_fixed_point_maths.h.

17 : d(0){};

◆ KisFixedPoint() [2/3]

KisFixedPoint::KisFixedPoint ( int iValue)
inline

Definition at line 19 of file kis_fixed_point_maths.h.

20 : d(iValue * 256)
21 {
22 }

◆ KisFixedPoint() [3/3]

KisFixedPoint::KisFixedPoint ( qreal fValue)
inline

Definition at line 24 of file kis_fixed_point_maths.h.

25 : d(static_cast<int>(fValue * 256))
26 {
27 }

Member Function Documentation

◆ dec256Frac()

KisFixedPoint & KisFixedPoint::dec256Frac ( )
inline

Definition at line 63 of file kis_fixed_point_maths.h.

63 {
64 d--;
65 return *this;
66 }

References d.

◆ from256Frac()

KisFixedPoint & KisFixedPoint::from256Frac ( qint32 v)
inline

Definition at line 49 of file kis_fixed_point_maths.h.

49 {
50 d = v;
51 return *this;
52 }
qreal v

References d, and v.

◆ inc256Frac()

KisFixedPoint & KisFixedPoint::inc256Frac ( )
inline

Definition at line 58 of file kis_fixed_point_maths.h.

58 {
59 d++;
60 return *this;
61 }

References d.

◆ isInteger()

bool KisFixedPoint::isInteger ( ) const
inline

Definition at line 68 of file kis_fixed_point_maths.h.

68 {
69 return !(d & ((1 << 8) -1 ));
70 }

References d.

◆ operator*=()

KisFixedPoint & KisFixedPoint::operator*= ( const KisFixedPoint & x)
inline

Until C++20 d >>= 8 is "implementation defined" for negative d. But we have a unittest that confirms that the our compiler handles that in an expected way

Definition at line 90 of file kis_fixed_point_maths.h.

91 {
98 d *= x.d;
99 d >>= 8;
100 return *this;
101 }

References d.

◆ operator+=()

KisFixedPoint & KisFixedPoint::operator+= ( const KisFixedPoint & x)
inline

Definition at line 80 of file kis_fixed_point_maths.h.

80 {
81 d += x.d;
82 return *this;
83 }

References d.

◆ operator-=()

KisFixedPoint & KisFixedPoint::operator-= ( const KisFixedPoint & x)
inline

Definition at line 85 of file kis_fixed_point_maths.h.

85 {
86 d -= x.d;
87 return *this;
88 }

References d.

◆ operator/=()

KisFixedPoint & KisFixedPoint::operator/= ( const KisFixedPoint & x)
inline

Until C++20 d <<= 8 is an "undefined behavior" for negative d. But we have a unittest that confirms that the our compiler handles that in an expected way

Definition at line 103 of file kis_fixed_point_maths.h.

104 {
111 d *= 256;
112 d /= x.d;
113 return *this;
114 }

References d.

◆ operator<()

bool KisFixedPoint::operator< ( const KisFixedPoint & x) const
inline

Definition at line 72 of file kis_fixed_point_maths.h.

72 {
73 return d < x.d;
74 }

References d.

◆ operator==()

bool KisFixedPoint::operator== ( const KisFixedPoint & x) const
inline

Definition at line 76 of file kis_fixed_point_maths.h.

76 {
77 return d == x.d;
78 }

References d.

◆ to256Frac()

qint32 KisFixedPoint::to256Frac ( ) const
inline

Definition at line 54 of file kis_fixed_point_maths.h.

54 {
55 return d;
56 }

References d.

◆ toFloat()

qreal KisFixedPoint::toFloat ( ) const
inline

Definition at line 45 of file kis_fixed_point_maths.h.

45 {
46 return qreal(d) / qreal(1 << 8);
47 }

References d.

◆ toInt()

qint32 KisFixedPoint::toInt ( ) const
inline

Definition at line 29 of file kis_fixed_point_maths.h.

29 {
30 return d >= 0 ? d >> 8 : -((-d) >> 8);
31 }

References d.

◆ toIntCeil()

qint32 KisFixedPoint::toIntCeil ( ) const
inline

Definition at line 37 of file kis_fixed_point_maths.h.

37 {
38 return d >= 0 ? (d + ((1 << 8) - 1)) >> 8 : -((-d) >> 8);
39 }

References d.

◆ toIntFloor()

qint32 KisFixedPoint::toIntFloor ( ) const
inline

Definition at line 41 of file kis_fixed_point_maths.h.

41 {
42 return d >= 0 ? d >> 8 : -((-d + ((1 << 8) - 1)) >> 8);
43 }

References d.

◆ toIntRound()

qint32 KisFixedPoint::toIntRound ( ) const
inline

Definition at line 33 of file kis_fixed_point_maths.h.

33 {
34 return d >= 0 ? (d + (1 << 7)) >> 8 : -((-d + (1 << 7)) >> 8);
35 }

References d.

Friends And Related Symbol Documentation

◆ operator-

KisFixedPoint operator- ( KisFixedPoint x)
friend

Definition at line 124 of file kis_fixed_point_maths.h.

124 {
125 x.d = -x.d;
126 return x;
127}

◆ operator<<

QDebug operator<< ( QDebug dbg,
const KisFixedPoint & v )
friend

Definition at line 129 of file kis_fixed_point_maths.h.

129 {
130 dbg.nospace() << v.toFloat() << " (d = " << v.d << ")";
131 return dbg.space();
132}

Member Data Documentation

◆ d

qint32 KisFixedPoint::d
private

Definition at line 121 of file kis_fixed_point_maths.h.


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