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

Unified Diff: src/pathops/SkPathOpsPoint.h

Issue 2128633003: pathops coincidence and security rewrite (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: require resulting t to be between 0 and 1 Created 4 years, 5 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
Index: src/pathops/SkPathOpsPoint.h
diff --git a/src/pathops/SkPathOpsPoint.h b/src/pathops/SkPathOpsPoint.h
index e3f722bede18219384532a11c1975064304d730d..f30f155e8fc451afe1c6c593b1b06634b7ea585e 100644
--- a/src/pathops/SkPathOpsPoint.h
+++ b/src/pathops/SkPathOpsPoint.h
@@ -58,12 +58,20 @@ struct SkDVector {
}
// similar to cross, this bastardization considers nearly coincident to be zero
+ // uses ulps epsilon == 16
double crossCheck(const SkDVector& a) const {
double xy = fX * a.fY;
double yx = fY * a.fX;
return AlmostEqualUlps(xy, yx) ? 0 : xy - yx;
}
+ // allow tinier numbers
+ double crossNoNormalCheck(const SkDVector& a) const {
+ double xy = fX * a.fY;
+ double yx = fY * a.fX;
+ return AlmostEqualUlpsNoNormalCheck(xy, yx) ? 0 : xy - yx;
+ }
+
double dot(const SkDVector& a) const {
return fX * a.fX + fY * a.fY;
}
@@ -75,6 +83,12 @@ struct SkDVector {
double lengthSquared() const {
return fX * fX + fY * fY;
}
+
+ void normalize() {
+ double inverseLength = 1 / this->length();
+ fX *= inverseLength;
+ fY *= inverseLength;
+ }
};
struct SkDPoint {
@@ -164,7 +178,7 @@ struct SkDPoint {
float tiniest = SkTMin(SkTMin(SkTMin(a.fX, b.fX), a.fY), b.fY);
float largest = SkTMax(SkTMax(SkTMax(a.fX, b.fX), a.fY), b.fY);
largest = SkTMax(largest, -tiniest);
- return AlmostPequalUlps((double) largest, largest + dist); // is dist within ULPS tolerance?
+ return AlmostDequalUlps((double) largest, largest + dist); // is dist within ULPS tolerance?
}
// only used by testing

Powered by Google App Engine
This is Rietveld 408576698