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

Unified Diff: src/pathops/SkPathOpsTypes.cpp

Issue 15338003: path ops -- rewrite angle sort (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pathops/SkPathOpsTypes.h ('k') | tests/PathOpsAngleTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pathops/SkPathOpsTypes.cpp
===================================================================
--- src/pathops/SkPathOpsTypes.cpp (revision 9425)
+++ src/pathops/SkPathOpsTypes.cpp (working copy)
@@ -4,36 +4,31 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+#include "SkFloatBits.h"
#include "SkPathOpsTypes.h"
const int UlpsEpsilon = 16;
// from http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
-union SkPathOpsUlpsFloat {
- int32_t fInt;
- float fFloat;
-
- SkPathOpsUlpsFloat(float num = 0.0f) : fFloat(num) {}
- bool negative() const { return fInt < 0; }
-};
-
+// FIXME: move to SkFloatBits.h
bool AlmostEqualUlps(float A, float B) {
- SkPathOpsUlpsFloat uA(A);
- SkPathOpsUlpsFloat uB(B);
+ SkFloatIntUnion floatIntA, floatIntB;
+ floatIntA.fFloat = A;
+ floatIntB.fFloat = B;
// Different signs means they do not match.
- if (uA.negative() != uB.negative())
+ if ((floatIntA.fSignBitInt < 0) != (floatIntB.fSignBitInt < 0))
{
// Check for equality to make sure +0 == -0
return A == B;
}
// Find the difference in ULPs.
- int ulpsDiff = abs(uA.fInt - uB.fInt);
+ int ulpsDiff = abs(floatIntA.fSignBitInt - floatIntB.fSignBitInt);
return ulpsDiff <= UlpsEpsilon;
}
// cube root approximation using bit hack for 64-bit float
// adapted from Kahan's cbrt
-static double cbrt_5d(double d) {
+static double cbrt_5d(double d) {
const unsigned int B1 = 715094163;
double t = 0.0;
unsigned int* pt = (unsigned int*) &t;
@@ -43,7 +38,7 @@
}
// iterative cube root approximation using Halley's method (double)
-static double cbrta_halleyd(const double a, const double R) {
+static double cbrta_halleyd(const double a, const double R) {
const double a3 = a * a * a;
const double b = a * (a3 + R + R) / (a3 + a3 + R);
return b;
« no previous file with comments | « src/pathops/SkPathOpsTypes.h ('k') | tests/PathOpsAngleTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698