OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_GFX_QUAD_F_H_ | |
6 #define UI_GFX_QUAD_F_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "ui/base/ui_export.h" | |
11 #include "ui/gfx/point_f.h" | |
12 #include "ui/gfx/rect_f.h" | |
13 | |
14 namespace gfx { | |
15 | |
16 // A Quad is defined by four corners, allowing it to have edges that are not | |
17 // axis-aligned, unlike a Rect. | |
18 class UI_EXPORT QuadF { | |
19 public: | |
20 QuadF(); | |
21 QuadF(const PointF& p1, const PointF& p2, const PointF& p3, const PointF& p4); | |
22 explicit QuadF(const RectF& rect); | |
23 ~QuadF(); | |
24 | |
25 void operator=(const QuadF& quad); | |
26 void operator=(const RectF& rect); | |
27 | |
28 void set_p1(const PointF& p) { p1_ = p; } | |
29 void set_p2(const PointF& p) { p2_ = p; } | |
30 void set_p3(const PointF& p) { p3_ = p; } | |
31 void set_p4(const PointF& p) { p4_ = p; } | |
32 | |
33 PointF p1() const { return p1_; } | |
sky
2012/11/02 15:49:43
const PointF&
tfarina
2012/11/02 15:53:30
See my email to Peter about this.
The subject is:
danakj
2012/11/02 15:55:00
Done.
| |
34 PointF p2() const { return p2_; } | |
35 PointF p3() const { return p3_; } | |
36 PointF p4() const { return p4_; } | |
37 | |
38 // Returns true if the quad is an axis-aligned rectangle. | |
39 bool IsRectilinear() const; | |
40 | |
41 // Returns true if the points of the quad are in counter-clockwise order. This | |
42 // assumes that the quad is convex, and that no three points are collinear. | |
43 bool IsCounterClockwise() const; | |
44 | |
45 // Returns true if the |point| is contained within the quad, or lies on on | |
46 // edge of the quad. | |
47 bool Contains(const gfx::PointF& point) const; | |
48 | |
49 // Returns a rectangle that bounds the four points of the quad. The points of | |
50 // the quad may lie on the right/bottom edge of the resulting rectangle, | |
51 // rather than being strictly inside it. | |
52 RectF BoundingBox() const; | |
53 | |
54 // Add a vector to the quad, offseting each point in the quad by the vector. | |
55 void operator+=(const Vector2dF& rhs); | |
56 // Subtract a vector from the quad, offseting each point in the quad by the | |
57 // inverse of the vector. | |
58 void operator-=(const Vector2dF& rhs); | |
59 | |
60 // Scale each point in the quad by the |scale| factor. | |
61 void Scale(float scale) { Scale(scale, scale); } | |
62 | |
63 // Scale each point in the quad by the scale factors along each axis. | |
64 void Scale(float x_scale, float y_scale); | |
65 | |
66 // Returns a string representation of quad. | |
67 std::string ToString() const; | |
68 | |
69 private: | |
70 PointF p1_; | |
71 PointF p2_; | |
72 PointF p3_; | |
73 PointF p4_; | |
74 }; | |
75 | |
76 inline bool operator==(const QuadF& lhs, const QuadF& rhs) { | |
77 return lhs.p1() == rhs.p1() && lhs.p2() == rhs.p2() | |
78 && lhs.p3() == rhs.p3() && lhs.p4() == rhs.p4(); | |
sky
2012/11/02 15:49:43
&& on previous side.
danakj
2012/11/02 15:55:00
Done.
| |
79 } | |
80 | |
81 inline bool operator!=(const QuadF& lhs, const QuadF& rhs) { | |
82 return !(lhs == rhs); | |
83 } | |
84 | |
85 // Add a vector to a quad, offseting each point in the quad by the vector. | |
86 UI_EXPORT QuadF operator+(const QuadF& lhs, const Vector2dF& rhs); | |
87 // Subtract a vector from a quad, offseting each point in the quad by the | |
88 // inverse of the vector. | |
89 UI_EXPORT QuadF operator-(const QuadF& lhs, const Vector2dF& rhs); | |
90 | |
91 } // namespace gfx | |
92 | |
93 #endif // UI_GFX_QUAD_F_H_ | |
OLD | NEW |