diff options
-rw-r--r-- | include/core/SkPoint.h | 10 | ||||
-rw-r--r-- | src/core/SkPath.cpp | 13 | ||||
-rw-r--r-- | src/core/SkPoint.cpp | 3 | ||||
-rw-r--r-- | tests/PointTest.cpp | 6 |
4 files changed, 17 insertions, 15 deletions
diff --git a/include/core/SkPoint.h b/include/core/SkPoint.h index 18b371f2ca..323c824a1b 100644 --- a/include/core/SkPoint.h +++ b/include/core/SkPoint.h @@ -258,25 +258,25 @@ struct SK_API SkPoint { /** Set the point (vector) to be unit-length in the same direction as it already points. If the point has a degenerate length (i.e. nearly 0) - then return false and do nothing; otherwise return true. + then set it to (0,0) and return false; otherwise return true. */ bool normalize(); /** Set the point (vector) to be unit-length in the same direction as the x,y params. If the vector (x,y) has a degenerate length (i.e. nearly 0) - then return false and do nothing, otherwise return true. + then set it to (0,0) and return false, otherwise return true. */ bool setNormalize(SkScalar x, SkScalar y); /** Scale the point (vector) to have the specified length, and return that length. If the original length is degenerately small (nearly zero), - do nothing and return false, otherwise return true. + set it to (0,0) and return false, otherwise return true. */ bool setLength(SkScalar length); /** Set the point (vector) to have the specified length in the same direction as (x,y). If the vector (x,y) has a degenerate length - (i.e. nearly 0) then return false and do nothing, otherwise return true. + (i.e. nearly 0) then set it to (0,0) and return false, otherwise return true. */ bool setLength(SkScalar x, SkScalar y, SkScalar length); @@ -423,7 +423,7 @@ struct SK_API SkPoint { static SkScalar Length(SkScalar x, SkScalar y); /** Normalize pt, returning its previous length. If the prev length is too - small (degenerate), return 0 and leave pt unchanged. This uses the same + small (degenerate), set pt to (0,0) and return 0. This uses the same tolerance as CanNormalize. Note that this method may be significantly more expensive than diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp index a08abbd14b..2cb33e2012 100644 --- a/src/core/SkPath.cpp +++ b/src/core/SkPath.cpp @@ -1287,7 +1287,12 @@ void SkPath::addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle */ void SkPath::arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius) { - SkVector before, after; + if (radius == 0) { + this->lineTo(x1, y1); + return; + } + + SkVector before, after; // need to know our prev pt so we can construct tangent vectors { @@ -1295,12 +1300,6 @@ void SkPath::arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, this->getLastPt(&start); // Handle degenerate cases by adding a line to the first point and // bailing out. - if ((x1 == start.fX && y1 == start.fY) || - (x1 == x2 && y1 == y2) || - radius == 0) { - this->lineTo(x1, y1); - return; - } before.setNormalize(x1 - start.fX, y1 - start.fY); after.setNormalize(x2 - x1, y2 - y1); } diff --git a/src/core/SkPoint.cpp b/src/core/SkPoint.cpp index 2970e35c54..20bc33666e 100644 --- a/src/core/SkPoint.cpp +++ b/src/core/SkPoint.cpp @@ -100,6 +100,7 @@ SkScalar SkPoint::Normalize(SkPoint* pt) { float y = pt->fY; float mag2; if (isLengthNearlyZero(x, y, &mag2)) { + pt->set(0, 0); return 0; } @@ -147,6 +148,7 @@ SkScalar SkPoint::Length(SkScalar dx, SkScalar dy) { bool SkPoint::setLength(float x, float y, float length) { float mag2; if (isLengthNearlyZero(x, y, &mag2)) { + this->set(0, 0); return false; } @@ -183,6 +185,7 @@ bool SkPoint::setLengthFast(float length) { bool SkPoint::setLengthFast(float x, float y, float length) { float mag2; if (isLengthNearlyZero(x, y, &mag2)) { + this->set(0, 0); return false; } diff --git a/tests/PointTest.cpp b/tests/PointTest.cpp index fed443a02e..08ce7208eb 100644 --- a/tests/PointTest.cpp +++ b/tests/PointTest.cpp @@ -108,13 +108,13 @@ static void test_overflow(skiatest::Reporter* reporter) { // report failure if we try to normalize them. static void test_underflow(skiatest::Reporter* reporter) { SkPoint pt = { 1.0e-37f, 1.0e-37f }; - SkPoint copy = pt; + const SkPoint empty = { 0, 0 }; REPORTER_ASSERT(reporter, 0 == SkPoint::Normalize(&pt)); - REPORTER_ASSERT(reporter, pt == copy); // pt is unchanged + REPORTER_ASSERT(reporter, pt == empty); REPORTER_ASSERT(reporter, !pt.setLength(SK_Scalar1)); - REPORTER_ASSERT(reporter, pt == copy); // pt is unchanged + REPORTER_ASSERT(reporter, pt == empty); } DEF_TEST(Point, reporter) { |