1 // Copyright 2014 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.
8 #include "platform/geometry/FloatSize.h"
9 #include "platform/geometry/IntSize.h"
10 #include "wtf/MathExtras.h"
16 class PLATFORM_EXPORT DoubleSize
{
18 DoubleSize() : m_width(0), m_height(0) { }
19 DoubleSize(double width
, double height
) : m_width(width
), m_height(height
) { }
20 DoubleSize(const IntSize
& p
) : m_width(p
.width()), m_height(p
.height()) { }
21 DoubleSize(const FloatSize
& s
) : m_width(s
.width()), m_height(s
.height()) { }
22 explicit DoubleSize(const LayoutSize
&);
24 double width() const { return m_width
; }
25 double height() const { return m_height
; }
27 void setWidth(double width
) { m_width
= width
; }
28 void setHeight(double height
) { m_height
= height
; }
30 bool isEmpty() const { return m_width
<= 0 || m_height
<= 0; }
34 void expand(float width
, float height
)
40 void scale(float widthScale
, float heightScale
)
42 m_width
= m_width
* widthScale
;
43 m_height
= m_height
* heightScale
;
46 void scale(float scale
)
48 this->scale(scale
, scale
);
52 double m_width
, m_height
;
55 inline DoubleSize
& operator+=(DoubleSize
& a
, const DoubleSize
& b
)
57 a
.setWidth(a
.width() + b
.width());
58 a
.setHeight(a
.height() + b
.height());
62 inline DoubleSize
& operator-=(DoubleSize
& a
, const DoubleSize
& b
)
64 a
.setWidth(a
.width() - b
.width());
65 a
.setHeight(a
.height() - b
.height());
69 inline DoubleSize
operator+(const DoubleSize
& a
, const DoubleSize
& b
)
71 return DoubleSize(a
.width() + b
.width(), a
.height() + b
.height());
74 inline DoubleSize
operator-(const DoubleSize
& a
, const DoubleSize
& b
)
76 return DoubleSize(a
.width() - b
.width(), a
.height() - b
.height());
79 inline bool operator==(const DoubleSize
& a
, const DoubleSize
& b
)
81 return a
.width() == b
.width() && a
.height() == b
.height();
84 inline bool operator!=(const DoubleSize
& a
, const DoubleSize
& b
)
86 return a
.width() != b
.width() || a
.height() != b
.height();
89 inline IntSize
flooredIntSize(const DoubleSize
& p
)
91 return IntSize(clampTo
<int>(floor(p
.width())), clampTo
<int>(floor(p
.height())));
94 inline IntSize
roundedIntSize(const DoubleSize
& p
)
96 return IntSize(clampTo
<int>(roundf(p
.width())), clampTo
<int>(roundf(p
.height())));
99 inline IntSize
expandedIntSize(const DoubleSize
& p
)
101 return IntSize(clampTo
<int>(ceilf(p
.width())), clampTo
<int>(ceilf(p
.height())));
104 inline FloatSize
toFloatSize(const DoubleSize
& p
)
106 return FloatSize(p
.width(), p
.height());
111 #endif // DoubleSize_h