Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Unified Diff: src/core/SkPath.cpp

Issue 298973004: In convexity checker don't advance last vector when x-product isn't significant. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: remove debugging code Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/PathTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPath.cpp
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 9f94b726872dd9e84f3f8426f150861096d45df1..d51a40e2718e391c0ec288733ac31c74b5401f99 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -2223,7 +2223,7 @@ void SkPath::validate() const {
static int sign(SkScalar x) { return x < 0; }
#define kValueNeverReturnedBySign 2
-static bool AlmostEqual(SkScalar compA, SkScalar compB) {
+static bool almost_equal(SkScalar compA, SkScalar compB) {
// The error epsilon was empirically derived; worse case round rects
// with a mid point outset by 2x float epsilon in tests had an error
// of 12.
@@ -2247,8 +2247,7 @@ struct Convexicator {
// warnings
fLastPt.set(0, 0);
fCurrPt.set(0, 0);
- fVec0.set(0, 0);
- fVec1.set(0, 0);
+ fLastVec.set(0, 0);
fFirstVec.set(0, 0);
fDx = fDy = 0;
@@ -2274,7 +2273,7 @@ struct Convexicator {
fLastPt = fCurrPt;
fCurrPt = pt;
if (++fPtCount == 2) {
- fFirstVec = fVec1 = vec;
+ fFirstVec = fLastVec = vec;
} else {
SkASSERT(fPtCount > 2);
this->addVec(vec);
@@ -2303,31 +2302,28 @@ struct Convexicator {
private:
void addVec(const SkVector& vec) {
SkASSERT(vec.fX || vec.fY);
- fVec0 = fVec1;
- fVec1 = vec;
- SkScalar cross = SkPoint::CrossProduct(fVec0, fVec1);
+ SkScalar cross = SkPoint::CrossProduct(fLastVec, vec);
SkScalar smallest = SkTMin(fCurrPt.fX, SkTMin(fCurrPt.fY, SkTMin(fLastPt.fX, fLastPt.fY)));
SkScalar largest = SkTMax(fCurrPt.fX, SkTMax(fCurrPt.fY, SkTMax(fLastPt.fX, fLastPt.fY)));
largest = SkTMax(largest, -smallest);
- int sign = AlmostEqual(largest, largest + cross) ? 0 : SkScalarSignAsInt(cross);
- if (0 == fSign) {
- fSign = sign;
- if (1 == sign) {
- fDirection = SkPath::kCW_Direction;
- } else if (-1 == sign) {
- fDirection = SkPath::kCCW_Direction;
- }
- } else if (sign) {
- if (fSign != sign) {
+ if (!almost_equal(largest, largest + cross)) {
+ int sign = SkScalarSignAsInt(cross);
+ if (0 == fSign) {
+ fSign = sign;
+ fDirection = (1 == sign) ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
+ } else if (sign && fSign != sign) {
fConvexity = SkPath::kConcave_Convexity;
fDirection = SkPath::kUnknown_Direction;
}
+ fLastVec = vec;
}
}
SkPoint fLastPt;
SkPoint fCurrPt;
- SkVector fVec0, fVec1, fFirstVec;
+ // fLastVec does not necessarily start at fLastPt. We only advance it when the cross product
+ // value with the current vec is deemed to be of a significant value.
+ SkVector fLastVec, fFirstVec;
int fPtCount; // non-degenerate points
int fSign;
SkPath::Convexity fConvexity;
« no previous file with comments | « no previous file | tests/PathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698