path ops : enable optimizations
this addresses a few FIXME issues
- speed up implicit quad computation
- use ulps instead of epsilon
- assert on bad line results more often
git-svn-id: http://skia.googlecode.com/svn/trunk@8823 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/pathops/SkDLineIntersection.cpp b/src/pathops/SkDLineIntersection.cpp
index 68e1f9e..5fd7d61 100644
--- a/src/pathops/SkDLineIntersection.cpp
+++ b/src/pathops/SkDLineIntersection.cpp
@@ -76,8 +76,7 @@
axLen * (ay - ax * ayLen / axLen) == axLen * (by - bx * ayLen / axLen)
axLen * ay - ax * ayLen == axLen * by - bx * ayLen
*/
- // FIXME: need to use AlmostEqualUlps variant instead
- if (!approximately_equal_squared(axLen * a[0].fY - ayLen * a[0].fX,
+ if (!AlmostEqualUlps(axLen * a[0].fY - ayLen * a[0].fX,
axLen * b[0].fY - ayLen * b[0].fX)) {
return fUsed = 0;
}
@@ -154,7 +153,7 @@
int SkIntersections::horizontal(const SkDLine& line, double left, double right, double y) {
int result = horizontal(line, y);
if (result != 1) {
- SkASSERT(result == 0); // FIXME: this is incorrect if result == 2
+ SkASSERT(0);
return result;
}
double xIntercept = line[0].fX + fT[0][0] * (line[1].fX - line[0].fX);
@@ -258,7 +257,6 @@
bool second = fabs(fT[0][0] - fT[0][1]) > FLT_EPSILON;
SkASSERT((fabs(fT[1][0] - fT[1][1]) <= FLT_EPSILON) ^ second);
return computePoints(line, 1 + second);
- break;
}
if (flipped) {
// OPTIMIZATION: instead of swapping, pass original line, use [1].fY - [0].fY
diff --git a/src/pathops/SkDQuadImplicit.cpp b/src/pathops/SkDQuadImplicit.cpp
index 9f1e882..84ad452 100644
--- a/src/pathops/SkDQuadImplicit.cpp
+++ b/src/pathops/SkDQuadImplicit.cpp
@@ -48,8 +48,8 @@
*
*/
-// OPTIMIZATION: test, verify tricky arithmetic
-static bool straight_forward = true;
+// use the tricky arithmetic path, but leave the original to compare just in case
+static bool straight_forward = false;
SkDQuadImplicit::SkDQuadImplicit(const SkDQuad& q) {
double a, b, c;
@@ -89,7 +89,7 @@
/* Given a pair of quadratics, determine their parametric coefficients.
* If the scaled coefficients are nearly equal, then the part of the quadratics
* may be coincident.
- * FIXME: optimization -- since comparison short-circuits on no match,
+ * OPTIMIZATION -- since comparison short-circuits on no match,
* lazily compute the coefficients, comparing the easiest to compute first.
* xx and yy first; then xy; and so on.
*/
diff --git a/src/pathops/SkPathOpsTypes.h b/src/pathops/SkPathOpsTypes.h
index 4d81586..5a5394a 100644
--- a/src/pathops/SkPathOpsTypes.h
+++ b/src/pathops/SkPathOpsTypes.h
@@ -21,6 +21,7 @@
kEvenOdd_PathOpsMask = 1
};
+// Use Almost Equal when comparing coordinates. Use epsilon to compare T values.
extern bool AlmostEqualUlps(float A, float B);
inline bool AlmostEqualUlps(double A, double B) {
return AlmostEqualUlps(SkDoubleToScalar(A), SkDoubleToScalar(B));