-
Notifications
You must be signed in to change notification settings - Fork 1
/
base_arbitary.hpp
55 lines (51 loc) · 1.25 KB
/
base_arbitary.hpp
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
#pragma once
#include"../template/template.hpp"
namespace lib {
template<typename T>
struct Vec {
T x, y, z;
Vec (T _x = 0, T _y = 0, T _z = 0) : x(_x), y(_y), z(_z) {}
Vec& operator*=(const T& a){
x *= a;
y *= a;
z *= a;
return *this;
}
Vec& operator/=(const T& a){
x /= a;
y /= a;
z /= a;
return *this;
}
Vec& operator+=(const Vec& rhs) {
x += rhs.x;
y += rhs.y;
z += rhs.z;
return *this;
}
Vec& operator-=(const Vec& rhs) {
x -= rhs.x;
y -= rhs.y;
z -= rhs.z;
return *this;
}
friend Vec operator+(const Vec& lhs, const Vec& rhs) {
return Vec(lhs) += rhs;
}
friend Vec operator-(const Vec& lhs, const Vec& rhs) {
return Vec(lhs) -= rhs;
}
friend Vec operator*(const Vec& lhs, const T& rhs) {
return Vec(lhs) *= rhs;
}
friend Vec operator*(const T& rhs, const Vec& lhs) {
return Vec(lhs) *= rhs;
}
friend Vec operator/(const Vec& lhs, const T& rhs) {
return Vec(lhs) /= rhs;
}
friend std::ostream &operator<<(std::ostream &os,const Vec&r) {
return os << "(" << r.x << "," << r.y << "," << r.z << ")";
}
};
};