Debian Codegraph @

src/gengine/V2.h

raw
1 #ifndef HEADER_V2_H
2 #define HEADER_V2_H
3
4 #include "StringTool.h"
5
6 #include <string>
7 #include <assert.h>
8
9 /**
10 * Vector x,y.
11 * Constant object.
12 */
13 class V2 {
14 private:
15 int m_x;
16 int m_y;
17 public:
18 V2(int x, int y) { m_x = x; m_y = y; }
19
20 inline int getX() const { return m_x; }
21 inline int getY() const { return m_y; }
22
23 V2 plus(const V2 &other) const
24 {
25 return V2(m_x + other.m_x, m_y + other.m_y);
26 }
27 V2 minus(const V2 &other) const
28 {
29 return V2(m_x - other.m_x, m_y - other.m_y);
30 }
31 V2 scale(int rate) const
32 {
33 return V2(m_x * rate, m_y * rate);
34 }
35 V2 shrink(int rate) const
36 {
37 assert(rate != 0);
38 return V2(m_x / rate, m_y / rate);
39 }
40 bool equals(const V2 &other)
41 {
42 return m_x == other.m_x && m_y == other.m_y;
43 }
44
45 std::string toString() const
46 {
47 return "[" + StringTool::toString(m_x)
48 + "," + StringTool::toString(m_y) + "]";
49 }
50 };
51
52 #endif