-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.cpp
47 lines (39 loc) · 874 Bytes
/
point.cpp
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
#include "point.hpp"
#include <iostream>
#include <cmath>
Point Point::operator+(Point other)
{
return Point(x + other.x, y + other.y, z + other.z);
}
Point Point::operator-(Point other)
{
return Point(x - other.x, y - other.y, z - other.z);
}
Point Point::operator/(float divisor)
{
return Point(x / divisor, y / divisor, z / divisor);
}
bool Point::operator==(Point other)
{
return x == other.x && y == other.y && z == other.z;
}
float Point::length() {
return std::sqrt(std::pow(x, 2.0f) + std::pow(y, 2.0f) + std::pow(z, 2.0f));
}
Point Point::x_component()
{
return Point(x, 0, 0);
}
Point Point::y_component()
{
return Point(0, y, 0);
}
Point Point::z_component()
{
return Point(0, 0, z);
}
std::ostream &operator<<(std::ostream &os, const Point &p)
{
os << "(" << p.x << ", " << p.y << ", " << p.z << ")";
return os;
}