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 #ifndef UI_GFX_GEOMETRY_QUAD_F_H_ | 5 #ifndef UI_GFX_GEOMETRY_QUAD_F_H_ |
6 #define UI_GFX_GEOMETRY_QUAD_F_H_ | 6 #define UI_GFX_GEOMETRY_QUAD_F_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <cmath> | 9 #include <cmath> |
10 #include <iosfwd> | 10 #include <iosfwd> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // the quad may lie on the right/bottom edge of the resulting rectangle, | 60 // the quad may lie on the right/bottom edge of the resulting rectangle, |
61 // rather than being strictly inside it. | 61 // rather than being strictly inside it. |
62 RectF BoundingBox() const { | 62 RectF BoundingBox() const { |
63 float rl = std::min(std::min(p1_.x(), p2_.x()), std::min(p3_.x(), p4_.x())); | 63 float rl = std::min(std::min(p1_.x(), p2_.x()), std::min(p3_.x(), p4_.x())); |
64 float rr = std::max(std::max(p1_.x(), p2_.x()), std::max(p3_.x(), p4_.x())); | 64 float rr = std::max(std::max(p1_.x(), p2_.x()), std::max(p3_.x(), p4_.x())); |
65 float rt = std::min(std::min(p1_.y(), p2_.y()), std::min(p3_.y(), p4_.y())); | 65 float rt = std::min(std::min(p1_.y(), p2_.y()), std::min(p3_.y(), p4_.y())); |
66 float rb = std::max(std::max(p1_.y(), p2_.y()), std::max(p3_.y(), p4_.y())); | 66 float rb = std::max(std::max(p1_.y(), p2_.y()), std::max(p3_.y(), p4_.y())); |
67 return RectF(rl, rt, rr - rl, rb - rt); | 67 return RectF(rl, rt, rr - rl, rb - rt); |
68 } | 68 } |
69 | 69 |
| 70 // Realigns the corners in the quad by rotating them n corners to the right. |
| 71 void Realign(size_t times) { |
| 72 for (size_t i = 0; i < times % 4; ++i) { |
| 73 PointF temp = p1_; |
| 74 p1_ = p2_; |
| 75 p2_ = p3_; |
| 76 p3_ = p4_; |
| 77 p4_ = temp; |
| 78 } |
| 79 } |
| 80 |
70 // Add a vector to the quad, offseting each point in the quad by the vector. | 81 // Add a vector to the quad, offseting each point in the quad by the vector. |
71 void operator+=(const Vector2dF& rhs); | 82 void operator+=(const Vector2dF& rhs); |
72 // Subtract a vector from the quad, offseting each point in the quad by the | 83 // Subtract a vector from the quad, offseting each point in the quad by the |
73 // inverse of the vector. | 84 // inverse of the vector. |
74 void operator-=(const Vector2dF& rhs); | 85 void operator-=(const Vector2dF& rhs); |
75 | 86 |
76 // Scale each point in the quad by the |scale| factor. | 87 // Scale each point in the quad by the |scale| factor. |
77 void Scale(float scale) { Scale(scale, scale); } | 88 void Scale(float scale) { Scale(scale, scale); } |
78 | 89 |
79 // Scale each point in the quad by the scale factors along each axis. | 90 // Scale each point in the quad by the scale factors along each axis. |
(...skipping 26 matching lines...) Expand all Loading... |
106 GFX_EXPORT QuadF operator-(const QuadF& lhs, const Vector2dF& rhs); | 117 GFX_EXPORT QuadF operator-(const QuadF& lhs, const Vector2dF& rhs); |
107 | 118 |
108 // This is declared here for use in gtest-based unit tests but is defined in | 119 // This is declared here for use in gtest-based unit tests but is defined in |
109 // the gfx_test_support target. Depend on that to use this in your unit test. | 120 // the gfx_test_support target. Depend on that to use this in your unit test. |
110 // This should not be used in production code - call ToString() instead. | 121 // This should not be used in production code - call ToString() instead. |
111 void PrintTo(const QuadF& quad, ::std::ostream* os); | 122 void PrintTo(const QuadF& quad, ::std::ostream* os); |
112 | 123 |
113 } // namespace gfx | 124 } // namespace gfx |
114 | 125 |
115 #endif // UI_GFX_GEOMETRY_QUAD_F_H_ | 126 #endif // UI_GFX_GEOMETRY_QUAD_F_H_ |
OLD | NEW |