-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector.h
executable file
·47 lines (40 loc) · 1.17 KB
/
vector.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
#ifndef VECTOR_H
#define VECTOR_H
#include <iostream>
#include <string>
#include <functional>
#include "math.h"
class Vector {
public:
double x, y, z;
public:
Vector();
Vector(double x, double y, double z);
Vector(const Vector& vector);
Vector operator+(const Vector& vector);
Vector operator*(double rhs);
Vector& operator=(const Vector& vector);
bool operator==(const Vector& vector) const {
return x == vector.x && y == vector.y && z == vector.z;
}
bool equalsWithThreshold(const Vector& vector, double threshold) {
return Math::doubleEquals(x, vector.x, threshold) &&
Math::doubleEquals(y, vector.y, threshold) &&
Math::doubleEquals(z, vector.z, threshold);
}
Vector interpolate(const Vector& vector, double factor) const;
double getX();
double getY();
double getZ();
Vector& parseFromString(const std::string& data);
friend std::ostream& operator<<(std::ostream& out, const Vector& vector);
};
namespace std {
template <>
struct hash<Vector> {
size_t operator()(const Vector& vector) const {
return hash<double>()(vector.x) ^ hash<double>()(vector.y) ^ hash<double>()(vector.z);
}
};
}
#endif