Mir
point.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: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17 */
18
19#ifndef MIR_GEOMETRY_POINT_H_
20#define MIR_GEOMETRY_POINT_H_
21
22#include "dimensions.h"
23#include <iosfwd>
24
25namespace mir
26{
27namespace geometry
28{
29
30struct Point
31{
32 constexpr Point() = default;
33 constexpr Point(Point const&) = default;
34 Point& operator=(Point const&) = default;
35
36 template<typename XType, typename YType>
37 constexpr Point(XType&& x, YType&& y) : x(x), y(y) {}
38
41};
42
43inline constexpr bool operator == (Point const& lhs, Point const& rhs)
44{
45 return lhs.x == rhs.x && lhs.y == rhs.y;
46}
47
48inline constexpr bool operator != (Point const& lhs, Point const& rhs)
49{
50 return lhs.x != rhs.x || lhs.y != rhs.y;
51}
52
53inline constexpr Point operator+(Point lhs, DeltaX rhs) { return{lhs.x + rhs, lhs.y}; }
54inline constexpr Point operator+(Point lhs, DeltaY rhs) { return{lhs.x, lhs.y + rhs}; }
55
56inline constexpr Point operator-(Point lhs, DeltaX rhs) { return{lhs.x - rhs, lhs.y}; }
57inline constexpr Point operator-(Point lhs, DeltaY rhs) { return{lhs.x, lhs.y - rhs}; }
58
59inline Point& operator+=(Point& lhs, DeltaX rhs) { lhs.x += rhs; return lhs; }
60inline Point& operator+=(Point& lhs, DeltaY rhs) { lhs.y += rhs; return lhs; }
61
62inline Point& operator-=(Point& lhs, DeltaX rhs) { lhs.x -= rhs; return lhs; }
63inline Point& operator-=(Point& lhs, DeltaY rhs) { lhs.y -= rhs; return lhs; }
64
65std::ostream& operator<<(std::ostream& out, Point const& value);
66}
67}
68
69#endif /* MIR_GEOMETRY_POINT_H_ */
DeltaX & operator-=(DeltaX &lhs, DeltaX rhs)
Definition: dimensions.h:123
std::ostream & operator<<(std::ostream &out, Displacement const &value)
constexpr bool operator==(Displacement const &lhs, Displacement const &rhs)
Definition: displacement.h:52
DeltaX & operator+=(DeltaX &lhs, DeltaX rhs)
Definition: dimensions.h:121
constexpr DeltaX operator+(DeltaX lhs, DeltaX rhs)
Definition: dimensions.h:117
constexpr DeltaX operator-(DeltaX lhs, DeltaX rhs)
Definition: dimensions.h:119
constexpr bool operator!=(Displacement const &lhs, Displacement const &rhs)
Definition: displacement.h:57
Definition: splash_session.h:24
Definition: point.h:31
constexpr Point(XType &&x, YType &&y)
Definition: point.h:37
Y y
Definition: point.h:40
Point & operator=(Point const &)=default
X x
Definition: point.h:39
constexpr Point(Point const &)=default
constexpr Point()=default

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.