Pepper_56_C++_interfaces
Pepper_56_C++_interfaces
 All Classes Namespaces Files Functions Typedefs Enumerations Macros Groups
point.h
Go to the documentation of this file.
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.
4 
5 #ifndef PPAPI_CPP_POINT_H_
6 #define PPAPI_CPP_POINT_H_
7 
8 #include <stdint.h>
9 
10 #include "ppapi/c/pp_point.h"
11 
14 
15 namespace pp {
16 
18 class Point {
19  public:
21  Point() {
22  point_.x = 0;
23  point_.y = 0;
24  }
25 
33  Point(int32_t in_x, int32_t in_y) {
34  point_.x = in_x;
35  point_.y = in_y;
36  }
37 
42  Point(const PP_Point& point) { // Implicit.
43  point_.x = point.x;
44  point_.y = point.y;
45  }
46 
48  ~Point() {
49  }
50 
53  operator PP_Point() const {
54  return point_;
55  }
56 
60  const PP_Point& pp_point() const {
61  return point_;
62  }
63 
67  PP_Point& pp_point() {
68  return point_;
69  }
70 
74  int32_t x() const { return point_.x; }
75 
79  void set_x(int32_t in_x) {
80  point_.x = in_x;
81  }
82 
86  int32_t y() const { return point_.y; }
87 
91  void set_y(int32_t in_y) {
92  point_.y = in_y;
93  }
94 
101  Point operator+(const Point& other) const {
102  return Point(x() + other.x(), y() + other.y());
103  }
104 
111  Point operator-(const Point& other) const {
112  return Point(x() - other.x(), y() - other.y());
113  }
114 
121  Point& operator+=(const Point& other) {
122  point_.x += other.x();
123  point_.y += other.y();
124  return *this;
125  }
126 
133  Point& operator-=(const Point& other) {
134  point_.x -= other.x();
135  point_.y -= other.y();
136  return *this;
137  }
138 
142  void swap(Point& other) {
143  int32_t x = point_.x;
144  int32_t y = point_.y;
145  point_.x = other.point_.x;
146  point_.y = other.point_.y;
147  other.point_.x = x;
148  other.point_.y = y;
149  }
150 
151  private:
152  PP_Point point_;
153 };
154 
157 class FloatPoint {
158  public:
161  float_point_.x = 0.0f;
162  float_point_.y = 0.0f;
163  }
164 
173  FloatPoint(float in_x, float in_y) {
174  float_point_.x = in_x;
175  float_point_.y = in_y;
176  }
177 
182  FloatPoint(const PP_FloatPoint& point) { // Implicit.
183  float_point_.x = point.x;
184  float_point_.y = point.y;
185  }
188  }
189 
192  operator PP_FloatPoint() const {
193  return float_point_;
194  }
195 
199  const PP_FloatPoint& pp_float_point() const {
200  return float_point_;
201  }
202 
206  PP_FloatPoint& pp_float_point() {
207  return float_point_;
208  }
209 
213  float x() const { return float_point_.x; }
214 
218  void set_x(float in_x) {
219  float_point_.x = in_x;
220  }
221 
225  float y() const { return float_point_.y; }
226 
230  void set_y(float in_y) {
231  float_point_.y = in_y;
232  }
233 
240  FloatPoint operator+(const FloatPoint& other) const {
241  return FloatPoint(x() + other.x(), y() + other.y());
242  }
243 
250  FloatPoint operator-(const FloatPoint& other) const {
251  return FloatPoint(x() - other.x(), y() - other.y());
252  }
253 
261  float_point_.x += other.x();
262  float_point_.y += other.y();
263  return *this;
264  }
265 
273  float_point_.x -= other.x();
274  float_point_.y -= other.y();
275  return *this;
276  }
277 
281  void swap(FloatPoint& other) {
282  float x = float_point_.x;
283  float y = float_point_.y;
284  float_point_.x = other.float_point_.x;
285  float_point_.y = other.float_point_.y;
286  other.float_point_.x = x;
287  other.float_point_.y = y;
288  }
289 
290  private:
291  PP_FloatPoint float_point_;
292 };
293 
294 } // namespace pp
295 
302 inline bool operator==(const pp::Point& lhs, const pp::Point& rhs) {
303  return lhs.x() == rhs.x() && lhs.y() == rhs.y();
304 }
305 
313 inline bool operator!=(const pp::Point& lhs, const pp::Point& rhs) {
314  return !(lhs == rhs);
315 }
316 
323 inline bool operator==(const pp::FloatPoint& lhs, const pp::FloatPoint& rhs) {
324  return lhs.x() == rhs.x() && lhs.y() == rhs.y();
325 }
326 
334 inline bool operator!=(const pp::FloatPoint& lhs, const pp::FloatPoint& rhs) {
335  return !(lhs == rhs);
336 }
337 
338 #endif // PPAPI_CPP_POINT_H_
void swap(FloatPoint &other)
Definition: point.h:281
Point(const PP_Point &point)
Definition: point.h:42
const PP_Point & pp_point() const
Definition: point.h:60
A 2 dimensional point with 0,0 being the upper-left starting coordinate.
Definition: point.h:18
FloatPoint & operator+=(const FloatPoint &other)
Definition: point.h:260
const PP_FloatPoint & pp_float_point() const
Definition: point.h:199
int32_t y() const
Definition: point.h:86
void swap(Point &other)
Definition: point.h:142
PP_FloatPoint & pp_float_point()
Definition: point.h:206
~Point()
Destructor.
Definition: point.h:48
void set_y(int32_t in_y)
Definition: point.h:91
Point operator+(const Point &other) const
Definition: point.h:101
void set_x(int32_t in_x)
Definition: point.h:79
float y() const
Definition: point.h:225
void set_y(float in_y)
Definition: point.h:230
Point & operator-=(const Point &other)
Definition: point.h:133
FloatPoint & operator-=(const FloatPoint &other)
Definition: point.h:272
Point()
The default constructor for a point at 0,0.
Definition: point.h:21
int32_t x() const
Definition: point.h:74
float x() const
Definition: point.h:213
Definition: point.h:157
~FloatPoint()
Destructor.
Definition: point.h:187
void set_x(float in_x)
Definition: point.h:218
Point & operator+=(const Point &other)
Definition: point.h:121
FloatPoint()
A constructor for a point at 0,0.
Definition: point.h:160
PP_Point & pp_point()
Definition: point.h:67
Point operator-(const Point &other) const
Definition: point.h:111
FloatPoint(float in_x, float in_y)
Definition: point.h:173
FloatPoint(const PP_FloatPoint &point)
Definition: point.h:182
bool operator!=(const pp::Point &lhs, const pp::Point &rhs)
Definition: point.h:313
FloatPoint operator-(const FloatPoint &other) const
Definition: point.h:250
FloatPoint operator+(const FloatPoint &other) const
Definition: point.h:240
bool operator==(const pp::Point &lhs, const pp::Point &rhs)
Definition: point.h:302
Point(int32_t in_x, int32_t in_y)
Definition: point.h:33