Mir
Loading...
Searching...
No Matches
point.h
Go to the documentation of this file.
1/*
2 * Copyright © 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
17#ifndef MIR_GEOMETRY_POINT_H_
18#define MIR_GEOMETRY_POINT_H_
19
20#include "forward.h"
21#include "dimensions.h"
22#include <ostream>
23
24namespace mir
25{
26namespace geometry
27{
28namespace generic
29{
30template<typename T>
31struct Size;
32template<typename T>
33struct Displacement;
34
35template<typename T>
36struct Point
37{
38 using ValueType = T;
39
40 constexpr Point() = default;
41 constexpr Point(Point const&) = default;
42 Point& operator=(Point const&) = default;
43
44 template<typename U>
45 explicit constexpr Point(Point<U> const& other) noexcept
46 : x{X<T>{other.x}},
47 y{Y<T>{other.y}}
48 {
49 }
50
51 template<typename XType, typename YType>
52 constexpr Point(XType&& x, YType&& y) : x(x), y(y) {}
53
56};
57
58template<typename T>
59inline constexpr bool operator == (Point<T> const& lhs, Point<T> const& rhs)
60{
61 return lhs.x == rhs.x && lhs.y == rhs.y;
62}
63
64template<typename T>
65inline constexpr bool operator != (Point<T> const& lhs, Point<T> const& rhs)
66{
67 return lhs.x != rhs.x || lhs.y != rhs.y;
68}
69
70template<typename T>
71inline constexpr Point<T> operator+(Point<T> lhs, DeltaX<T> rhs) { return{lhs.x + rhs, lhs.y}; }
72template<typename T>
73inline constexpr Point<T> operator+(Point<T> lhs, DeltaY<T> rhs) { return{lhs.x, lhs.y + rhs}; }
74
75template<typename T>
76inline constexpr Point<T> operator-(Point<T> lhs, DeltaX<T> rhs) { return{lhs.x - rhs, lhs.y}; }
77template<typename T>
78inline constexpr Point<T> operator-(Point<T> lhs, DeltaY<T> rhs) { return{lhs.x, lhs.y - rhs}; }
79
80template<typename T>
81inline Point<T>& operator+=(Point<T>& lhs, DeltaX<T> rhs) { lhs.x += rhs; return lhs; }
82template<typename T>
83inline Point<T>& operator+=(Point<T>& lhs, DeltaY<T> rhs) { lhs.y += rhs; return lhs; }
84
85template<typename T>
86inline Point<T>& operator-=(Point<T>& lhs, DeltaX<T> rhs) { lhs.x -= rhs; return lhs; }
87template<typename T>
88inline Point<T>& operator-=(Point<T>& lhs, DeltaY<T> rhs) { lhs.y -= rhs; return lhs; }
89
90template<typename T>
91std::ostream& operator<<(std::ostream& out, Point<T> const& value)
92{
93 out << value.x << ", " << value.y;
94 return out;
95}
96
97}
98}
99}
100
101#endif // MIR_GEOMETRY_POINT_H_
DeltaX< T > & operator-=(DeltaX< T > &lhs, DeltaX< T > rhs)
Definition dimensions.h:142
std::ostream & operator<<(std::ostream &out, Value< T, Tag > const &value)
Definition dimensions.h:118
constexpr bool operator==(Displacement< T > const &lhs, Displacement< T > const &rhs)
Definition displacement.h:75
constexpr DeltaX< T > operator+(DeltaX< T > lhs, DeltaX< T > rhs)
Definition dimensions.h:126
DeltaX< T > & operator+=(DeltaX< T > &lhs, DeltaX< T > rhs)
Definition dimensions.h:138
constexpr DeltaX< T > operator-(DeltaX< T > lhs, DeltaX< T > rhs)
Definition dimensions.h:130
constexpr bool operator!=(Displacement< T > const &lhs, Displacement< T > const &rhs)
Definition displacement.h:81
generic::Size< int > Size
Definition forward.h:82
generic::Displacement< int > Displacement
Definition forward.h:83
Definition splash_session.h:22
Definition point.h:37
X< T > x
Definition point.h:54
constexpr Point(Point< U > const &other) noexcept
Definition point.h:45
Y< T > y
Definition point.h:55
Point & operator=(Point const &)=default
constexpr Point()=default
T ValueType
Definition point.h:38
constexpr Point(Point const &)=default
constexpr Point(XType &&x, YType &&y)
Definition point.h:52
Wraps a geometry value and prevents it from being accidentally used for invalid operations (such as s...
Definition dimensions.h:37

Copyright © 2012-2025 Canonical Ltd.
Generated on Mon Jan 20 23:24:07 UTC 2025
This documentation is licensed under the GPL version 2 or 3.