File: point.h

package info (click to toggle)
wlcs 1.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,528 kB
  • sloc: cpp: 14,211; xml: 7,744; ansic: 952; sh: 164; makefile: 33
file content (98 lines) | stat: -rw-r--r-- 2,757 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright © Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 2 or 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef WLCS_GEOMETRY_POINT_H_
#define WLCS_GEOMETRY_POINT_H_

#include "forward.h"
#include "dimensions.h"
#include <ostream>

namespace wlcs
{
namespace generic
{
template<typename T>
struct Size;
template<typename T>
struct Displacement;

template<typename T>
struct Point
{
    using ValueType = T;

    constexpr Point() = default;
    constexpr Point(Point const&) = default;
    Point& operator=(Point const&) = default;

    template<typename U>
    explicit constexpr Point(Point<U> const& other) noexcept
        : x{X<T>{other.x}},
          y{Y<T>{other.y}}
    {
    }

    template<typename XType, typename YType>
    constexpr Point(XType&& x, YType&& y) : x(x), y(y) {}

    X<T> x;
    Y<T> y;
};

template<typename T>
inline constexpr bool operator == (Point<T> const& lhs, Point<T> const& rhs)
{
    return lhs.x == rhs.x && lhs.y == rhs.y;
}

template<typename T>
inline constexpr bool operator != (Point<T> const& lhs, Point<T> const& rhs)
{
    return lhs.x != rhs.x || lhs.y != rhs.y;
}

template<typename T>
inline constexpr Point<T> operator+(Point<T> lhs, DeltaX<T> rhs) { return{lhs.x + rhs, lhs.y}; }
template<typename T>
inline constexpr Point<T> operator+(Point<T> lhs, DeltaY<T> rhs) { return{lhs.x, lhs.y + rhs}; }

template<typename T>
inline constexpr Point<T> operator-(Point<T> lhs, DeltaX<T> rhs) { return{lhs.x - rhs, lhs.y}; }
template<typename T>
inline constexpr Point<T> operator-(Point<T> lhs, DeltaY<T> rhs) { return{lhs.x, lhs.y - rhs}; }

template<typename T>
inline Point<T>& operator+=(Point<T>& lhs, DeltaX<T> rhs) { lhs.x += rhs; return lhs; }
template<typename T>
inline Point<T>& operator+=(Point<T>& lhs, DeltaY<T> rhs) { lhs.y += rhs; return lhs; }

template<typename T>
inline Point<T>& operator-=(Point<T>& lhs, DeltaX<T> rhs) { lhs.x -= rhs; return lhs; }
template<typename T>
inline Point<T>& operator-=(Point<T>& lhs, DeltaY<T> rhs) { lhs.y -= rhs; return lhs; }

template<typename T>
std::ostream& operator<<(std::ostream& out, Point<T> const& value)
{
    out << value.x << ", " << value.y;
    return out;
}

}
}

#endif // WLCS_GEOMETRY_POINT_H_