-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint.h
84 lines (71 loc) · 1.39 KB
/
Point.h
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
//
// Point.h
// TankGame
//
// Created by Jacob Gonzalez on 11/04/2015.
// Copyright (c) 2015 Jacob Gonzalez. All rights reserved.
//
#ifndef _POINT_H
#define _POINT_H
#include <cmath>
// :: Point structure class ::
// :: Allows direct manipulation ::
template<typename T>
class Point
{
public:
Point()
: x(0), y(0)
{}
Point(T _x, T _y)
: x(_x), y(_y)
{}
// : return the diagonal length of the vector x,y :
T length()
{
return sqrt(x*x + y*y);
}
// x value
T x;
// y value
T y;
// == operator
bool operator==(const Point<T> &p1)
{
if (x == p1.x && y == p1.y)
{
return true;
}
return false;
}
// : - operator
Point<T> operator-(const Point<T> &rhs)
{
Point<T> delta(x-rhs.x, y-rhs.y);
return delta;
}
// : + operator
Point<T> operator+(const Point<T> &rhs)
{
Point<T> delta(x+rhs.x, y+rhs.y);
return delta;
}
// : * operator
Point<T> operator*(const Point<T> &rhs)
{
Point<T> delta(x*rhs.x, y*rhs.y);
return delta;
}
// : / operator
Point<T> operator/(const Point<T> &rhs)
{
Point<T> delta(x/rhs.x, y/rhs.y);
return delta;
}
// : return a point for (0, 0)
static Point<T> zero()
{
return Point<T>(0, 0);
}
};
#endif /* _POINT_H */