Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / pathops / SkDQuadLineIntersection.cpp
index bae003c..1b9d8cc 100644 (file)
@@ -86,7 +86,6 @@ Thus, if the slope of the line tends towards vertical, we use:
        C =   ( (a          ) - g'*(d           ) - h' )
  */
 
-
 class LineQuadraticIntersections {
 public:
     enum PinTPoint {
@@ -99,7 +98,7 @@ public:
         , fLine(l)
         , fIntersections(i)
         , fAllowNear(true) {
-        i->setMax(2);
+        i->setMax(3);  // allow short partial coincidence plus discrete intersection
     }
 
     void allowNear(bool allow) {
@@ -311,10 +310,10 @@ protected:
     }
 
     bool pinTs(double* quadT, double* lineT, SkDPoint* pt, PinTPoint ptSet) {
-        if (!approximately_one_or_less(*lineT)) {
+        if (!approximately_one_or_less_double(*lineT)) {
             return false;
         }
-        if (!approximately_zero_or_more(*lineT)) {
+        if (!approximately_zero_or_more_double(*lineT)) {
             return false;
         }
         double qT = *quadT = SkPinT(*quadT);
@@ -326,13 +325,20 @@ protected:
         }
         SkPoint gridPt = pt->asSkPoint();
         if (gridPt == fLine[0].asSkPoint()) {
+            *pt = fLine[0];
             *lineT = 0;
         } else if (gridPt == fLine[1].asSkPoint()) {
+            *pt = fLine[1];
             *lineT = 1;
         }
+        if (fIntersections->used() > 0 && approximately_equal((*fIntersections)[1][0], *lineT)) {
+            return false;
+        }
         if (gridPt == fQuad[0].asSkPoint()) {
+            *pt = fQuad[0];
             *quadT = 0;
         } else if (gridPt == fQuad[2].asSkPoint()) {
+            *pt = fQuad[2];
             *quadT = 1;
         }
         return true;
@@ -345,44 +351,6 @@ private:
     bool fAllowNear;
 };
 
-// utility for pairs of coincident quads
-static double horizontalIntersect(const SkDQuad& quad, const SkDPoint& pt) {
-    LineQuadraticIntersections q(quad, *(static_cast<SkDLine*>(0)),
-            static_cast<SkIntersections*>(0));
-    double rootVals[2];
-    int roots = q.horizontalIntersect(pt.fY, rootVals);
-    for (int index = 0; index < roots; ++index) {
-        double t = rootVals[index];
-        SkDPoint qPt = quad.ptAtT(t);
-        if (AlmostEqualUlps(qPt.fX, pt.fX)) {
-            return t;
-        }
-    }
-    return -1;
-}
-
-static double verticalIntersect(const SkDQuad& quad, const SkDPoint& pt) {
-    LineQuadraticIntersections q(quad, *(static_cast<SkDLine*>(0)),
-            static_cast<SkIntersections*>(0));
-    double rootVals[2];
-    int roots = q.verticalIntersect(pt.fX, rootVals);
-    for (int index = 0; index < roots; ++index) {
-        double t = rootVals[index];
-        SkDPoint qPt = quad.ptAtT(t);
-        if (AlmostEqualUlps(qPt.fY, pt.fY)) {
-            return t;
-        }
-    }
-    return -1;
-}
-
-double SkIntersections::Axial(const SkDQuad& q1, const SkDPoint& p, bool vertical) {
-    if (vertical) {
-        return verticalIntersect(q1, p);
-    }
-    return horizontalIntersect(q1, p);
-}
-
 int SkIntersections::horizontal(const SkDQuad& quad, double left, double right, double y,
                                 bool flipped) {
     SkDLine line = {{{ left, y }, { right, y }}};