CARLA
 
载入中...
搜索中...
未找到
Position.h
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include <type_traits>
10
11namespace MapGen {
12
13 template<typename T>
14 class Position {
15 public:
16 using number_type = T;
17
18 static_assert(
19 std::is_arithmetic<number_type>::value &&
20 !std::is_same<number_type, bool>::value, "not a valid number type");
21
23
25
26 Position() = default;
27
28 constexpr Position(T X, T Y) : x(X), y(Y) {}
29
30 constexpr bool operator==(const Position &rhs) const {
31 return (x == rhs.x) && (y == rhs.y);
32 }
33
34 constexpr bool operator!=(const Position &rhs) const {
35 return !(*this == rhs);
36 }
37
39 x += rhs.x;
40 y += rhs.y;
41 return *this;
42 }
43
44 friend Position operator+(Position lhs, const Position &rhs) {
45 lhs += rhs;
46 return lhs;
47 }
48
50 x -= rhs.x;
51 y -= rhs.y;
52 return *this;
53 }
54
55 friend Position operator-(Position lhs, const Position &rhs) {
56 lhs -= rhs;
57 return lhs;
58 }
59 };
60
61} // namespace MapGen
constexpr bool operator!=(const Position &rhs) const
Definition Position.h:34
Position & operator+=(const Position &rhs)
Definition Position.h:38
Position & operator-=(const Position &rhs)
Definition Position.h:49
Position()=default
friend Position operator+(Position lhs, const Position &rhs)
Definition Position.h:44
number_type y
Definition Position.h:24
friend Position operator-(Position lhs, const Position &rhs)
Definition Position.h:55
constexpr Position(T X, T Y)
Definition Position.h:28
number_type x
Definition Position.h:22
constexpr bool operator==(const Position &rhs) const
Definition Position.h:30