| 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 DoublePoint_h | 5 #ifndef DoublePoint_h |
| 6 #define DoublePoint_h | 6 #define DoublePoint_h |
| 7 | 7 |
| 8 #include "platform/geometry/DoubleSize.h" | 8 #include "platform/geometry/DoubleSize.h" |
| 9 #include "platform/geometry/FloatPoint.h" | 9 #include "platform/geometry/FloatPoint.h" |
| 10 #include "platform/geometry/IntPoint.h" | 10 #include "platform/geometry/IntPoint.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 class PLATFORM_EXPORT DoublePoint { | 14 class PLATFORM_EXPORT DoublePoint { |
| 15 public: | 15 public: |
| 16 DoublePoint() | 16 DoublePoint() |
| 17 : m_x(0) | 17 : m_x(0) |
| 18 , m_y(0) | 18 , m_y(0) |
| 19 { | 19 { |
| 20 } | 20 } |
| 21 DoublePoint(double x, double y) | 21 DoublePoint(double x, double y) |
| 22 : m_x(x) | 22 : m_x(x) |
| 23 , m_y(y) | 23 , m_y(y) |
| 24 { | 24 { |
| 25 } | 25 } |
| 26 explicit DoublePoint(const IntPoint& p) | 26 DoublePoint(const IntPoint& p) |
| 27 : m_x(p.x()) | 27 : m_x(p.x()) |
| 28 , m_y(p.y()) | 28 , m_y(p.y()) |
| 29 { | 29 { |
| 30 } | 30 } |
| 31 explicit DoublePoint(const FloatPoint& p) | 31 DoublePoint(const FloatPoint& p) |
| 32 : m_x(p.x()) | 32 : m_x(p.x()) |
| 33 , m_y(p.y()) | 33 , m_y(p.y()) |
| 34 { | 34 { |
| 35 } | 35 } |
| 36 | 36 |
| 37 explicit DoublePoint(const DoubleSize& size) |
| 38 : m_x(size.width()), m_y(size.height()) |
| 39 { |
| 40 } |
| 41 |
| 37 DoublePoint expandedTo(int x, int y) const | 42 DoublePoint expandedTo(int x, int y) const |
| 38 { | 43 { |
| 39 return DoublePoint(m_x > x ? m_x : x, m_y > y ? m_y : y); | 44 return DoublePoint(m_x > x ? m_x : x, m_y > y ? m_y : y); |
| 40 } | 45 } |
| 41 | 46 |
| 42 DoublePoint shrunkTo(int x, int y) const | 47 DoublePoint shrunkTo(int x, int y) const |
| 43 { | 48 { |
| 44 return DoublePoint(m_x < x ? m_x : x, m_y < y ? m_y : y); | 49 return DoublePoint(m_x < x ? m_x : x, m_y < y ? m_y : y); |
| 45 } | 50 } |
| 46 | 51 |
| 47 double x() const { return m_x; } | 52 double x() const { return m_x; } |
| 48 double y() const { return m_y; } | 53 double y() const { return m_y; } |
| 49 | 54 |
| 50 private: | 55 private: |
| 51 double m_x, m_y; | 56 double m_x, m_y; |
| 52 }; | 57 }; |
| 53 | 58 |
| 54 inline bool operator==(const DoublePoint& a, const DoublePoint& b) | 59 inline bool operator==(const DoublePoint& a, const DoublePoint& b) |
| 55 { | 60 { |
| 56 return a.x() == b.x() && a.y() == b.y(); | 61 return a.x() == b.x() && a.y() == b.y(); |
| 57 } | 62 } |
| 58 | 63 |
| 59 inline bool operator!=(const DoublePoint& a, const DoublePoint& b) | 64 inline bool operator!=(const DoublePoint& a, const DoublePoint& b) |
| 60 { | 65 { |
| 61 return a.x() != b.x() || a.y() != b.y(); | 66 return a.x() != b.x() || a.y() != b.y(); |
| 62 } | 67 } |
| 63 | 68 |
| 69 inline DoublePoint operator+(const DoublePoint& a, const DoubleSize& b) |
| 70 { |
| 71 return DoublePoint(a.x() + b.width(), a.y() + b.height()); |
| 72 } |
| 73 |
| 64 inline DoubleSize operator-(const DoublePoint& a, const DoublePoint& b) | 74 inline DoubleSize operator-(const DoublePoint& a, const DoublePoint& b) |
| 65 { | 75 { |
| 66 return DoubleSize(a.x() - b.x(), a.y() - b.y()); | 76 return DoubleSize(a.x() - b.x(), a.y() - b.y()); |
| 67 } | 77 } |
| 68 | 78 |
| 79 inline DoublePoint operator-(const DoublePoint& a) |
| 80 { |
| 81 return DoublePoint(-a.x(), -a.y()); |
| 82 } |
| 83 |
| 69 inline IntPoint flooredIntPoint(const DoublePoint& p) | 84 inline IntPoint flooredIntPoint(const DoublePoint& p) |
| 70 { | 85 { |
| 71 return IntPoint(clampTo<int>(floor(p.x())), clampTo<int>(floor(p.y()))); | 86 return IntPoint(clampTo<int>(floor(p.x())), clampTo<int>(floor(p.y()))); |
| 72 } | 87 } |
| 73 | 88 |
| 74 inline FloatPoint toFloatPoint(const DoublePoint& a) | 89 inline FloatPoint toFloatPoint(const DoublePoint& a) |
| 75 { | 90 { |
| 76 return FloatPoint(a.x(), a.y()); | 91 return FloatPoint(a.x(), a.y()); |
| 77 } | 92 } |
| 78 | 93 |
| 79 inline DoubleSize toDoubleSize(const DoublePoint& a) | 94 inline DoubleSize toDoubleSize(const DoublePoint& a) |
| 80 { | 95 { |
| 81 return DoubleSize(a.x(), a.y()); | 96 return DoubleSize(a.x(), a.y()); |
| 82 } | 97 } |
| 83 | 98 |
| 84 } | 99 } |
| 85 | 100 |
| 86 #endif | 101 #endif |
| OLD | NEW |