ezgl  1.0.1
An Easy Graphics & GUI Library
point.hpp
1 /*
2  * Copyright 2019-2022 University of Toronto
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * Authors: Mario Badr, Sameh Attia, Tanner Young-Schultz and Vaughn Betz
17  */
18 
19 #ifndef EZGL_POINT_HPP
20 #define EZGL_POINT_HPP
21 
22 namespace ezgl {
23 
27 class point2d {
28 public:
32  point2d() : x(0.0), y(0.0)
33  {
34  }
35 
39  point2d(double x_coord, double y_coord) : x(x_coord), y(y_coord)
40  {
41  }
42 
46  double x = 0.0;
47 
51  double y = 0.0;
52 
56  friend bool operator==(point2d const &lhs, point2d const &rhs)
57  {
58  return (lhs.x == rhs.x) && (lhs.y == rhs.y);
59  }
60 
64  friend bool operator!=(point2d const &lhs, point2d const &rhs)
65  {
66  return !(lhs == rhs);
67  }
68 
72  friend point2d operator+(point2d const &lhs, point2d const &rhs)
73  {
74  return {lhs.x + rhs.x, lhs.y + rhs.y};
75  }
76 
80  friend point2d &operator+=(point2d &lhs, point2d const &rhs)
81  {
82  lhs.x += rhs.x;
83  lhs.y += rhs.y;
84 
85  return lhs;
86  }
87 
91  friend point2d operator-(point2d const &lhs, point2d const &rhs)
92  {
93  return {lhs.x - rhs.x, lhs.y - rhs.y};
94  }
95 
99  friend point2d &operator-=(point2d &lhs, point2d const &rhs)
100  {
101  lhs.x -= rhs.x;
102  lhs.y -= rhs.y;
103 
104  return lhs;
105  }
106 
110  friend point2d operator*(point2d const &lhs, point2d const &rhs)
111  {
112  return {lhs.x * rhs.x, lhs.y * rhs.y};
113  }
114 
118  friend point2d &operator*=(point2d &lhs, point2d const &rhs)
119  {
120  lhs.x *= rhs.x;
121  lhs.y *= rhs.y;
122 
123  return lhs;
124  }
125 };
126 }
127 
128 #endif //EZGL_POINT_HPP
Represents a two-dimensional point.
Definition: point.hpp:27
point2d()
Default constructor: Create a point at (0, 0).
Definition: point.hpp:32
double y
Location of the y-coordinate.
Definition: point.hpp:51
friend bool operator==(point2d const &lhs, point2d const &rhs)
Test for equality.
Definition: point.hpp:56
double x
Location of the x-coordinate.
Definition: point.hpp:46
friend point2d operator-(point2d const &lhs, point2d const &rhs)
Create a new point that is the difference of two points.
Definition: point.hpp:91
friend point2d & operator*=(point2d &lhs, point2d const &rhs)
Multiply one point with another point.
Definition: point.hpp:118
friend point2d & operator+=(point2d &lhs, point2d const &rhs)
Add one point to another point.
Definition: point.hpp:80
friend point2d & operator-=(point2d &lhs, point2d const &rhs)
Subtract one point from another point.
Definition: point.hpp:99
friend point2d operator*(point2d const &lhs, point2d const &rhs)
Create a new point that is the product of two points.
Definition: point.hpp:110
point2d(double x_coord, double y_coord)
Create a point at the given x and y position.
Definition: point.hpp:39
friend point2d operator+(point2d const &lhs, point2d const &rhs)
Create a new point that is the sum of two points.
Definition: point.hpp:72
friend bool operator!=(point2d const &lhs, point2d const &rhs)
Test for inequality.
Definition: point.hpp:64
A library for creating a graphical user interface.
Definition: application.hpp:40