Mir
size.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, 2016 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 2 or 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIR_GEOMETRY_SIZE_H_
20 #define MIR_GEOMETRY_SIZE_H_
21 
23 #include <iosfwd>
24 
25 namespace mir
26 {
27 namespace geometry
28 {
29 
30 struct Size
31 {
32  constexpr Size() noexcept {}
33  constexpr Size(Size const&) noexcept = default;
34  Size& operator=(Size const&) noexcept = default;
35 
36  template<typename WidthType, typename HeightType>
37  constexpr Size(WidthType&& width, HeightType&& height) noexcept : width(width), height(height) {}
38 
41 };
42 
43 inline constexpr bool operator == (Size const& lhs, Size const& rhs)
44 {
45  return lhs.width == rhs.width && lhs.height == rhs.height;
46 }
47 
48 inline constexpr bool operator != (Size const& lhs, Size const& rhs)
49 {
50  return lhs.width != rhs.width || lhs.height != rhs.height;
51 }
52 
53 std::ostream& operator<<(std::ostream& out, Size const& value);
54 
55 template<typename Scalar>
56 inline constexpr Size operator*(Scalar scale, Size const& size)
57 {
58  return Size{scale*size.width, scale*size.height};
59 }
60 
61 template<typename Scalar>
62 inline constexpr Size operator*(Size const& size, Scalar scale)
63 {
64  return scale*size;
65 }
66 
67 #ifdef MIR_GEOMETRY_DISPLACEMENT_H_
68 inline constexpr Displacement as_displacement(Size const& size)
69 {
70  return Displacement{size.width.as_int(), size.height.as_int()};
71 }
72 
73 inline constexpr Size as_size(Displacement const& disp)
74 {
75  return Size{disp.dx.as_int(), disp.dy.as_int()};
76 }
77 #endif
78 }
79 }
80 
81 #endif /* MIR_GEOMETRY_SIZE_H_ */
Definition: size.h:30
Definition: splash_session.h:24
constexpr Size(WidthType &&width, HeightType &&height) noexcept
Definition: size.h:37
constexpr int as_int() const
Definition: dimensions.h:53
constexpr bool operator !=(Point const &lhs, Point const &rhs)
Definition: point.h:48
Height height
Definition: size.h:40
std::ostream & operator<<(std::ostream &out, Displacement const &value)
Width width
Definition: size.h:39
constexpr bool operator==(Displacement const &lhs, Displacement const &rhs)
Definition: displacement.h:51
constexpr Width operator *(Scalar scale, Width const &w)
Definition: dimensions.h:148
constexpr Size() noexcept
Definition: size.h:32
Size & operator=(Size const &) noexcept=default

Copyright © 2012-2019 Canonical Ltd.
Generated on Fri Feb 1 22:50:25 UTC 2019
This documentation is licensed under the GPL version 2 or 3.