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_SIZE_F_H_
6 #define UI_GFX_GEOMETRY_SIZE_F_H_
12 #include "base/compiler_specific.h"
13 #include "ui/gfx/gfx_export.h"
17 // A floating version of gfx::Size.
18 class GFX_EXPORT SizeF
{
20 SizeF() : width_(0.f
), height_(0.f
) {}
21 SizeF(float width
, float height
)
22 : width_(fmaxf(0, width
)), height_(fmaxf(0, height
)) {}
25 float width() const { return width_
; }
26 float height() const { return height_
; }
28 void set_width(float width
) { width_
= fmaxf(0, width
); }
29 void set_height(float height
) { height_
= fmaxf(0, height
); }
31 float GetArea() const;
33 void SetSize(float width
, float height
) {
38 void Enlarge(float grow_width
, float grow_height
);
40 void SetToMin(const SizeF
& other
);
41 void SetToMax(const SizeF
& other
);
43 bool IsEmpty() const { return !width() || !height(); }
45 void Scale(float scale
) {
49 void Scale(float x_scale
, float y_scale
) {
50 SetSize(width() * x_scale
, height() * y_scale
);
53 std::string
ToString() const;
60 inline bool operator==(const SizeF
& lhs
, const SizeF
& rhs
) {
61 return lhs
.width() == rhs
.width() && lhs
.height() == rhs
.height();
64 inline bool operator!=(const SizeF
& lhs
, const SizeF
& rhs
) {
68 GFX_EXPORT SizeF
ScaleSize(const SizeF
& p
, float x_scale
, float y_scale
);
70 inline SizeF
ScaleSize(const SizeF
& p
, float scale
) {
71 return ScaleSize(p
, scale
, scale
);
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 SizeF
& size
, ::std::ostream
* os
);
81 #endif // UI_GFX_GEOMETRY_SIZE_F_H_