77Point2D::Point2D () {}
88
99Point2D::Point2D (double xi, double yi) {
10- this ->x = xi;
11- this ->y = yi;
10+ this ->x = xi;
11+ this ->y = yi;
1212}
1313
1414Point2D::Point2D (const Point2D &other) {
15- this ->x = other.x ;
16- this ->y = other.y ;
15+ this ->x = other.x ;
16+ this ->y = other.y ;
1717}
1818
19- Point2D::~Point2D () {}
19+ Point2D::~Point2D () {
20+ }
2021
2122void Point2D::Set (const double xi, const double yi) {
22- this ->x = xi;
23- this ->y = yi;
23+ this ->x =xi;
24+ this ->y =yi;
25+ }
26+
27+ void Point2D::SetX (double xi) {
28+ this ->x =xi;
2429}
2530
26- void Point2D::SetX (double xi) { this ->x = xi; }
31+ void Point2D::SetY (double yi) {
32+ this ->y =yi;
33+ }
2734
28- void Point2D::SetY (double yi) { this ->y = yi; }
35+ double Point2D::GetX () const {
36+ return x;
37+ }
2938
30- double Point2D::GetX () const { return x; }
39+ double Point2D::GetY () const {
40+ return y;
41+ }
3142
32- double Point2D::GetY () const { return y; }
43+ /* std::string Point2D::toString(Point2D &p) {
44+ return "( "+ std::to_string(p.x) + " , " +std::to_string(p.y)+" )";
45+ }*/
3346
34- // std::string Point2D::ToString() const {
47+
48+ // To find orientation of ordered triplet (p1, p2, p3).
49+ // The function returns following values
50+ // 0 --> p, q and r are colinear
51+ // 1 --> Clockwise
52+ // 2 --> Counterclockwise
53+ // taken from http://www.geeksforgeeks.org/orientation-3-ordered-points/
54+ int Point2D::orientation (Point2D p1, Point2D p2, Point2D p3)
55+ {
56+ int val = (p2.y - p1.y ) * (p3.x - p2.x ) -
57+ (p2.x - p1.x ) * (p3.y - p2.y );
58+
59+ if (val == 0 ) return 0 ; // colinear
60+ return (val > 0 )? 1 : 2 ; // clock or counterclock wise
61+ }
62+
63+ // std::string Point2D::ToString() const {
3564// return std::string("%f",x)
3665// }
3766
3867void Point2D::operator =(const Point2D &other) {
39- x = other.x ;
40- y = other.y ;
68+ x= other.x ;
69+ y= other.y ;
4170}
4271
4372bool Point2D::operator ==(const Point2D &other) const {
44- return (x == other.x ) && (y == other.y );
73+ return (x== other.x )&&(y== other.y );
4574}
4675
4776bool Point2D::operator !=(const Point2D &other) const {
48- return !(*this == other);
77+ return !(*this == other);
4978}
5079
5180// x order
5281bool Point2D::operator >(const Point2D &other) const {
53- if (x != other.x )
54- return x > other.x ;
55- else
56- return y > other.y ; // equal x
82+ if (x!=other.x )return x>other.x ;
83+ else return y>other.y ;// equal x
5784}
5885
59- bool Point2D::operator <(const Point2D &other) const {
60- // std::cout<<" comparing "<<x<<" and "<<other.x<<" output "<<(x <
61- // other.x)<<std::endl;
62- if (x != other.x )
63- return x < other.x ;
64- else
65- return y < other.y ; // equal x
86+ bool Point2D::operator < (const Point2D &other) const {
87+ // std::cout<<" comparing "<<x<<" and "<<other.x<<" output "<<(x < other.x)<<std::endl;
88+ if (x!=other.x ) return x < other.x ;
89+ else return y<other.y ;// equal x
6690}
6791
6892bool Point2D::operator >=(const Point2D &other) const {
69- return (*this == other) || (*this > other);
93+ return (*this == other)|| (*this > other);
7094}
7195
7296bool Point2D::operator <=(const Point2D &other) const {
73- return (*this == other) || (*this < other);
97+ return (*this == other)|| (*this < other);
7498}
99+
100+ void Point2D::write (std::ostream& os)
101+ {
102+ os << " ( " <<x<<" , " <<y<<" )" <<std::endl;
103+ }
0 commit comments