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

Unified Diff: ui/gfx/geometry/quad_f.cc

Issue 458113002: Optimize QuadF's IsCounterClockwise function (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 | « AUTHORS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/geometry/quad_f.cc
diff --git a/ui/gfx/geometry/quad_f.cc b/ui/gfx/geometry/quad_f.cc
index dbc50458b3fa1e04aedfdee3c51d5ae00351b46a..a384ea06dcc53e9c76be8e54ebbb7525a00360de 100644
--- a/ui/gfx/geometry/quad_f.cc
+++ b/ui/gfx/geometry/quad_f.cc
@@ -45,17 +45,16 @@ bool QuadF::IsCounterClockwise() const {
// pointing downards.
// Reference: http://mathworld.wolfram.com/PolygonArea.html
+ float tmp1 = p2_.y() - p4_.y();
danakj 2014/08/11 14:18:49 how about naming this p24 or something more descri
kui.zheng 2014/08/12 04:20:55 Done.
+ float tmp2 = p3_.y() - p1_.y();
danakj 2014/08/11 14:18:49 ditto
kui.zheng 2014/08/12 04:20:55 Done.
+
// Up-cast to double so this cannot overflow.
- double determinant1 = static_cast<double>(p1_.x()) * p2_.y()
- - static_cast<double>(p2_.x()) * p1_.y();
- double determinant2 = static_cast<double>(p2_.x()) * p3_.y()
- - static_cast<double>(p3_.x()) * p2_.y();
- double determinant3 = static_cast<double>(p3_.x()) * p4_.y()
- - static_cast<double>(p4_.x()) * p3_.y();
- double determinant4 = static_cast<double>(p4_.x()) * p1_.y()
- - static_cast<double>(p1_.x()) * p4_.y();
-
- return determinant1 + determinant2 + determinant3 + determinant4 < 0;
+ double determinant1 = static_cast<double>(p1_.x()) * tmp1;
Ian Vollick 2014/08/11 14:39:09 If I'm understanding things, determinant1 here is
kui.zheng 2014/08/12 04:20:55 Right, This patch just refactoring the computation
+ double determinant2 = static_cast<double>(p2_.x()) * tmp2;
+ double determinant3 = static_cast<double>(p3_.x()) * tmp1;
+ double determinant4 = static_cast<double>(p4_.x()) * tmp2;
+
+ return determinant1 + determinant2 < determinant3 + determinant4;
}
static inline bool PointIsInTriangle(const PointF& point,
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698