-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvec2.cpp
More file actions
50 lines (35 loc) · 1017 Bytes
/
Copy pathvec2.cpp
File metadata and controls
50 lines (35 loc) · 1017 Bytes
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
#include "vec2.h"
Vec2::Vec2(float x_, float y_)
: x(x_), y(y_) {}
Vec2::Vec2(): x(0), y(0){}
const Vec2 Vec2::operator +(const Vec2& v) const {
return Vec2(this->x + v.x, this->y + v.y);
}
const Vec2 Vec2::operator -(const Vec2& v) const {
return Vec2(this->x - v.x, this->y - v.y);
}
const Vec2 Vec2::operator *(const float scal) const {
return Vec2(scal*this->x, scal*this->y);
}
const Vec2 operator*(const float scal, Vec2 const& v) {
const Vec2 u = Vec2(scal*v.x, scal*v.y);
return u;
}
std::ostream& operator<<(std::ostream& out, Vec2 const& v) {
return out << (double) v.x << ", " << (double) v.y;
}
const float Vec2::dotProduct(const Vec2& v) const {
return this->x * v.x + this->y * v.y;
}
const float Vec2::squaredLength() const {
return this->x * this->x + this->y * this->y;
}
const float Vec2::length() const {
return sqrt(this->squaredLength());
}
const float &Vec2::getX() const {
return x;
}
const float &Vec2::getY() const {
return y;
}