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.
5 #ifndef UI_GFX_GEOMETRY_POINT_F_H_
6 #define UI_GFX_GEOMETRY_POINT_F_H_
11 #include "ui/gfx/geometry/point_base.h"
12 #include "ui/gfx/geometry/vector2d_f.h"
13 #include "ui/gfx/gfx_export.h"
17 // A floating version of gfx::Point.
18 class GFX_EXPORT PointF
: public PointBase
<PointF
, float, Vector2dF
> {
20 PointF() : PointBase
<PointF
, float, Vector2dF
>(0, 0) {}
21 PointF(float x
, float y
) : PointBase
<PointF
, float, Vector2dF
>(x
, y
) {}
24 void Scale(float scale
) {
28 void Scale(float x_scale
, float y_scale
) {
29 SetPoint(x() * x_scale
, y() * y_scale
);
32 // Returns a string representation of point.
33 std::string
ToString() const;
36 inline bool operator==(const PointF
& lhs
, const PointF
& rhs
) {
37 return lhs
.x() == rhs
.x() && lhs
.y() == rhs
.y();
40 inline bool operator!=(const PointF
& lhs
, const PointF
& rhs
) {
44 inline PointF
operator+(const PointF
& lhs
, const Vector2dF
& rhs
) {
50 inline PointF
operator-(const PointF
& lhs
, const Vector2dF
& rhs
) {
56 inline Vector2dF
operator-(const PointF
& lhs
, const PointF
& rhs
) {
57 return Vector2dF(lhs
.x() - rhs
.x(), lhs
.y() - rhs
.y());
60 inline PointF
PointAtOffsetFromOrigin(const Vector2dF
& offset_from_origin
) {
61 return PointF(offset_from_origin
.x(), offset_from_origin
.y());
64 GFX_EXPORT PointF
ScalePoint(const PointF
& p
, float x_scale
, float y_scale
);
66 inline PointF
ScalePoint(const PointF
& p
, float scale
) {
67 return ScalePoint(p
, scale
, scale
);
70 #if !defined(COMPILER_MSVC)
71 extern template class PointBase
<PointF
, float, Vector2dF
>;
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
);
81 #endif // UI_GFX_GEOMETRY_POINT_F_H_