Krita Source Code Documentation
Loading...
Searching...
No Matches
KisFastMath Namespace Reference

Functions

KRITAIMAGE_EXPORT qreal atan2 (qreal y, qreal x)
 atan2 replacement
 

Detailed Description

This namespace contains fast but inaccurate version of mathematical function.

Function Documentation

◆ atan2()

qreal KisFastMath::atan2 ( qreal y,
qreal x )

atan2 replacement

Definition at line 68 of file kis_fast_math.cpp.

69{
70
71 if (y == 0.0) { // the line is horizontal
72 if (x >= 0.0) { // towards the right
73 return(0.0);// the angle is 0
74 }
75 // toward the left
76 return qreal(M_PI);
77 } // we now know that y is not 0 check x
78 if (x == 0.0) { // the line is vertical
79 if (y > 0.0) {
80 return M_PI_2;
81 }
82 return -M_PI_2;
83 }
84 // from here on we know that neither x nor y is 0
85 if (x > 0.0) {
86 // we are in quadrant 1 or 4
87 if (y > 0.0) {
88 // we are in quadrant 1
89 // now figure out which side of the 45 degree line
90 if (x > y) {
91 return(calcAngle(x, y));
92 }
93 return(M_PI_2 - calcAngle(y, x));
94 }
95 // we are in quadrant 4
96 y = -y;
97 // now figure out which side of the 45 degree line
98 if (x > y) {
99 return(-calcAngle(x, y));
100 }
101 return(-M_PI_2 + calcAngle(y, x));
102 }
103 // we are in quadrant 2 or 3
104 x = -x;
105 // flip x so we can use it as a positive
106 if (y > 0.0) {
107 // we are in quadrant 2
108 // now figure out which side of the 45 degree line
109 if (x > y) {
110 return(M_PI - calcAngle(x, y));
111 } return(M_PI_2 + calcAngle(y, x));
112 }
113 // we are in quadrant 3
114 y = -y;
115 // flip y so we can use it as a positive
116 // now figure out which side of the 45 degree line
117 if (x > y) {
118 return(-M_PI + calcAngle(x, y));
119 } return(-M_PI_2 - calcAngle(y, x));
120}
qreal calcAngle(qreal x, qreal y)
#define M_PI
Definition kis_global.h:111

References calcAngle(), and M_PI.