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

Unified Diff: src/core/SkPath.cpp

Issue 48783002: perpendicular round rects; fuzzy convexity (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix release warning Created 7 years, 2 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
« src/core/SkGeometry.cpp ('K') | « src/core/SkGeometry.cpp ('k') | no next file » | 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 9df62850fd2eb5bc9cf442dc4675b7091cded8c1..d49a964492f483cc10b7063fe18a091511466d0a 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -2283,8 +2283,20 @@ void SkPath::validate() const {
static int sign(SkScalar x) { return x < 0; }
#define kValueNeverReturnedBySign 2
-static int CrossProductSign(const SkVector& a, const SkVector& b) {
- return SkScalarSignAsInt(SkPoint::CrossProduct(a, b));
+static bool AlmostEqual(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.
+ const int epsilon = 16;
+ if (!SkScalarIsFinite(compA) || !SkScalarIsFinite(compB)) {
+ return false;
+ }
+ if (sk_float_abs(compA) <= FLT_EPSILON && sk_float_abs(compB) <= FLT_EPSILON) {
+ return true;
+ }
+ int aBits = SkFloatAs2sCompliment(compA);
+ int bBits = SkFloatAs2sCompliment(compB);
+ return aBits < bBits + epsilon && bBits < aBits + epsilon;
}
// only valid for a single contour
@@ -2295,6 +2307,7 @@ struct Convexicator {
, fDirection(SkPath::kUnknown_Direction) {
fSign = 0;
// warnings
+ fLastPt.set(0, 0);
fCurrPt.set(0, 0);
fVec0.set(0, 0);
fVec1.set(0, 0);
@@ -2320,6 +2333,7 @@ struct Convexicator {
} else {
SkVector vec = pt - fCurrPt;
if (vec.fX || vec.fY) {
+ fLastPt = fCurrPt;
fCurrPt = pt;
if (++fPtCount == 2) {
fFirstVec = fVec1 = vec;
@@ -2353,7 +2367,11 @@ private:
SkASSERT(vec.fX || vec.fY);
fVec0 = fVec1;
fVec1 = vec;
- int sign = CrossProductSign(fVec0, fVec1);
+ SkScalar cross = SkPoint::CrossProduct(fVec0, fVec1);
reed1 2013/10/29 20:50:06 I need some comment block or other way to know wha
+ 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) {
@@ -2369,6 +2387,7 @@ private:
}
}
+ SkPoint fLastPt;
SkPoint fCurrPt;
SkVector fVec0, fVec1, fFirstVec;
int fPtCount; // non-degenerate points
« src/core/SkGeometry.cpp ('K') | « src/core/SkGeometry.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698