Xinqi Bao's Git

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