Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DoubleSize_h | 5 #ifndef DoubleSize_h |
| 6 #define DoubleSize_h | 6 #define DoubleSize_h |
| 7 | 7 |
| 8 #include "platform/geometry/FloatSize.h" | 8 #include "platform/geometry/FloatSize.h" |
| 9 #include "platform/geometry/IntSize.h" | 9 #include "platform/geometry/IntSize.h" |
| 10 #include "wtf/MathExtras.h" | 10 #include "wtf/MathExtras.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 class PLATFORM_EXPORT DoubleSize { | 14 class PLATFORM_EXPORT DoubleSize { |
| 15 public: | 15 public: |
| 16 DoubleSize() : m_width(0), m_height(0) { } | 16 DoubleSize() : m_width(0), m_height(0) { } |
| 17 DoubleSize(double width, double height) : m_width(width), m_height(height) { } | 17 DoubleSize(double width, double height) : m_width(width), m_height(height) { } |
| 18 DoubleSize(const IntSize& p) : m_width(p.width()), m_height(p.height()) { } | |
| 18 | 19 |
| 19 double width() const { return m_width; } | 20 double width() const { return m_width; } |
| 20 double height() const { return m_height; } | 21 double height() const { return m_height; } |
| 21 | 22 |
| 22 void setWidth(double width) { m_width = width; } | 23 void setWidth(double width) { m_width = width; } |
| 23 void setHeight(double height) { m_height = height; } | 24 void setHeight(double height) { m_height = height; } |
| 24 | 25 |
| 25 bool isEmpty() const { return m_width <= 0 || m_height <= 0; } | 26 bool isEmpty() const { return m_width <= 0 || m_height <= 0; } |
| 26 | 27 |
| 27 bool isZero() const; | 28 bool isZero() const; |
| 28 | 29 |
| 29 private: | 30 private: |
| 30 double m_width, m_height; | 31 double m_width, m_height; |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 inline DoubleSize& operator+=(DoubleSize& a, const DoubleSize& b) | 34 inline DoubleSize& operator+=(DoubleSize& a, const DoubleSize& b) |
| 34 { | 35 { |
| 35 a.setWidth(a.width() + b.width()); | 36 a.setWidth(a.width() + b.width()); |
| 36 a.setHeight(a.height() + b.height()); | 37 a.setHeight(a.height() + b.height()); |
| 37 return a; | 38 return a; |
| 38 } | 39 } |
| 39 | 40 |
| 41 inline DoubleSize operator+(const DoubleSize& a, const IntSize& b) | |
|
Rick Byers
2014/10/02 21:44:06
are these still necessary if you have the implicit
Yufeng Shen (Slow to review)
2014/10/02 23:34:35
removed.
| |
| 42 { | |
| 43 return DoubleSize(a.width() + b.width(), a.height() + b.height()); | |
| 44 } | |
| 45 | |
| 46 inline DoubleSize operator+(const IntSize& a, const DoubleSize& b) | |
| 47 { | |
| 48 return DoubleSize(a.width() + b.width(), a.height() + b.height()); | |
| 49 } | |
| 50 | |
| 51 inline DoubleSize operator+(const DoubleSize& a, const DoubleSize& b) | |
| 52 { | |
| 53 return DoubleSize(a.width() + b.width(), a.height() + b.height()); | |
| 54 } | |
| 55 | |
| 40 inline DoubleSize operator-(const DoubleSize& a, const DoubleSize& b) | 56 inline DoubleSize operator-(const DoubleSize& a, const DoubleSize& b) |
| 41 { | 57 { |
| 42 return DoubleSize(a.width() - b.width(), a.height() - b.height()); | 58 return DoubleSize(a.width() - b.width(), a.height() - b.height()); |
| 43 } | 59 } |
| 44 | 60 |
| 45 inline bool operator==(const DoubleSize& a, const DoubleSize& b) | 61 inline bool operator==(const DoubleSize& a, const DoubleSize& b) |
| 46 { | 62 { |
| 47 return a.width() == b.width() && a.height() == b.height(); | 63 return a.width() == b.width() && a.height() == b.height(); |
| 48 } | 64 } |
| 49 | 65 |
| 66 inline bool operator!=(const DoubleSize& a, const DoubleSize& b) | |
| 67 { | |
| 68 return a.width() != b.width() || a.height() != b.height(); | |
| 69 } | |
| 70 | |
| 50 inline IntSize flooredIntSize(const DoubleSize& p) | 71 inline IntSize flooredIntSize(const DoubleSize& p) |
| 51 { | 72 { |
| 52 return IntSize(clampToInteger(floor(p.width())), clampToInteger(floor(p.heig ht()))); | 73 return IntSize(clampToInteger(floor(p.width())), clampToInteger(floor(p.heig ht()))); |
| 53 } | 74 } |
| 54 | 75 |
| 55 inline FloatSize toFloatSize(const DoubleSize& p) | 76 inline FloatSize toFloatSize(const DoubleSize& p) |
| 56 { | 77 { |
| 57 return FloatSize(p.width(), p.height()); | 78 return FloatSize(p.width(), p.height()); |
| 58 } | 79 } |
| 59 | 80 |
| 60 } // namespace blink | 81 } // namespace blink |
| 61 | 82 |
| 62 #endif // DoubleSize_h | 83 #endif // DoubleSize_h |
| OLD | NEW |