| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <cmath> | 11 #include <cmath> |
| 12 #include <iosfwd> | 12 #include <iosfwd> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "ui/gfx/geometry/point_f.h" | 16 #include "ui/gfx/geometry/point_f.h" |
| 17 #include "ui/gfx/geometry/rect_f.h" | 17 #include "ui/gfx/geometry/rect_f.h" |
| 18 #include "ui/gfx/gfx_export.h" | 18 #include "ui/gfx/gfx_export.h" |
| 19 | 19 |
| 20 namespace gfx { | 20 namespace gfx { |
| 21 | 21 |
| 22 // A Quad is defined by four corners, allowing it to have edges that are not | 22 // A Quad is defined by four corners, allowing it to have edges that are not |
| 23 // axis-aligned, unlike a Rect. | 23 // axis-aligned, unlike a Rect. |
| 24 class GFX_EXPORT QuadF { | 24 class GFX_EXPORT QuadF { |
| 25 public: | 25 public: |
| 26 QuadF() {} | 26 constexpr QuadF() = default; |
| 27 QuadF(const PointF& p1, const PointF& p2, const PointF& p3, const PointF& p4) | 27 constexpr QuadF(const PointF& p1, |
| 28 : p1_(p1), | 28 const PointF& p2, |
| 29 p2_(p2), | 29 const PointF& p3, |
| 30 p3_(p3), | 30 const PointF& p4) |
| 31 p4_(p4) {} | 31 : p1_(p1), p2_(p2), p3_(p3), p4_(p4) {} |
| 32 | 32 |
| 33 explicit QuadF(const RectF& rect) | 33 constexpr explicit QuadF(const RectF& rect) |
| 34 : p1_(rect.x(), rect.y()), | 34 : p1_(rect.x(), rect.y()), |
| 35 p2_(rect.right(), rect.y()), | 35 p2_(rect.right(), rect.y()), |
| 36 p3_(rect.right(), rect.bottom()), | 36 p3_(rect.right(), rect.bottom()), |
| 37 p4_(rect.x(), rect.bottom()) {} | 37 p4_(rect.x(), rect.bottom()) {} |
| 38 | 38 |
| 39 void operator=(const RectF& rect); | 39 void operator=(const RectF& rect); |
| 40 | 40 |
| 41 void set_p1(const PointF& p) { p1_ = p; } | 41 void set_p1(const PointF& p) { p1_ = p; } |
| 42 void set_p2(const PointF& p) { p2_ = p; } | 42 void set_p2(const PointF& p) { p2_ = p; } |
| 43 void set_p3(const PointF& p) { p3_ = p; } | 43 void set_p3(const PointF& p) { p3_ = p; } |
| 44 void set_p4(const PointF& p) { p4_ = p; } | 44 void set_p4(const PointF& p) { p4_ = p; } |
| 45 | 45 |
| 46 const PointF& p1() const { return p1_; } | 46 constexpr const PointF& p1() const { return p1_; } |
| 47 const PointF& p2() const { return p2_; } | 47 constexpr const PointF& p2() const { return p2_; } |
| 48 const PointF& p3() const { return p3_; } | 48 constexpr const PointF& p3() const { return p3_; } |
| 49 const PointF& p4() const { return p4_; } | 49 constexpr const PointF& p4() const { return p4_; } |
| 50 | 50 |
| 51 // Returns true if the quad is an axis-aligned rectangle. | 51 // Returns true if the quad is an axis-aligned rectangle. |
| 52 bool IsRectilinear() const; | 52 bool IsRectilinear() const; |
| 53 | 53 |
| 54 // Returns true if the points of the quad are in counter-clockwise order. This | 54 // Returns true if the points of the quad are in counter-clockwise order. This |
| 55 // assumes that the quad is convex, and that no three points are collinear. | 55 // assumes that the quad is convex, and that no three points are collinear. |
| 56 bool IsCounterClockwise() const; | 56 bool IsCounterClockwise() const; |
| 57 | 57 |
| 58 // Returns true if the |point| is contained within the quad, or lies on on | 58 // Returns true if the |point| is contained within the quad, or lies on on |
| 59 // edge of the quad. This assumes that the quad is convex. | 59 // edge of the quad. This assumes that the quad is convex. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 GFX_EXPORT QuadF operator-(const QuadF& lhs, const Vector2dF& rhs); | 121 GFX_EXPORT QuadF operator-(const QuadF& lhs, const Vector2dF& rhs); |
| 122 | 122 |
| 123 // This is declared here for use in gtest-based unit tests but is defined in | 123 // This is declared here for use in gtest-based unit tests but is defined in |
| 124 // the gfx_test_support target. Depend on that to use this in your unit test. | 124 // the gfx_test_support target. Depend on that to use this in your unit test. |
| 125 // This should not be used in production code - call ToString() instead. | 125 // This should not be used in production code - call ToString() instead. |
| 126 void PrintTo(const QuadF& quad, ::std::ostream* os); | 126 void PrintTo(const QuadF& quad, ::std::ostream* os); |
| 127 | 127 |
| 128 } // namespace gfx | 128 } // namespace gfx |
| 129 | 129 |
| 130 #endif // UI_GFX_GEOMETRY_QUAD_F_H_ | 130 #endif // UI_GFX_GEOMETRY_QUAD_F_H_ |
| OLD | NEW |