-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.cpp
More file actions
50 lines (39 loc) · 1.05 KB
/
Point.cpp
File metadata and controls
50 lines (39 loc) · 1.05 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
//
// Created by jlwoolf on 01/12/21.
//
#include "Point.h"
Point::Point() : x(0), y(0), z(0), n(0) {}
Point::Point(Point const &p) : x(p.x), y(p.y), z(p.z), n(p.n) {}
Point::Point(int x, int y, int z, int n) : x(x), y(y), z(z), n(n) {}
bool Point::operator==(const Point &p) {
return n == p.n;
}
bool Point::operator<(const Point &p) {
return n < p.n;
}
bool Point::operator>(const Point &p) {
return n > p.n;
}
std::ostream &operator<<(std::ostream &os, const Point &p) {
os << p.x << " " << p.y << " " << p.z;
return os;
}
std::fstream &operator<<(std::fstream &fs, const Point &p) {
fs << std::to_string(p.x) << " " << std::to_string(p.y) << " " << std::to_string(p.z);
return fs;
}
int Point::getN() const {
return n;
}
int Point::getX() const {
return x;
}
int Point::getY() const {
return y;
}
int Point::getZ() const {
return z;
}
int Point::manhattanDistance(const Point &p1, const Point &p2) {
return std::abs(p1.getX() - p2.getX()) + std::abs(p1.getY() - p2.getY()) + std::abs(p1.getZ() - p2.getZ());
}