Chromium Code Reviews| Index: src/pathops/SkPathOpsCurve.cpp |
| diff --git a/src/pathops/SkPathOpsCurve.cpp b/src/pathops/SkPathOpsCurve.cpp |
| index bf44d25e17c9b1ec12f7d85512bd5e2e2564f421..df67efaca5fbbb345104264336365ffe3b18d676 100644 |
| --- a/src/pathops/SkPathOpsCurve.cpp |
| +++ b/src/pathops/SkPathOpsCurve.cpp |
| @@ -8,6 +8,57 @@ |
| #include "SkPathOpsRect.h" |
| #include "SkPathOpsCurve.h" |
| + // this cheats and assumes that the perpendicular to the point is the closest ray to the curve |
| + // this case (where the line and the curve are nearly coincident) may be the only case that counts |
| +double SkDCurve::nearPoint(SkPath::Verb verb, const SkDPoint& xy, const SkDPoint& opp) const { |
| + int count = SkPathOpsVerbToPoints(verb); |
| + double minX = fCubic.fPts[0].fX; |
| + double maxX = minX; |
| + for (int index = 0; index < count; ++index) { |
| + minX = SkTMin(minX, fCubic.fPts[index].fX); |
| + maxX = SkTMax(maxX, fCubic.fPts[index].fX); |
| + } |
| + if (!AlmostBetweenUlps(minX, xy.fX, maxX)) { |
| + return -1; |
| + } |
| + double minY = fCubic.fPts[0].fY; |
| + double maxY = minY; |
| + for (int index = 0; index < count; ++index) { |
| + minY = SkTMin(minY, fCubic.fPts[index].fY); |
| + maxY = SkTMax(maxY, fCubic.fPts[index].fY); |
| + } |
| + if (!AlmostBetweenUlps(minY, xy.fY, maxY)) { |
| + return -1; |
| + } |
| + SkIntersections i; |
| + SkDLine perp = {{ xy, { xy.fX + opp.fY - xy.fY, xy.fY + xy.fX - opp.fX }}}; |
| + (*CurveDIntersectRay[verb])(*this, perp, &i); |
| + int minIndex = -1; |
| + double minDist = FLT_MAX; |
| + for (int index = 0; index < i.used(); ++index) { |
| + double dist = xy.distance(i.pt(index)); |
| + if (minDist > dist) { |
| + minDist = dist; |
| + minIndex = index; |
| + } |
| + } |
| + if (minIndex < 0) { |
| + return -1; |
| + } |
| + double largest = SkTMax(SkTMax(maxX, maxY), -SkTMin(minX, minY)); |
| + if (!AlmostEqualUlps_Pin(largest, largest + minDist)) { // is distance within ULPS tolerance? |
| + return -1; |
| + } |
| + return SkPinT(i[0][minIndex]); |
| +} |
| + |
| +void SkDCurve::offset(SkPath::Verb verb, const SkDVector& off) { |
| + int count = SkPathOpsVerbToPoints(verb); |
| + for (int index = 0; index < count; ++index) { |
| + fCubic.fPts[index] += off; |
| + } |
| +} |
| + |
| void SkDCurve::setConicBounds(const SkPoint curve[3], SkScalar curveWeight, |
| double tStart, double tEnd, SkPathOpsBounds* bounds) { |
| SkDConic dCurve; |
| @@ -18,7 +69,7 @@ void SkDCurve::setConicBounds(const SkPoint curve[3], SkScalar curveWeight, |
| SkDoubleToScalar(dRect.fRight), SkDoubleToScalar(dRect.fBottom)); |
| } |
| -void SkDCurve::setCubicBounds(const SkPoint curve[4], SkScalar , |
| +void SkDCurve::setCubicBounds(const SkPoint curve[4], SkScalar , |
|
herb_g
2016/07/18 15:13:39
Space before ","
caryclark
2016/07/18 15:55:49
See earlier reply.
|
| double tStart, double tEnd, SkPathOpsBounds* bounds) { |
| SkDCubic dCurve; |
| dCurve.set(curve); |