| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 WINDOW_MANAGER_GEOMETRY_H_ | 5 #ifndef WINDOW_MANAGER_GEOMETRY_H_ |
| 6 #define WINDOW_MANAGER_GEOMETRY_H_ | 6 #define WINDOW_MANAGER_GEOMETRY_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <iosfwd> | 9 #include <iosfwd> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 struct Size { | 50 struct Size { |
| 51 Size() : width(0), height(0) {} | 51 Size() : width(0), height(0) {} |
| 52 Size(int width, int height) : width(width), height(height) {} | 52 Size(int width, int height) : width(width), height(height) {} |
| 53 | 53 |
| 54 void reset(int new_width, int new_height) { | 54 void reset(int new_width, int new_height) { |
| 55 width = new_width; | 55 width = new_width; |
| 56 height = new_height; | 56 height = new_height; |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool empty() const { return width <= 0 || height <= 0; } |
| 60 int area() const { return empty() ? 0 : width * height; } |
| 61 |
| 59 bool operator==(const Size& o) const { | 62 bool operator==(const Size& o) const { |
| 60 return width == o.width && height == o.height; | 63 return width == o.width && height == o.height; |
| 61 } | 64 } |
| 62 bool operator!=(const Size& o) const { | 65 bool operator!=(const Size& o) const { |
| 63 return width != o.width || height != o.height; | 66 return width != o.width || height != o.height; |
| 64 } | 67 } |
| 65 | 68 |
| 66 int width; | 69 int width; |
| 67 int height; | 70 int height; |
| 68 }; | 71 }; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 131 } |
| 129 | 132 |
| 130 int max_x = std::min(x + width, other.x + other.width); | 133 int max_x = std::min(x + width, other.x + other.width); |
| 131 x = std::max(x, other.x); | 134 x = std::max(x, other.x); |
| 132 width = std::max(0, max_x - x); | 135 width = std::max(0, max_x - x); |
| 133 int max_y = std::min(y + height, other.y + other.height); | 136 int max_y = std::min(y + height, other.y + other.height); |
| 134 y = std::max(y, other.y); | 137 y = std::max(y, other.y); |
| 135 height = std::max(0, max_y - y); | 138 height = std::max(0, max_y - y); |
| 136 } | 139 } |
| 137 | 140 |
| 141 bool contains_point(const Point& point) const { |
| 142 return point.x >= x && |
| 143 point.x < x + width && |
| 144 point.y >= y && |
| 145 point.y < y + height; |
| 146 } |
| 147 |
| 138 bool operator==(const Rect& o) const { | 148 bool operator==(const Rect& o) const { |
| 139 return x == o.x && y == o.y && width == o.width && height == o.height; | 149 return x == o.x && y == o.y && width == o.width && height == o.height; |
| 140 } | 150 } |
| 141 bool operator!=(const Rect& o) const { | 151 bool operator!=(const Rect& o) const { |
| 142 return x != o.x || y != o.y || width != o.width || height != o.height; | 152 return x != o.x || y != o.y || width != o.width || height != o.height; |
| 143 } | 153 } |
| 144 | 154 |
| 145 int left() const { return x; } | 155 int left() const { return x; } |
| 146 int top() const { return y; } | 156 int top() const { return y; } |
| 147 int right() const { return x + width; } | 157 int right() const { return x + width; } |
| 148 int bottom() const { return y + height; } | 158 int bottom() const { return y + height; } |
| 149 | 159 |
| 150 int x; | 160 int x; |
| 151 int y; | 161 int y; |
| 152 int width; | 162 int width; |
| 153 int height; | 163 int height; |
| 154 }; | 164 }; |
| 155 | 165 |
| 156 } // namespace window_manager | 166 } // namespace window_manager |
| 157 | 167 |
| 158 std::ostream& operator<<(std::ostream& out, const window_manager::Point& point); | 168 std::ostream& operator<<(std::ostream& out, const window_manager::Point& point); |
| 159 std::ostream& operator<<(std::ostream& out, const window_manager::Size& size); | 169 std::ostream& operator<<(std::ostream& out, const window_manager::Size& size); |
| 160 std::ostream& operator<<(std::ostream& out, const window_manager::Rect& rect); | 170 std::ostream& operator<<(std::ostream& out, const window_manager::Rect& rect); |
| 161 | 171 |
| 162 #endif // WINDOW_MANAGER_GEOMETRY_H_ | 172 #endif // WINDOW_MANAGER_GEOMETRY_H_ |
| OLD | NEW |