path ops : enable optimizations
authorcaryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 23 Apr 2013 12:04:05 +0000 (12:04 +0000)
committercaryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 23 Apr 2013 12:04:05 +0000 (12:04 +0000)
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

src/pathops/SkDLineIntersection.cpp
src/pathops/SkDQuadImplicit.cpp
src/pathops/SkPathOpsTypes.h

index 68e1f9e..5fd7d61 100644 (file)
@@ -76,8 +76,7 @@ int SkIntersections::intersect(const SkDLine& a, const SkDLine& b) {
      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 y) {
 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 @@ int SkIntersections::vertical(const SkDLine& line, double top, double bottom,
             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
index 9f1e882..84ad452 100644 (file)
@@ -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 @@ SkDQuadImplicit::SkDQuadImplicit(const SkDQuad& q) {
  /* 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.
   */
index 4d81586..5a5394a 100644 (file)
@@ -21,6 +21,7 @@ enum SkPathOpsMask {
     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));