-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoint2D.cpp
48 lines (39 loc) · 996 Bytes
/
Point2D.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
48
#include <iostream>
#include <cmath>
#include "Point2D.h"
#include "Vector2D.h"
using namespace std;
//default constructor
Point2D::Point2D() {
x = 0.0;
y = 0.0;
}
Point2D::Point2D(double inputx, double inputy) {
x = inputx;
y = inputy;
}
//calculates distance between two point2ds
double GetDistanceBetween(Point2D p1, Point2D p2) {
return sqrt(pow(p1.x-p2.x,2.0)+pow(p1.y-p2.y,2.0));
}
//NOT Required in program document
bool operator == (Point2D p1, Point2D p2){
if (p1.x == p2.x && p1.y == p2.y){
return true;
}
return false;
}
//OLD ARTIFACT - DON'T USE
/*Point2D operator + (Point2D p1, Point2D p2) {
return Point2D(p1.x + p2.x, p1.y + p2.y);
}*/
Vector2D operator - (Point2D p1, Point2D p2) {
return Vector2D(p1.x - p2.x, p1.y - p2.y);
}
Point2D operator + (Point2D p1, Vector2D p2) {
return Point2D(p1.x + p2.x, p1.y + p2.y);
}
ostream& operator << (ostream& out, Point2D p1) {
out << "(" << p1.x << "," << p1.y << ")";
return out;
}