| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/geometry/quad_f.h" | 5 #include "ui/gfx/geometry/quad_f.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // Compute the barycentric coordinates (u, v, w) of |point| relative to the | 69 // Compute the barycentric coordinates (u, v, w) of |point| relative to the |
| 70 // triangle (r1, r2, r3) by the solving the system of equations: | 70 // triangle (r1, r2, r3) by the solving the system of equations: |
| 71 // 1) point = u * r1 + v * r2 + w * r3 | 71 // 1) point = u * r1 + v * r2 + w * r3 |
| 72 // 2) u + v + w = 1 | 72 // 2) u + v + w = 1 |
| 73 // This algorithm comes from Christer Ericson's Real-Time Collision Detection. | 73 // This algorithm comes from Christer Ericson's Real-Time Collision Detection. |
| 74 | 74 |
| 75 Vector2dF r31 = r1 - r3; | 75 Vector2dF r31 = r1 - r3; |
| 76 Vector2dF r32 = r2 - r3; | 76 Vector2dF r32 = r2 - r3; |
| 77 Vector2dF r3p = point - r3; | 77 Vector2dF r3p = point - r3; |
| 78 | 78 |
| 79 float denom = r32.y() * r31.x() - r32.x() * r31.y(); | 79 // Promote to doubles so all the math below is done with doubles, because |
| 80 float u = (r32.y() * r3p.x() - r32.x() * r3p.y()) / denom; | 80 // otherwise it gets incorrect results on arm64. |
| 81 float v = (r31.x() * r3p.y() - r31.y() * r3p.x()) / denom; | 81 double r31x = r31.x(); |
| 82 float w = 1.f - u - v; | 82 double r31y = r31.y(); |
| 83 double r32x = r32.x(); |
| 84 double r32y = r32.y(); |
| 85 |
| 86 double denom = r32y * r31x - r32x * r31y; |
| 87 double u = (r32y * r3p.x() - r32x * r3p.y()) / denom; |
| 88 double v = (r31x * r3p.y() - r31y * r3p.x()) / denom; |
| 89 double w = 1.0 - u - v; |
| 83 | 90 |
| 84 // Use the barycentric coordinates to test if |point| is inside the | 91 // Use the barycentric coordinates to test if |point| is inside the |
| 85 // triangle (r1, r2, r2). | 92 // triangle (r1, r2, r2). |
| 86 return (u >= 0) && (v >= 0) && (w >= 0); | 93 return (u >= 0) && (v >= 0) && (w >= 0); |
| 87 } | 94 } |
| 88 | 95 |
| 89 bool QuadF::Contains(const PointF& point) const { | 96 bool QuadF::Contains(const PointF& point) const { |
| 90 return PointIsInTriangle(point, p1_, p2_, p3_) | 97 return PointIsInTriangle(point, p1_, p2_, p3_) |
| 91 || PointIsInTriangle(point, p1_, p3_, p4_); | 98 || PointIsInTriangle(point, p1_, p3_, p4_); |
| 92 } | 99 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 118 return result; | 125 return result; |
| 119 } | 126 } |
| 120 | 127 |
| 121 QuadF operator-(const QuadF& lhs, const Vector2dF& rhs) { | 128 QuadF operator-(const QuadF& lhs, const Vector2dF& rhs) { |
| 122 QuadF result = lhs; | 129 QuadF result = lhs; |
| 123 result -= rhs; | 130 result -= rhs; |
| 124 return result; | 131 return result; |
| 125 } | 132 } |
| 126 | 133 |
| 127 } // namespace gfx | 134 } // namespace gfx |
| OLD | NEW |