-
Notifications
You must be signed in to change notification settings - Fork 1
/
vector2f.h
46 lines (35 loc) · 1.18 KB
/
vector2f.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
#ifndef VECTOR2F__H
#define VECTOR2F__H
#include <iostream>
class Vector2f {
public:
explicit Vector2f(float x = 0, float y = 0);
float &operator[](int index);
float operator[](int index) const;
bool operator==(const Vector2f &other) const {
return (v[0]==other.v[0] && v[1] == other.v[1]);
}
bool operator!=(const Vector2f &other) const {
return (v[0]!=other.v[0] or v[1] != other.v[1]);
}
Vector2f operator*(float scale) const;
Vector2f operator/(float scale) const;
Vector2f operator+(const Vector2f &other) const;
Vector2f operator-(const Vector2f &other) const;
Vector2f operator-() const;
const Vector2f &operator*=(float scale);
const Vector2f &operator/=(float scale);
const Vector2f &operator+=(const Vector2f &other);
const Vector2f &operator-=(const Vector2f &other);
float magnitude() const;
float magnitudeSquared() const;
Vector2f normalize() const;
float dot(const Vector2f &other) const;
Vector2f cross(const Vector2f &other) const;
Vector2f& operator=(const Vector2f&);
private:
float v[2];
};
Vector2f operator*(float scale, const Vector2f &v);
std::ostream &operator<<(std::ostream &output, const Vector2f &v);
#endif