• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_GEOMETRY_POINT_F_H_
6 #define UI_GFX_GEOMETRY_POINT_F_H_
7 
8 #include <iosfwd>
9 #include <string>
10 
11 #include "ui/gfx/geometry/point_base.h"
12 #include "ui/gfx/geometry/vector2d_f.h"
13 #include "ui/gfx/gfx_export.h"
14 
15 namespace gfx {
16 
17 // A floating version of gfx::Point.
18 class GFX_EXPORT PointF : public PointBase<PointF, float, Vector2dF> {
19  public:
PointF()20   PointF() : PointBase<PointF, float, Vector2dF>(0, 0) {}
PointF(float x,float y)21   PointF(float x, float y) : PointBase<PointF, float, Vector2dF>(x, y) {}
~PointF()22   ~PointF() {}
23 
Scale(float scale)24   void Scale(float scale) {
25     Scale(scale, scale);
26   }
27 
Scale(float x_scale,float y_scale)28   void Scale(float x_scale, float y_scale) {
29     SetPoint(x() * x_scale, y() * y_scale);
30   }
31 
32   // Returns a string representation of point.
33   std::string ToString() const;
34 };
35 
36 inline bool operator==(const PointF& lhs, const PointF& rhs) {
37   return lhs.x() == rhs.x() && lhs.y() == rhs.y();
38 }
39 
40 inline bool operator!=(const PointF& lhs, const PointF& rhs) {
41   return !(lhs == rhs);
42 }
43 
44 inline PointF operator+(const PointF& lhs, const Vector2dF& rhs) {
45   PointF result(lhs);
46   result += rhs;
47   return result;
48 }
49 
50 inline PointF operator-(const PointF& lhs, const Vector2dF& rhs) {
51   PointF result(lhs);
52   result -= rhs;
53   return result;
54 }
55 
56 inline Vector2dF operator-(const PointF& lhs, const PointF& rhs) {
57   return Vector2dF(lhs.x() - rhs.x(), lhs.y() - rhs.y());
58 }
59 
PointAtOffsetFromOrigin(const Vector2dF & offset_from_origin)60 inline PointF PointAtOffsetFromOrigin(const Vector2dF& offset_from_origin) {
61   return PointF(offset_from_origin.x(), offset_from_origin.y());
62 }
63 
64 GFX_EXPORT PointF ScalePoint(const PointF& p, float x_scale, float y_scale);
65 
ScalePoint(const PointF & p,float scale)66 inline PointF ScalePoint(const PointF& p, float scale) {
67   return ScalePoint(p, scale, scale);
68 }
69 
70 #if !defined(COMPILER_MSVC) && !defined(__native_client__)
71 extern template class PointBase<PointF, float, Vector2dF>;
72 #endif
73 
74 // This is declared here for use in gtest-based unit tests but is defined in
75 // the gfx_test_support target. Depend on that to use this in your unit test.
76 // This should not be used in production code - call ToString() instead.
77 void PrintTo(const PointF& point, ::std::ostream* os);
78 
79 }  // namespace gfx
80 
81 #endif  // UI_GFX_GEOMETRY_POINT_F_H_
82