Disable flaky tests in --site-per-process mode:
[chromium-blink-merge.git] / ppapi / cpp / point.h
blobc881bbd55068898dba21d0774221978125e520f7
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PPAPI_CPP_POINT_H_
6 #define PPAPI_CPP_POINT_H_
8 #include "ppapi/c/pp_point.h"
10 /// @file
11 /// This file defines the API to create a 2 dimensional point.
13 namespace pp {
15 /// A 2 dimensional point with 0,0 being the upper-left starting coordinate.
16 class Point {
17 public:
18 /// The default constructor for a point at 0,0.
19 Point() {
20 point_.x = 0;
21 point_.y = 0;
24 /// A constructor accepting two int32_t values for x and y and converting
25 /// them to a Point.
26 ///
27 /// @param[in] in_x An int32_t value representing a horizontal coordinate
28 /// of a point, starting with 0 as the left-most coordinate.
29 /// @param[in] in_y An int32_t value representing a vertical coordinate
30 /// of a point, starting with 0 as the top-most coordinate.
31 Point(int32_t in_x, int32_t in_y) {
32 point_.x = in_x;
33 point_.y = in_y;
36 /// A constructor accepting a pointer to a PP_Point and converting the
37 /// PP_Point to a Point. This is an implicit conversion constructor.
38 ///
39 /// @param[in] point A pointer to a PP_Point.
40 Point(const PP_Point& point) { // Implicit.
41 point_.x = point.x;
42 point_.y = point.y;
45 /// Destructor.
46 ~Point() {
49 /// A function allowing implicit conversion of a Point to a PP_Point.
50 /// @return A Point.
51 operator PP_Point() const {
52 return point_;
55 /// Getter function for returning the internal PP_Point struct.
56 ///
57 /// @return A const reference to the internal PP_Point struct.
58 const PP_Point& pp_point() const {
59 return point_;
62 /// Getter function for returning the internal PP_Point struct.
63 ///
64 /// @return A mutable reference to the PP_Point struct.
65 PP_Point& pp_point() {
66 return point_;
69 /// Getter function for returning the value of x.
70 ///
71 /// @return The value of x for this Point.
72 int32_t x() const { return point_.x; }
74 /// Setter function for setting the value of x.
75 ///
76 /// @param[in] in_x A new x value.
77 void set_x(int32_t in_x) {
78 point_.x = in_x;
81 /// Getter function for returning the value of y.
82 ///
83 /// @return The value of y for this Point.
84 int32_t y() const { return point_.y; }
86 /// Setter function for setting the value of y.
87 ///
88 /// @param[in] in_y A new y value.
89 void set_y(int32_t in_y) {
90 point_.y = in_y;
93 /// Adds two Points (this and other) together by adding their x values and
94 /// y values.
95 ///
96 /// @param[in] other A Point.
97 ///
98 /// @return A new Point containing the result.
99 Point operator+(const Point& other) const {
100 return Point(x() + other.x(), y() + other.y());
103 /// Subtracts one Point from another Point by subtracting their x values
104 /// and y values. Returns a new point with the result.
106 /// @param[in] other A Point.
108 /// @return A new Point containing the result.
109 Point operator-(const Point& other) const {
110 return Point(x() - other.x(), y() - other.y());
113 /// Adds two Points (this and other) together by adding their x and y
114 /// values. Returns this point as the result.
116 /// @param[in] other A Point.
118 /// @return This Point containing the result.
119 Point& operator+=(const Point& other) {
120 point_.x += other.x();
121 point_.y += other.y();
122 return *this;
125 /// Subtracts one Point from another Point by subtracting their x values
126 /// and y values. Returns this point as the result.
128 /// @param[in] other A Point.
130 /// @return This Point containing the result.
131 Point& operator-=(const Point& other) {
132 point_.x -= other.x();
133 point_.y -= other.y();
134 return *this;
137 /// Swaps the coordinates of two Points.
139 /// @param[in] other A Point.
140 void swap(Point& other) {
141 int32_t x = point_.x;
142 int32_t y = point_.y;
143 point_.x = other.point_.x;
144 point_.y = other.point_.y;
145 other.point_.x = x;
146 other.point_.y = y;
149 private:
150 PP_Point point_;
153 /// A 2 dimensional floating-point point with 0,0 being the upper-left starting
154 /// coordinate.
155 class FloatPoint {
156 public:
157 /// A constructor for a point at 0,0.
158 FloatPoint() {
159 float_point_.x = 0.0f;
160 float_point_.y = 0.0f;
163 /// A constructor accepting two values for x and y and converting them to a
164 /// FloatPoint.
166 /// @param[in] in_x An value representing a horizontal coordinate of a
167 /// point, starting with 0 as the left-most coordinate.
169 /// @param[in] in_y An value representing a vertical coordinate of a point,
170 /// starting with 0 as the top-most coordinate.
171 FloatPoint(float in_x, float in_y) {
172 float_point_.x = in_x;
173 float_point_.y = in_y;
176 /// A constructor accepting a pointer to a PP_FloatPoint and converting the
177 /// PP_Point to a Point. This is an implicit conversion constructor.
179 /// @param[in] point A PP_FloatPoint.
180 FloatPoint(const PP_FloatPoint& point) { // Implicit.
181 float_point_.x = point.x;
182 float_point_.y = point.y;
184 /// Destructor.
185 ~FloatPoint() {
188 /// A function allowing implicit conversion of a FloatPoint to a
189 /// PP_FloatPoint.
190 operator PP_FloatPoint() const {
191 return float_point_;
194 /// Getter function for returning the internal PP_FloatPoint struct.
196 /// @return A const reference to the internal PP_FloatPoint struct.
197 const PP_FloatPoint& pp_float_point() const {
198 return float_point_;
201 /// Getter function for returning the internal PP_Point struct.
203 /// @return A mutable reference to the PP_Point struct.
204 PP_FloatPoint& pp_float_point() {
205 return float_point_;
208 /// Getter function for returning the value of x.
210 /// @return The value of x for this Point.
211 float x() const { return float_point_.x; }
213 /// Setter function for setting the value of x.
215 /// @param[in] in_x A new x value.
216 void set_x(float in_x) {
217 float_point_.x = in_x;
220 /// Getter function for returning the value of y.
222 /// @return The value of y for this Point.
223 float y() const { return float_point_.y; }
225 /// Setter function for setting the value of y.
227 /// @param[in] in_y A new y value.
228 void set_y(float in_y) {
229 float_point_.y = in_y;
232 /// Adds two Points (this and other) together by adding their x values and
233 /// y values.
235 /// @param[in] other A Point.
237 /// @return A new Point containing the result.
238 FloatPoint operator+(const FloatPoint& other) const {
239 return FloatPoint(x() + other.x(), y() + other.y());
242 /// Subtracts one Point from another Point by subtracting their x values
243 /// and y values. Returns a new point with the result.
245 /// @param[in] other A FloatPoint.
247 /// @return A new Point containing the result.
248 FloatPoint operator-(const FloatPoint& other) const {
249 return FloatPoint(x() - other.x(), y() - other.y());
252 /// Adds two Points (this and other) together by adding their x and y
253 /// values. Returns this point as the result.
255 /// @param[in] other A Point.
257 /// @return This Point containing the result.
258 FloatPoint& operator+=(const FloatPoint& other) {
259 float_point_.x += other.x();
260 float_point_.y += other.y();
261 return *this;
264 /// Subtracts one Point from another Point by subtracting their x values
265 /// and y values. Returns this point as the result.
267 /// @param[in] other A Point.
269 /// @return This Point containing the result.
270 FloatPoint& operator-=(const FloatPoint& other) {
271 float_point_.x -= other.x();
272 float_point_.y -= other.y();
273 return *this;
276 /// Swaps the coordinates of two Points.
278 /// @param[in] other A Point.
279 void swap(FloatPoint& other) {
280 float x = float_point_.x;
281 float y = float_point_.y;
282 float_point_.x = other.float_point_.x;
283 float_point_.y = other.float_point_.y;
284 other.float_point_.x = x;
285 other.float_point_.y = y;
288 private:
289 PP_FloatPoint float_point_;
292 } // namespace pp
294 /// Determines whether the x and y values of two Points are equal.
296 /// @param[in] lhs The Point on the left-hand side of the equation.
297 /// @param[in] rhs The Point on the right-hand side of the equation.
299 /// @return true if they are equal, false if unequal.
300 inline bool operator==(const pp::Point& lhs, const pp::Point& rhs) {
301 return lhs.x() == rhs.x() && lhs.y() == rhs.y();
304 /// Determines whether two Points have different coordinates.
306 /// @param[in] lhs The Point on the left-hand side of the equation.
307 /// @param[in] rhs The Point on the right-hand side of the equation.
309 /// @return true if the coordinates of lhs are equal to the coordinates
310 /// of rhs, otherwise false.
311 inline bool operator!=(const pp::Point& lhs, const pp::Point& rhs) {
312 return !(lhs == rhs);
315 /// Determines whether the x and y values of two FloatPoints are equal.
317 /// @param[in] lhs The Point on the left-hand side of the equation.
318 /// @param[in] rhs The Point on the right-hand side of the equation.
320 /// @return true if they are equal, false if unequal.
321 inline bool operator==(const pp::FloatPoint& lhs, const pp::FloatPoint& rhs) {
322 return lhs.x() == rhs.x() && lhs.y() == rhs.y();
325 /// Determines whether two Points have different coordinates.
327 /// @param[in] lhs The Point on the left-hand side of the equation.
328 /// @param[in] rhs The Point on the right-hand side of the equation.
330 /// @return true if the coordinates of lhs are equal to the coordinates
331 /// of rhs, otherwise false.
332 inline bool operator!=(const pp::FloatPoint& lhs, const pp::FloatPoint& rhs) {
333 return !(lhs == rhs);
336 #endif // PPAPI_CPP_POINT_H_