Xinqi Bao's Git

XbSlicer, re-organized the entire project
[XbSlicer.git] / src / Vec3d.cc
1 #include "Vec3d.hh"
2
3 #include <cmath>
4
5 #include "Configurations.hh"
6
7 Vec3d::Vec3d() {}
8 Vec3d::Vec3d(double x, double y, double z) : x(x), y(y), z(z) {}
9 void Vec3d::readBuffer(BufferReadBinary& buffer)
10 {
11 x = buffer.getFloat();
12 buffer.stepFloat();
13 y = buffer.getFloat();
14 buffer.stepFloat();
15 z = buffer.getFloat();
16 buffer.stepFloat();
17 }
18
19 bool Vec3d::equal(const Vec3d& v) const
20 {
21 if (fabs(x - v.x) < thr && fabs(y - v.y) < thr && fabs(z - v.z) < thr)
22 return true;
23 return false;
24 }
25 bool Vec3d::equal(const Vec3d* v) const { return equal(*v); }
26 double Vec3d::sum() const { return x + y + z; }
27
28 std::istream& operator>>(std::istream& s, Vec3d& v)
29 {
30 return s >> v.x >> v.y >> v.z;
31 }
32 std::istream& operator>>(std::istream& s, Vec3d* v)
33 {
34 return s >> v->x >> v->y >> v->z;
35 }
36 std::ostream& operator<<(std::ostream& s, const Vec3d& v)
37 {
38 return s << v.x << "," << v.y << "," << v.z;
39 }
40 std::ostream& operator<<(std::ostream& s, const Vec3d* v)
41 {
42 return s << v->x << "," << v->y << "," << v->z;
43 }