-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_pointxyz.cpp
More file actions
53 lines (40 loc) · 1.15 KB
/
example_pointxyz.cpp
File metadata and controls
53 lines (40 loc) · 1.15 KB
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
// NOTE: In g++, compile with -O3
// NOTE: In msvc, compile with /std:c++14 /O2 /EHsc. Not using /EHsc will cause the code to crash
#include "expr_vector.h"
class PointXYZ
{
public:
PointXYZ() : x(0), y(0), z(0) {}
PointXYZ(double x, double y, double z) : x(x), y(y), z(z) {}
double x,y,z;
};
inline PointXYZ operator+(PointXYZ p1, PointXYZ p2)
{
return PointXYZ{p1.x+p2.x, p1.y+p2.y, p1.z+p2.z};
}
inline PointXYZ operator*(double d, PointXYZ p)
{
return PointXYZ{d*p.x, d*p.y, d*p.z};
}
inline PointXYZ operator*(PointXYZ p, double d)
{
return PointXYZ{p.x*d, p.y*d, p.z*d};
}
inline PointXYZ operator/(PointXYZ p, double d)
{
return PointXYZ{p.x/d, p.y/d, p.z/d};
}
inline double operator*(PointXYZ p1, PointXYZ p2)
{
return p1.x*p2.x + p1.y*p2.y + p1.z*p2.z;
}
inline double abs(PointXYZ p) {return sqrt(p.x*p.x + p.y*p.y + p.z*p.z);}
std::ostream& operator<<(std::ostream& os, const PointXYZ& p) {os << "(" << p.x << "," << p.y << "," << p.z << ")"; return os;}
int main()
{
ExprVector<PointXYZ> a(10, PointXYZ(1,2,3)), b;
b = 2 * a / sqrt(a*a);
std::cout << b << std::endl;
std::cout << abs(b) << std::endl;
return 0;
}