-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathline.cpp
More file actions
65 lines (62 loc) · 1.29 KB
/
line.cpp
File metadata and controls
65 lines (62 loc) · 1.29 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "Line.h"
#include "Point.h"
Line::Line()
{
p1.x = 0.0, p1.y = 0.0, p2.x = 1.0, p2.y = 1.0;
}
Line::Line(const Line& lin)
{
*this = lin;
}
void Line::setPoint1(double p, double q)
{
p1.Point::Point(p, q);
}
void Line::setPoint2(double p, double q)
{
p2.Point::Point(p, q);
}
void Line::setLine(double p, double q, double r, double s)
{
p1.Point::Point(p, q);
p2.Point::Point(r, s);
}
Point Line::getPoint1()
{
return p1;
}
Point Line::getPoint2()
{
return p2;
}
bool Line::operator==(const Line& ln1)
{
return (p1 == ln1.p1 && p2 == ln1.p2);
}
bool Line::operator!=(const Line& ln1)
{
return (p1 != ln1.p1 && p2 != ln1.p2);
}
double Line::Distance(const Line& ln)
{
return(p1 - p2);
}
double Line::Slope(const Line& ln)
{
return((p1.y - p2.y) / (p1.x - p2.x));
}
istream& operator>>(istream& is, Line& ln)
{
double pna;
double pnb;
double pnc;
double pnd;
is >> pna >> pnb >> pnc >> pnd;
ln.setLine(pna, pnb, pnc, pnd);
return is;
}
ostream& operator<<(ostream& os, Line& ln)
{
os << "(" << "(" << ln.getPoint1().getX() << "," << ln.getPoint1().getY() << ")" << "," << "(" << ln.getPoint2().getX() << "," << ln.getPoint2().getY() << ")" << ")";
return os;
}