Index: ui/gfx/geometry/quad_f.cc |
diff --git a/ui/gfx/geometry/quad_f.cc b/ui/gfx/geometry/quad_f.cc |
index 1283b0dc3bbc4a1a64542840945d1f8c360d83f1..8c9156d34a32a63f1f69535acd6fd105ea98a8fd 100644 |
--- a/ui/gfx/geometry/quad_f.cc |
+++ b/ui/gfx/geometry/quad_f.cc |
@@ -65,21 +65,14 @@ static inline bool PointIsInTriangle(const PointF& point, |
// Compute the barycentric coordinates of |point| relative to the triangle |
// (r1, r2, r3). This algorithm comes from Christer Ericson's Real-Time |
danakj
2014/05/16 15:43:44
Can you update this comment with a citation on the
jdduke (slow)
2014/05/16 16:49:47
Hmm, the algorithm is the same (barycentric coords
danakj
2014/05/16 17:01:48
Ahhh yeh ok, showing the equation we're solving so
jdduke (slow)
2014/05/16 17:30:32
Done.
|
// Collision Detection. |
- Vector2dF v0 = r2 - r1; |
- Vector2dF v1 = r3 - r1; |
- Vector2dF v2 = point - r1; |
- |
- double dot00 = DotProduct(v0, v0); |
- double dot01 = DotProduct(v0, v1); |
- double dot11 = DotProduct(v1, v1); |
- double dot20 = DotProduct(v2, v0); |
- double dot21 = DotProduct(v2, v1); |
- |
- double denom = dot00 * dot11 - dot01 * dot01; |
- |
- double v = (dot11 * dot20 - dot01 * dot21) / denom; |
- double w = (dot00 * dot21 - dot01 * dot20) / denom; |
- double u = 1 - v - w; |
+ Vector2dF r31 = r1 - r3; |
+ Vector2dF r32 = r2 - r3; |
+ Vector2dF r3p = point - r3; |
+ |
+ float denom = r32.y() * r31.x() - r32.x() * r31.y(); |
+ float v = (r32.y() * r3p.x() - r32.x() * r3p.y()) / denom; |
+ float w = (r31.x() * r3p.y() - r31.y() * r3p.x()) / denom; |
+ float u = 1.f - v - w; |
// Use the barycentric coordinates to test if |point| is inside the |
// triangle (r1, r2, r2). |