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

Copyright © 2012-2022 Canonical Ltd.
Generated on Sun Oct 9 06:13:38 UTC 2022
This documentation is licensed under the GPL version 2 or 3.