-
Notifications
You must be signed in to change notification settings - Fork 0
/
vec2.cpp
43 lines (33 loc) · 846 Bytes
/
vec2.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
#include "vec2.h"
vec2::vec2(float xcoord, float ycoord){
x = xcoord;
y = ycoord;
}
vec2 vec2::operator + (vec2 const &coord){
return vec2(x + coord.x, y + coord.y);
}
vec2 vec2::operator - (vec2 const &coord){
return vec2(x - coord.x, y - coord.y);
}
vec2 vec2::operator / (float const &num){
return vec2(x/num , y/num);
}
vec2 vec2::operator * (float const &num){
return vec2(x*num, y*num);
}
bool vec2::operator == (vec2 const &coord){
return x == coord.x and y == coord.y;
}
vec2 vec2::operator = (vec2 const &coord){
x = coord.x;
y = coord.y;
}
float vec2::magnitude(){
return sqrt(pow(x,2) + pow(y,2));
}
float vec2::distance(vec2 coord){
return sqrt(pow(x - coord.x, 2) + pow(y - coord.y, 2));
}
void vec2::print_coord(void){
std::cout << "coord x,y: " << x << "," << y << "\n";
}