Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/pathops/SkPathOpsTypes.cpp

Issue 52653002: pathops work in progress (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add raster vs gpu test Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/pathops/SkPathOpsTypes.h ('k') | src/pathops/SkQuarticRoot.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SkFloatBits.h" 7 #include "SkFloatBits.h"
8 #include "SkPathOpsTypes.h" 8 #include "SkPathOpsTypes.h"
9 9
10 static bool arguments_denormalized(float a, float b, int epsilon) { 10 static bool arguments_denormalized(float a, float b, int epsilon) {
11 float denomalizedCheck = FLT_EPSILON * epsilon / 2; 11 float denormalizedCheck = FLT_EPSILON * epsilon / 2;
12 return fabsf(a) <= denomalizedCheck && fabsf(b) <= denomalizedCheck; 12 return fabsf(a) <= denormalizedCheck && fabsf(b) <= denormalizedCheck;
13 } 13 }
14 14
15 // from http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-num bers-2012-edition/ 15 // from http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-num bers-2012-edition/
16 // FIXME: move to SkFloatBits.h 16 // FIXME: move to SkFloatBits.h
17 static bool equal_ulps(float a, float b, int epsilon) { 17 static bool equal_ulps(float a, float b, int epsilon, int depsilon) {
18 if (!SkScalarIsFinite(a) || !SkScalarIsFinite(b)) { 18 if (!SkScalarIsFinite(a) || !SkScalarIsFinite(b)) {
19 return false; 19 return false;
20 } 20 }
21 if (arguments_denormalized(a, b, epsilon)) { 21 if (arguments_denormalized(a, b, depsilon)) {
22 return true; 22 return true;
23 } 23 }
24 int aBits = SkFloatAs2sCompliment(a); 24 int aBits = SkFloatAs2sCompliment(a);
25 int bBits = SkFloatAs2sCompliment(b); 25 int bBits = SkFloatAs2sCompliment(b);
26 // Find the difference in ULPs. 26 // Find the difference in ULPs.
27 return aBits < bBits + epsilon && bBits < aBits + epsilon; 27 return aBits < bBits + epsilon && bBits < aBits + epsilon;
28 } 28 }
29 29
30 static bool d_equal_ulps(float a, float b, int epsilon) { 30 static bool d_equal_ulps(float a, float b, int epsilon) {
31 if (!SkScalarIsFinite(a) || !SkScalarIsFinite(b)) { 31 if (!SkScalarIsFinite(a) || !SkScalarIsFinite(b)) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 82 }
83 int aBits = SkFloatAs2sCompliment(a); 83 int aBits = SkFloatAs2sCompliment(a);
84 int bBits = SkFloatAs2sCompliment(b); 84 int bBits = SkFloatAs2sCompliment(b);
85 // Find the difference in ULPs. 85 // Find the difference in ULPs.
86 return aBits < bBits + epsilon; 86 return aBits < bBits + epsilon;
87 } 87 }
88 88
89 // equality using the same error term as between 89 // equality using the same error term as between
90 bool AlmostBequalUlps(float a, float b) { 90 bool AlmostBequalUlps(float a, float b) {
91 const int UlpsEpsilon = 2; 91 const int UlpsEpsilon = 2;
92 return equal_ulps(a, b, UlpsEpsilon); 92 return equal_ulps(a, b, UlpsEpsilon, UlpsEpsilon);
93 }
94
95 bool AlmostPequalUlps(float a, float b) {
96 const int UlpsEpsilon = 8;
97 return equal_ulps(a, b, UlpsEpsilon, UlpsEpsilon);
93 } 98 }
94 99
95 bool AlmostDequalUlps(float a, float b) { 100 bool AlmostDequalUlps(float a, float b) {
96 const int UlpsEpsilon = 16; 101 const int UlpsEpsilon = 16;
97 return d_equal_ulps(a, b, UlpsEpsilon); 102 return d_equal_ulps(a, b, UlpsEpsilon);
98 } 103 }
99 104
100 bool AlmostEqualUlps(float a, float b) { 105 bool AlmostEqualUlps(float a, float b) {
101 const int UlpsEpsilon = 16; 106 const int UlpsEpsilon = 16;
102 return equal_ulps(a, b, UlpsEpsilon); 107 return equal_ulps(a, b, UlpsEpsilon, UlpsEpsilon);
103 } 108 }
104 109
105 bool NotAlmostEqualUlps(float a, float b) { 110 bool NotAlmostEqualUlps(float a, float b) {
106 const int UlpsEpsilon = 16; 111 const int UlpsEpsilon = 16;
107 return not_equal_ulps(a, b, UlpsEpsilon); 112 return not_equal_ulps(a, b, UlpsEpsilon);
108 } 113 }
109 114
110 bool NotAlmostDequalUlps(float a, float b) { 115 bool NotAlmostDequalUlps(float a, float b) {
111 const int UlpsEpsilon = 16; 116 const int UlpsEpsilon = 16;
112 return d_not_equal_ulps(a, b, UlpsEpsilon); 117 return d_not_equal_ulps(a, b, UlpsEpsilon);
113 } 118 }
114 119
115 bool RoughlyEqualUlps(float a, float b) { 120 bool RoughlyEqualUlps(float a, float b) {
116 const int UlpsEpsilon = 256; 121 const int UlpsEpsilon = 256;
117 return equal_ulps(a, b, UlpsEpsilon); 122 const int DUlpsEpsilon = 1024;
123 return equal_ulps(a, b, UlpsEpsilon, DUlpsEpsilon);
118 } 124 }
119 125
120 bool AlmostBetweenUlps(float a, float b, float c) { 126 bool AlmostBetweenUlps(float a, float b, float c) {
121 const int UlpsEpsilon = 2; 127 const int UlpsEpsilon = 2;
122 return a <= c ? less_or_equal_ulps(a, b, UlpsEpsilon) && less_or_equal_ulps( b, c, UlpsEpsilon) 128 return a <= c ? less_or_equal_ulps(a, b, UlpsEpsilon) && less_or_equal_ulps( b, c, UlpsEpsilon)
123 : less_or_equal_ulps(b, a, UlpsEpsilon) && less_or_equal_ulps(c, b, Ulps Epsilon); 129 : less_or_equal_ulps(b, a, UlpsEpsilon) && less_or_equal_ulps(c, b, Ulps Epsilon);
124 } 130 }
125 131
126 bool AlmostLessUlps(float a, float b) { 132 bool AlmostLessUlps(float a, float b) {
127 const int UlpsEpsilon = 16; 133 const int UlpsEpsilon = 16;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 double SkDCubeRoot(double x) { 184 double SkDCubeRoot(double x) {
179 if (approximately_zero_cubed(x)) { 185 if (approximately_zero_cubed(x)) {
180 return 0; 186 return 0;
181 } 187 }
182 double result = halley_cbrt3d(fabs(x)); 188 double result = halley_cbrt3d(fabs(x));
183 if (x < 0) { 189 if (x < 0) {
184 result = -result; 190 result = -result;
185 } 191 }
186 return result; 192 return result;
187 } 193 }
OLDNEW
« no previous file with comments | « src/pathops/SkPathOpsTypes.h ('k') | src/pathops/SkQuarticRoot.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698