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 "point.h"
24 #include <iosfwd>
25 
26 namespace mir
27 {
28 namespace geometry
29 {
30 
31 struct Size
32 {
33  constexpr Size() noexcept {}
34  constexpr Size(Size const&) noexcept = default;
35  Size& operator=(Size const&) noexcept = default;
36 
37  template<typename WidthType, typename HeightType>
38  constexpr Size(WidthType&& width, HeightType&& height) noexcept : width(width), height(height) {}
39 
42 };
43 
44 inline constexpr bool operator == (Size const& lhs, Size const& rhs)
45 {
46  return lhs.width == rhs.width && lhs.height == rhs.height;
47 }
48 
49 inline constexpr bool operator != (Size const& lhs, Size const& rhs)
50 {
51  return lhs.width != rhs.width || lhs.height != rhs.height;
52 }
53 
54 std::ostream& operator<<(std::ostream& out, Size const& value);
55 
56 template<typename Scalar>
57 inline constexpr Size operator*(Scalar scale, Size const& size)
58 {
59  return Size{scale*size.width, scale*size.height};
60 }
61 
62 template<typename Scalar>
63 inline constexpr Size operator*(Size const& size, Scalar scale)
64 {
65  return scale*size;
66 }
67 
68 inline constexpr Size as_size(Point const& point)
69 {
70  return Size{point.x.as_int(), point.y.as_int()};
71 }
72 
73 inline constexpr Point as_point(Size const& size)
74 {
75  return Point{size.width.as_int(), size.height.as_int()};
76 }
77 }
78 }
79 
80 #endif /* MIR_GEOMETRY_SIZE_H_ */
mir::geometry::Size::Size
constexpr Size(WidthType &&width, HeightType &&height) noexcept
Definition: size.h:38
point.h
mir::geometry::detail::IntWrapper< struct WidthTag >
mir::geometry::Point::x
X x
Definition: point.h:39
mir::geometry::operator==
constexpr bool operator==(Displacement const &lhs, Displacement const &rhs)
Definition: displacement.h:52
mir
Definition: splash_session.h:24
mir::geometry::Size::height
Height height
Definition: size.h:41
mir::geometry::Size::operator=
Size & operator=(Size const &) noexcept=default
mir::geometry::Size::Size
constexpr Size() noexcept
Definition: size.h:33
mir::geometry::operator*
constexpr Width operator*(Scalar scale, Width const &w)
Definition: dimensions.h:162
mir::geometry::operator!=
constexpr bool operator!=(Displacement const &lhs, Displacement const &rhs)
Definition: displacement.h:57
mir::geometry::Point::y
Y y
Definition: point.h:40
mir::geometry::as_point
constexpr Point as_point(Displacement const &disp)
Definition: displacement.h:136
mir::geometry::as_size
constexpr Size as_size(Displacement const &disp)
Definition: displacement.h:126
mir::geometry::operator<<
std::ostream & operator<<(std::ostream &out, Displacement const &value)
mir::geometry::Size::width
Width width
Definition: size.h:40
mir::geometry::Point
Definition: point.h:30
dimensions.h
mir::geometry::detail::IntWrapper::as_int
constexpr int as_int() const
Definition: dimensions.h:53
mir::geometry::Size
Definition: size.h:31

Copyright © 2012-2020 Canonical Ltd.
Generated on Thu Apr 2 01:16:04 UTC 2020
This documentation is licensed under the GPL version 2 or 3.