| 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_QUAD_F_H_ | 5 #ifndef UI_GFX_QUAD_F_H_ |
| 6 #define UI_GFX_QUAD_F_H_ | 6 #define UI_GFX_QUAD_F_H_ |
| 7 | 7 |
| 8 #include <cmath> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "ui/base/ui_export.h" | 11 #include "ui/base/ui_export.h" |
| 11 #include "ui/gfx/point_f.h" | 12 #include "ui/gfx/point_f.h" |
| 12 #include "ui/gfx/rect_f.h" | 13 #include "ui/gfx/rect_f.h" |
| 13 | 14 |
| 14 namespace gfx { | 15 namespace gfx { |
| 15 | 16 |
| 16 // A Quad is defined by four corners, allowing it to have edges that are not | 17 // A Quad is defined by four corners, allowing it to have edges that are not |
| 17 // axis-aligned, unlike a Rect. | 18 // axis-aligned, unlike a Rect. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // assumes that the quad is convex, and that no three points are collinear. | 50 // assumes that the quad is convex, and that no three points are collinear. |
| 50 bool IsCounterClockwise() const; | 51 bool IsCounterClockwise() const; |
| 51 | 52 |
| 52 // Returns true if the |point| is contained within the quad, or lies on on | 53 // Returns true if the |point| is contained within the quad, or lies on on |
| 53 // edge of the quad. | 54 // edge of the quad. |
| 54 bool Contains(const gfx::PointF& point) const; | 55 bool Contains(const gfx::PointF& point) const; |
| 55 | 56 |
| 56 // Returns a rectangle that bounds the four points of the quad. The points of | 57 // Returns a rectangle that bounds the four points of the quad. The points of |
| 57 // the quad may lie on the right/bottom edge of the resulting rectangle, | 58 // the quad may lie on the right/bottom edge of the resulting rectangle, |
| 58 // rather than being strictly inside it. | 59 // rather than being strictly inside it. |
| 59 RectF BoundingBox() const; | 60 RectF BoundingBox() const { |
| 61 float rl = std::min(std::min(p1_.x(), p2_.x()), std::min(p3_.x(), p4_.x())); |
| 62 float rr = std::max(std::max(p1_.x(), p2_.x()), std::max(p3_.x(), p4_.x())); |
| 63 float rt = std::min(std::min(p1_.y(), p2_.y()), std::min(p3_.y(), p4_.y())); |
| 64 float rb = std::max(std::max(p1_.y(), p2_.y()), std::max(p3_.y(), p4_.y())); |
| 65 return RectF(rl, rt, rr - rl, rb - rt); |
| 66 } |
| 60 | 67 |
| 61 // Add a vector to the quad, offseting each point in the quad by the vector. | 68 // Add a vector to the quad, offseting each point in the quad by the vector. |
| 62 void operator+=(const Vector2dF& rhs); | 69 void operator+=(const Vector2dF& rhs); |
| 63 // Subtract a vector from the quad, offseting each point in the quad by the | 70 // Subtract a vector from the quad, offseting each point in the quad by the |
| 64 // inverse of the vector. | 71 // inverse of the vector. |
| 65 void operator-=(const Vector2dF& rhs); | 72 void operator-=(const Vector2dF& rhs); |
| 66 | 73 |
| 67 // Scale each point in the quad by the |scale| factor. | 74 // Scale each point in the quad by the |scale| factor. |
| 68 void Scale(float scale) { Scale(scale, scale); } | 75 void Scale(float scale) { Scale(scale, scale); } |
| 69 | 76 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 92 | 99 |
| 93 // Add a vector to a quad, offseting each point in the quad by the vector. | 100 // Add a vector to a quad, offseting each point in the quad by the vector. |
| 94 UI_EXPORT QuadF operator+(const QuadF& lhs, const Vector2dF& rhs); | 101 UI_EXPORT QuadF operator+(const QuadF& lhs, const Vector2dF& rhs); |
| 95 // Subtract a vector from a quad, offseting each point in the quad by the | 102 // Subtract a vector from a quad, offseting each point in the quad by the |
| 96 // inverse of the vector. | 103 // inverse of the vector. |
| 97 UI_EXPORT QuadF operator-(const QuadF& lhs, const Vector2dF& rhs); | 104 UI_EXPORT QuadF operator-(const QuadF& lhs, const Vector2dF& rhs); |
| 98 | 105 |
| 99 } // namespace gfx | 106 } // namespace gfx |
| 100 | 107 |
| 101 #endif // UI_GFX_QUAD_F_H_ | 108 #endif // UI_GFX_QUAD_F_H_ |
| OLD | NEW |