Flutter Engine
The Flutter Engine
Functions
SkPathOpsTypes.cpp File Reference
#include "src/pathops/SkPathOpsTypes.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/base/SkMath.h"
#include "include/private/base/SkTemplates.h"
#include "src/base/SkFloatBits.h"
#include <algorithm>
#include <cstdint>
#include <cstring>

Go to the source code of this file.

Functions

static bool arguments_denormalized (float a, float b, int epsilon)
 
static bool equal_ulps (float a, float b, int epsilon, int depsilon)
 
static bool equal_ulps_no_normal_check (float a, float b, int epsilon, int depsilon)
 
static bool equal_ulps_pin (float a, float b, int epsilon, int depsilon)
 
static bool d_equal_ulps (float a, float b, int epsilon)
 
static bool not_equal_ulps (float a, float b, int epsilon)
 
static bool not_equal_ulps_pin (float a, float b, int epsilon)
 
static bool d_not_equal_ulps (float a, float b, int epsilon)
 
static bool less_ulps (float a, float b, int epsilon)
 
static bool less_or_equal_ulps (float a, float b, int epsilon)
 
bool AlmostBequalUlps (float a, float b)
 
bool AlmostPequalUlps (float a, float b)
 
bool AlmostDequalUlps (float a, float b)
 
bool AlmostDequalUlps (double a, double b)
 
bool AlmostEqualUlps (float a, float b)
 
bool AlmostEqualUlpsNoNormalCheck (float a, float b)
 
bool AlmostEqualUlps_Pin (float a, float b)
 
bool NotAlmostEqualUlps (float a, float b)
 
bool NotAlmostEqualUlps_Pin (float a, float b)
 
bool NotAlmostDequalUlps (float a, float b)
 
bool RoughlyEqualUlps (float a, float b)
 
bool AlmostBetweenUlps (float a, float b, float c)
 
bool AlmostLessUlps (float a, float b)
 
bool AlmostLessOrEqualUlps (float a, float b)
 
int UlpsDistance (float a, float b)
 

Function Documentation

◆ AlmostBequalUlps()

bool AlmostBequalUlps ( float  a,
float  b 
)

Definition at line 113 of file SkPathOpsTypes.cpp.

113 {
114 const int UlpsEpsilon = 2;
115 return equal_ulps(a, b, UlpsEpsilon, UlpsEpsilon);
116}
static bool equal_ulps(float a, float b, int epsilon, int depsilon)
static bool b
struct MyStruct a[10]

◆ AlmostBetweenUlps()

bool AlmostBetweenUlps ( float  a,
float  b,
float  c 
)

Definition at line 174 of file SkPathOpsTypes.cpp.

174 {
175 const int UlpsEpsilon = 2;
176 return a <= c ? less_or_equal_ulps(a, b, UlpsEpsilon) && less_or_equal_ulps(b, c, UlpsEpsilon)
177 : less_or_equal_ulps(b, a, UlpsEpsilon) && less_or_equal_ulps(c, b, UlpsEpsilon);
178}
static bool less_or_equal_ulps(float a, float b, int epsilon)

◆ AlmostDequalUlps() [1/2]

bool AlmostDequalUlps ( double  a,
double  b 
)

Definition at line 128 of file SkPathOpsTypes.cpp.

128 {
129 if (fabs(a) < SK_ScalarMax && fabs(b) < SK_ScalarMax) {
131 }
132 // We allow divide-by-zero here. It only happens if one of a,b is zero, and the other is NaN.
133 // (Otherwise, we'd hit the condition above). Thus, if std::max returns 0, we compute NaN / 0,
134 // which will produce NaN. The comparison will return false, which is the correct answer.
135 return sk_ieee_double_divide(fabs(a - b), std::max(fabs(a), fabs(b))) < FLT_EPSILON * 16;
136}
static constexpr double sk_ieee_double_divide(double numer, double denom)
bool AlmostDequalUlps(float a, float b)
#define SK_ScalarMax
Definition: SkScalar.h:24
#define SkDoubleToScalar(x)
Definition: SkScalar.h:64
static float max(float r, float g, float b)
Definition: hsl.cpp:49

◆ AlmostDequalUlps() [2/2]

bool AlmostDequalUlps ( float  a,
float  b 
)

Definition at line 123 of file SkPathOpsTypes.cpp.

123 {
124 const int UlpsEpsilon = 16;
125 return d_equal_ulps(a, b, UlpsEpsilon);
126}
static bool d_equal_ulps(float a, float b, int epsilon)

◆ AlmostEqualUlps()

bool AlmostEqualUlps ( float  a,
float  b 
)

Definition at line 138 of file SkPathOpsTypes.cpp.

138 {
139 const int UlpsEpsilon = 16;
140 return equal_ulps(a, b, UlpsEpsilon, UlpsEpsilon);
141}

◆ AlmostEqualUlps_Pin()

bool AlmostEqualUlps_Pin ( float  a,
float  b 
)

Definition at line 148 of file SkPathOpsTypes.cpp.

148 {
149 const int UlpsEpsilon = 16;
150 return equal_ulps_pin(a, b, UlpsEpsilon, UlpsEpsilon);
151}
static bool equal_ulps_pin(float a, float b, int epsilon, int depsilon)

◆ AlmostEqualUlpsNoNormalCheck()

bool AlmostEqualUlpsNoNormalCheck ( float  a,
float  b 
)

Definition at line 143 of file SkPathOpsTypes.cpp.

143 {
144 const int UlpsEpsilon = 16;
145 return equal_ulps_no_normal_check(a, b, UlpsEpsilon, UlpsEpsilon);
146}
static bool equal_ulps_no_normal_check(float a, float b, int epsilon, int depsilon)

◆ AlmostLessOrEqualUlps()

bool AlmostLessOrEqualUlps ( float  a,
float  b 
)

Definition at line 185 of file SkPathOpsTypes.cpp.

185 {
186 const int UlpsEpsilon = 16;
187 return less_or_equal_ulps(a, b, UlpsEpsilon);
188}

◆ AlmostLessUlps()

bool AlmostLessUlps ( float  a,
float  b 
)

Definition at line 180 of file SkPathOpsTypes.cpp.

180 {
181 const int UlpsEpsilon = 16;
182 return less_ulps(a, b, UlpsEpsilon);
183}
static bool less_ulps(float a, float b, int epsilon)

◆ AlmostPequalUlps()

bool AlmostPequalUlps ( float  a,
float  b 
)

Definition at line 118 of file SkPathOpsTypes.cpp.

118 {
119 const int UlpsEpsilon = 8;
120 return equal_ulps(a, b, UlpsEpsilon, UlpsEpsilon);
121}

◆ arguments_denormalized()

static bool arguments_denormalized ( float  a,
float  b,
int  epsilon 
)
static

Definition at line 18 of file SkPathOpsTypes.cpp.

18 {
19 float denormalizedCheck = FLT_EPSILON * epsilon / 2;
20 return fabsf(a) <= denormalizedCheck && fabsf(b) <= denormalizedCheck;
21}

◆ d_equal_ulps()

static bool d_equal_ulps ( float  a,
float  b,
int  epsilon 
)
static

Definition at line 55 of file SkPathOpsTypes.cpp.

55 {
56 int aBits = SkFloatAs2sCompliment(a);
57 int bBits = SkFloatAs2sCompliment(b);
58 // Find the difference in ULPs.
59 return aBits < bBits + epsilon && bBits < aBits + epsilon;
60}
static int32_t SkFloatAs2sCompliment(float x)
Definition: SkFloatBits.h:59

◆ d_not_equal_ulps()

static bool d_not_equal_ulps ( float  a,
float  b,
int  epsilon 
)
static

Definition at line 85 of file SkPathOpsTypes.cpp.

85 {
86 int aBits = SkFloatAs2sCompliment(a);
87 int bBits = SkFloatAs2sCompliment(b);
88 // Find the difference in ULPs.
89 return aBits >= bBits + epsilon || bBits >= aBits + epsilon;
90}

◆ equal_ulps()

static bool equal_ulps ( float  a,
float  b,
int  epsilon,
int  depsilon 
)
static

Definition at line 25 of file SkPathOpsTypes.cpp.

25 {
26 if (arguments_denormalized(a, b, depsilon)) {
27 return true;
28 }
29 int aBits = SkFloatAs2sCompliment(a);
30 int bBits = SkFloatAs2sCompliment(b);
31 // Find the difference in ULPs.
32 return aBits < bBits + epsilon && bBits < aBits + epsilon;
33}
static bool arguments_denormalized(float a, float b, int epsilon)

◆ equal_ulps_no_normal_check()

static bool equal_ulps_no_normal_check ( float  a,
float  b,
int  epsilon,
int  depsilon 
)
static

Definition at line 35 of file SkPathOpsTypes.cpp.

35 {
36 int aBits = SkFloatAs2sCompliment(a);
37 int bBits = SkFloatAs2sCompliment(b);
38 // Find the difference in ULPs.
39 return aBits < bBits + epsilon && bBits < aBits + epsilon;
40}

◆ equal_ulps_pin()

static bool equal_ulps_pin ( float  a,
float  b,
int  epsilon,
int  depsilon 
)
static

Definition at line 42 of file SkPathOpsTypes.cpp.

42 {
43 if (!SkIsFinite(a, b)) {
44 return false;
45 }
46 if (arguments_denormalized(a, b, depsilon)) {
47 return true;
48 }
49 int aBits = SkFloatAs2sCompliment(a);
50 int bBits = SkFloatAs2sCompliment(b);
51 // Find the difference in ULPs.
52 return aBits < bBits + epsilon && bBits < aBits + epsilon;
53}
static bool SkIsFinite(T x, Pack... values)

◆ less_or_equal_ulps()

static bool less_or_equal_ulps ( float  a,
float  b,
int  epsilon 
)
static

Definition at line 102 of file SkPathOpsTypes.cpp.

102 {
103 if (arguments_denormalized(a, b, epsilon)) {
104 return a < b + FLT_EPSILON * epsilon;
105 }
106 int aBits = SkFloatAs2sCompliment(a);
107 int bBits = SkFloatAs2sCompliment(b);
108 // Find the difference in ULPs.
109 return aBits < bBits + epsilon;
110}

◆ less_ulps()

static bool less_ulps ( float  a,
float  b,
int  epsilon 
)
static

Definition at line 92 of file SkPathOpsTypes.cpp.

92 {
93 if (arguments_denormalized(a, b, epsilon)) {
94 return a <= b - FLT_EPSILON * epsilon;
95 }
96 int aBits = SkFloatAs2sCompliment(a);
97 int bBits = SkFloatAs2sCompliment(b);
98 // Find the difference in ULPs.
99 return aBits <= bBits - epsilon;
100}

◆ not_equal_ulps()

static bool not_equal_ulps ( float  a,
float  b,
int  epsilon 
)
static

Definition at line 62 of file SkPathOpsTypes.cpp.

62 {
63 if (arguments_denormalized(a, b, epsilon)) {
64 return false;
65 }
66 int aBits = SkFloatAs2sCompliment(a);
67 int bBits = SkFloatAs2sCompliment(b);
68 // Find the difference in ULPs.
69 return aBits >= bBits + epsilon || bBits >= aBits + epsilon;
70}

◆ not_equal_ulps_pin()

static bool not_equal_ulps_pin ( float  a,
float  b,
int  epsilon 
)
static

Definition at line 72 of file SkPathOpsTypes.cpp.

72 {
73 if (!SkIsFinite(a, b)) {
74 return false;
75 }
76 if (arguments_denormalized(a, b, epsilon)) {
77 return false;
78 }
79 int aBits = SkFloatAs2sCompliment(a);
80 int bBits = SkFloatAs2sCompliment(b);
81 // Find the difference in ULPs.
82 return aBits >= bBits + epsilon || bBits >= aBits + epsilon;
83}

◆ NotAlmostDequalUlps()

bool NotAlmostDequalUlps ( float  a,
float  b 
)

Definition at line 163 of file SkPathOpsTypes.cpp.

163 {
164 const int UlpsEpsilon = 16;
165 return d_not_equal_ulps(a, b, UlpsEpsilon);
166}
static bool d_not_equal_ulps(float a, float b, int epsilon)

◆ NotAlmostEqualUlps()

bool NotAlmostEqualUlps ( float  a,
float  b 
)

Definition at line 153 of file SkPathOpsTypes.cpp.

153 {
154 const int UlpsEpsilon = 16;
155 return not_equal_ulps(a, b, UlpsEpsilon);
156}
static bool not_equal_ulps(float a, float b, int epsilon)

◆ NotAlmostEqualUlps_Pin()

bool NotAlmostEqualUlps_Pin ( float  a,
float  b 
)

Definition at line 158 of file SkPathOpsTypes.cpp.

158 {
159 const int UlpsEpsilon = 16;
160 return not_equal_ulps_pin(a, b, UlpsEpsilon);
161}
static bool not_equal_ulps_pin(float a, float b, int epsilon)

◆ RoughlyEqualUlps()

bool RoughlyEqualUlps ( float  a,
float  b 
)

Definition at line 168 of file SkPathOpsTypes.cpp.

168 {
169 const int UlpsEpsilon = 256;
170 const int DUlpsEpsilon = 1024;
171 return equal_ulps(a, b, UlpsEpsilon, DUlpsEpsilon);
172}

◆ UlpsDistance()

int UlpsDistance ( float  a,
float  b 
)

Definition at line 190 of file SkPathOpsTypes.cpp.

190 {
191 int32_t floatIntA, floatIntB;
192 memcpy(&floatIntA, &a, sizeof(int32_t));
193 memcpy(&floatIntB, &b, sizeof(int32_t));
194 // Different signs means they do not match.
195 if ((floatIntA < 0) != (floatIntB < 0)) {
196 // Check for equality to make sure +0 == -0
197 return a == b ? 0 : SK_MaxS32;
198 }
199 // Find the difference in ULPs.
200 return SkTAbs(floatIntA - floatIntB);
201}
static constexpr int32_t SK_MaxS32
Definition: SkMath.h:21
static T SkTAbs(T value)
Definition: SkTemplates.h:43