OLD | NEW |
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 #ifndef SkPathOpsTypes_DEFINED | 7 #ifndef SkPathOpsTypes_DEFINED |
8 #define SkPathOpsTypes_DEFINED | 8 #define SkPathOpsTypes_DEFINED |
9 | 9 |
10 #include <float.h> // for FLT_EPSILON | 10 #include <float.h> // for FLT_EPSILON |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 const double FLT_EPSILON_HALF = FLT_EPSILON / 2; | 84 const double FLT_EPSILON_HALF = FLT_EPSILON / 2; |
85 const double FLT_EPSILON_DOUBLE = FLT_EPSILON * 2; | 85 const double FLT_EPSILON_DOUBLE = FLT_EPSILON * 2; |
86 const double FLT_EPSILON_ORDERABLE_ERR = FLT_EPSILON * 16; | 86 const double FLT_EPSILON_ORDERABLE_ERR = FLT_EPSILON * 16; |
87 const double FLT_EPSILON_SQUARED = FLT_EPSILON * FLT_EPSILON; | 87 const double FLT_EPSILON_SQUARED = FLT_EPSILON * FLT_EPSILON; |
88 const double FLT_EPSILON_SQRT = sqrt(FLT_EPSILON); | 88 const double FLT_EPSILON_SQRT = sqrt(FLT_EPSILON); |
89 const double FLT_EPSILON_INVERSE = 1 / FLT_EPSILON; | 89 const double FLT_EPSILON_INVERSE = 1 / FLT_EPSILON; |
90 const double DBL_EPSILON_ERR = DBL_EPSILON * 4; // FIXME: tune -- allow a few b
its of error | 90 const double DBL_EPSILON_ERR = DBL_EPSILON * 4; // FIXME: tune -- allow a few b
its of error |
91 const double DBL_EPSILON_SUBDIVIDE_ERR = DBL_EPSILON * 16; | 91 const double DBL_EPSILON_SUBDIVIDE_ERR = DBL_EPSILON * 16; |
92 const double ROUGH_EPSILON = FLT_EPSILON * 64; | 92 const double ROUGH_EPSILON = FLT_EPSILON * 64; |
93 const double MORE_ROUGH_EPSILON = FLT_EPSILON * 256; | 93 const double MORE_ROUGH_EPSILON = FLT_EPSILON * 256; |
| 94 const double WAY_ROUGH_EPSILON = FLT_EPSILON * 2048; |
| 95 |
| 96 inline bool zero_or_one(double x) { |
| 97 return x == 0 || x == 1; |
| 98 } |
94 | 99 |
95 inline bool approximately_zero(double x) { | 100 inline bool approximately_zero(double x) { |
96 return fabs(x) < FLT_EPSILON; | 101 return fabs(x) < FLT_EPSILON; |
97 } | 102 } |
98 | 103 |
99 inline bool precisely_zero(double x) { | 104 inline bool precisely_zero(double x) { |
100 return fabs(x) < DBL_EPSILON_ERR; | 105 return fabs(x) < DBL_EPSILON_ERR; |
101 } | 106 } |
102 | 107 |
103 inline bool precisely_subdivide_zero(double x) { | 108 inline bool precisely_subdivide_zero(double x) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 return a <= c ? precisely_negative(a - b) && precisely_negative(b - c) | 295 return a <= c ? precisely_negative(a - b) && precisely_negative(b - c) |
291 : precisely_negative(b - a) && precisely_negative(c - b); | 296 : precisely_negative(b - a) && precisely_negative(c - b); |
292 } | 297 } |
293 | 298 |
294 // returns true if (a <= b <= c) || (a >= b >= c) | 299 // returns true if (a <= b <= c) || (a >= b >= c) |
295 inline bool between(double a, double b, double c) { | 300 inline bool between(double a, double b, double c) { |
296 SkASSERT(((a <= b && b <= c) || (a >= b && b >= c)) == ((a - b) * (c - b) <=
0)); | 301 SkASSERT(((a <= b && b <= c) || (a >= b && b >= c)) == ((a - b) * (c - b) <=
0)); |
297 return (a - b) * (c - b) <= 0; | 302 return (a - b) * (c - b) <= 0; |
298 } | 303 } |
299 | 304 |
| 305 inline bool roughly_equal(double x, double y) { |
| 306 return fabs(x - y) < ROUGH_EPSILON; |
| 307 } |
| 308 |
300 inline bool more_roughly_equal(double x, double y) { | 309 inline bool more_roughly_equal(double x, double y) { |
301 return fabs(x - y) < MORE_ROUGH_EPSILON; | 310 return fabs(x - y) < MORE_ROUGH_EPSILON; |
302 } | 311 } |
303 | 312 |
304 inline bool roughly_equal(double x, double y) { | 313 inline bool way_roughly_equal(double x, double y) { |
305 return fabs(x - y) < ROUGH_EPSILON; | 314 return fabs(x - y) < WAY_ROUGH_EPSILON; |
306 } | 315 } |
307 | 316 |
308 struct SkDPoint; | 317 struct SkDPoint; |
309 struct SkDVector; | 318 struct SkDVector; |
310 struct SkDLine; | 319 struct SkDLine; |
311 struct SkDQuad; | 320 struct SkDQuad; |
312 struct SkDTriangle; | 321 struct SkDTriangle; |
313 struct SkDCubic; | 322 struct SkDCubic; |
314 struct SkDRect; | 323 struct SkDRect; |
315 | 324 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 */ | 371 */ |
363 inline int SkDSideBit(double x) { | 372 inline int SkDSideBit(double x) { |
364 return 1 << SKDSide(x); | 373 return 1 << SKDSide(x); |
365 } | 374 } |
366 | 375 |
367 inline double SkPinT(double t) { | 376 inline double SkPinT(double t) { |
368 return precisely_less_than_zero(t) ? 0 : precisely_greater_than_one(t) ? 1 :
t; | 377 return precisely_less_than_zero(t) ? 0 : precisely_greater_than_one(t) ? 1 :
t; |
369 } | 378 } |
370 | 379 |
371 #endif | 380 #endif |
OLD | NEW |