/
HPCIntVec2.cpp
executable file
·129 lines (107 loc) · 3.66 KB
/
HPCIntVec2.cpp
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//------------------------------------------------------------------------------
/// @file
/// @brief HPCIntVec2.hpp の実装
/// @author ハル研究所プログラミングコンテスト実行委員会
///
/// @copyright Copyright (c) 2014 HAL Laboratory, Inc.
/// @attention このファイルの利用は、同梱のREADMEにある
/// 利用条件に従ってください
//------------------------------------------------------------------------------
#include "HPCIntVec2.hpp"
#include "HPCMath.hpp"
namespace hpc {
//------------------------------------------------------------------------------
/// 原点またはゼロベクトルを値とするクラスのインスタンスを生成します。
IntVec2::IntVec2()
: x(0)
, y(0)
{
reset();
}
//------------------------------------------------------------------------------
/// 初期値を指定してクラスのインスタンスを生成します。
///
/// @param[in] aX x成分の値
/// @param[in] aY y成分の値
IntVec2::IntVec2(int aX, int aY)
: x(aX)
, y(aY)
{
}
//------------------------------------------------------------------------------
/// 値を (0, 0) に初期化します。
void IntVec2::reset()
{
x = 0;
y = 0;
}
//------------------------------------------------------------------------------
bool IntVec2::operator==(const IntVec2& aRhs)const
{
return x == aRhs.x && y == aRhs.y;
}
//------------------------------------------------------------------------------
IntVec2 IntVec2::operator-()const
{
return IntVec2(-x, -y);
}
//------------------------------------------------------------------------------
IntVec2& IntVec2::operator+=(const IntVec2& aRhs)
{
x += aRhs.x;
y += aRhs.y;
return *this;
}
//------------------------------------------------------------------------------
IntVec2& IntVec2::operator-=(const IntVec2& aRhs)
{
return *this += (-aRhs);
}
//------------------------------------------------------------------------------
IntVec2 IntVec2::operator+(const IntVec2& aRhs)const
{
IntVec2 v(*this);
v += aRhs;
return v;
}
//------------------------------------------------------------------------------
IntVec2 IntVec2::operator-(const IntVec2& aRhs)const
{
return *this + (-aRhs);
}
//------------------------------------------------------------------------------
IntVec2& IntVec2::operator*=(int aRhs)
{
x *= aRhs;
y *= aRhs;
return *this;
}
//------------------------------------------------------------------------------
IntVec2& IntVec2::operator/=(int aRhs)
{
x /= aRhs;
y /= aRhs;
return *this;
}
//------------------------------------------------------------------------------
IntVec2 IntVec2::operator*(int aRhs)const
{
IntVec2 v(*this);
v *= aRhs;
return v;
}
//------------------------------------------------------------------------------
IntVec2 IntVec2::operator/(int aRhs)const
{
IntVec2 v(*this);
v /= aRhs;
return v;
}
//------------------------------------------------------------------------------
IntVec2 operator*(int aLhs, const IntVec2& aRhs)
{
return aRhs * aLhs;
}
}
//------------------------------------------------------------------------------
// EOF