OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PPAPI_CPP_POINT_H_ | 5 #ifndef PPAPI_CPP_POINT_H_ |
6 #define PPAPI_CPP_POINT_H_ | 6 #define PPAPI_CPP_POINT_H_ |
7 | 7 |
8 #include "ppapi/c/pp_point.h" | 8 #include "ppapi/c/pp_point.h" |
9 | 9 |
10 /// @file | 10 /// @file |
11 /// This file defines the API to create a 2 dimensional point. | 11 /// This file defines the API to create a 2 dimensional point. |
12 | 12 |
13 namespace pp { | 13 namespace pp { |
14 | 14 |
15 /// A 2 dimensional point with 0,0 being the upper-left starting coordinate. | 15 /// A 2 dimensional point with 0,0 being the upper-left starting coordinate. |
16 class Point { | 16 class Point { |
17 public: | 17 public: |
18 /// A constructor for a point at 0,0. | 18 /// A constructor for a point at 0,0. |
19 Point() { | 19 Point() { |
20 point_.x = 0; | 20 point_.x = 0; |
21 point_.y = 0; | 21 point_.y = 0; |
22 } | 22 } |
23 | 23 |
24 /// A constructor accepting two int32_t values for x and y and converting | 24 /// A constructor accepting two int32_t values for x and y and converting |
25 /// them to a Point. | 25 /// them to a Point. |
26 /// @param[in] in_x An int32_t value representing a horizontal coordinate | 26 /// @param[in] in_x An int32_t value representing a horizontal coordinate |
27 /// of a point, starting with 0 as the left-most coordinate. | 27 /// of a point, starting with 0 as the left-most coordinate. |
28 /// @param[in] in_y An int32_t value representing a vertical coordinate | 28 /// @param[in] in_y An int32_t value representing a vertical coordinate |
29 /// of a point, starting with 0 as the top-most coordinate. | 29 /// of a point, starting with 0 as the top-most coordinate. |
30 Point(int32_t in_x, int32_t in_y) { | 30 Point(int32_t in_x, int32_t in_y) { |
31 point_.x = in_x; | 31 point_.x = in_x; |
32 point_.y = in_y; | 32 point_.y = in_y; |
33 } | 33 } |
34 | 34 |
35 /// A constructor accepting a pointer to a PP_Point and converting the | 35 /// A constructor accepting a pointer to a PP_Point and converting the |
36 /// PP_Point to a Point. This is an implicit conversion constructor. | 36 /// PP_Point to a Point. This is an implicit conversion constructor. |
37 /// @param[in] point A pointer to a PP_Point. | 37 /// @param[in] point A pointer to a PP_Point. |
dmichael (off chromium)
2011/07/01 20:04:19
This should just say 'A PP_Point' I think.
| |
38 Point(const PP_Point& point) { // Implicit. | 38 Point(const PP_Point& point) { // Implicit. |
39 point_.x = point.x; | 39 point_.x = point.x; |
40 point_.y = point.y; | 40 point_.y = point.y; |
41 } | 41 } |
42 /// Destructor. | 42 |
43 ~Point() { | 43 /// Destructor. |
44 ~Point() { | |
44 } | 45 } |
45 | 46 |
46 /// A function allowing implicit conversion of a Point to a PP_Point. | 47 /// A function allowing implicit conversion of a Point to a PP_Point. |
47 /// @return A Point. | 48 /// @return A Point. |
48 operator PP_Point() const { | 49 operator PP_Point() const { |
49 return point_; | 50 return point_; |
50 } | 51 } |
51 | 52 |
52 /// Getter function for returning the internal PP_Point struct. | 53 /// Getter function for returning the internal PP_Point struct. |
53 /// @return A const reference to the internal PP_Point struct. | 54 /// @return A const reference to the internal PP_Point struct. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 point_.x = other.point_.x; | 126 point_.x = other.point_.x; |
126 point_.y = other.point_.y; | 127 point_.y = other.point_.y; |
127 other.point_.x = x; | 128 other.point_.x = x; |
128 other.point_.y = y; | 129 other.point_.y = y; |
129 } | 130 } |
130 | 131 |
131 private: | 132 private: |
132 PP_Point point_; | 133 PP_Point point_; |
133 }; | 134 }; |
134 | 135 |
136 /// A 2 dimensional floating-point point with 0,0 being the upper-left starting | |
137 /// coordinate. | |
138 class FloatPoint { | |
139 public: | |
140 /// A constructor for a point at 0,0. | |
141 FloatPoint() { | |
142 float_point_.x = 0.0f; | |
143 float_point_.y = 0.0f; | |
144 } | |
145 | |
146 /// A constructor accepting two values for x and y and converting / them to a | |
dmichael (off chromium)
2011/07/01 20:04:19
nit: extra '/' after converting, and again at 149
| |
147 /// FloatPoint. | |
148 /// | |
149 /// @param[in] in_x An value representing a horizontal coordinate / of a | |
150 /// point, starting with 0 as the left-most coordinate. | |
151 /// | |
152 /// @param[in] in_y An value representing a vertical coordinate / of a point, | |
153 /// starting with 0 as the top-most coordinate. | |
154 FloatPoint(float in_x, float in_y) { | |
155 float_point_.x = in_x; | |
156 float_point_.y = in_y; | |
157 } | |
158 | |
159 /// A constructor accepting a pointer to a PP_FloatPoint and converting the | |
160 /// PP_Point to a Point. This is an implicit conversion constructor. | |
161 /// @param[in] point A pointer to a PP_Point. | |
dmichael (off chromium)
2011/07/01 20:04:19
Copy/paste error duplication :-) I would just say
| |
162 FloatPoint(const PP_FloatPoint& point) { // Implicit. | |
163 float_point_.x = point.x; | |
164 float_point_.y = point.y; | |
165 } | |
166 /// Destructor. | |
167 ~FloatPoint() { | |
168 } | |
169 | |
170 /// A function allowing implicit conversion of a FloatPoint to a | |
171 /// PP_FloatPoint. | |
172 operator PP_FloatPoint() const { | |
173 return float_point_; | |
174 } | |
175 | |
176 /// Getter function for returning the internal PP_FloatPoint struct. | |
177 /// @return A const reference to the internal PP_FloatPoint struct. | |
178 const PP_FloatPoint& pp_float_point() const { | |
179 return float_point_; | |
180 } | |
181 | |
182 /// Getter function for returning the internal PP_Point struct. | |
183 /// @return A mutable reference to the PP_Point struct. | |
184 PP_FloatPoint& pp_float_point() { | |
185 return float_point_; | |
186 } | |
187 | |
188 /// Getter function for returning the value of x. | |
189 /// @return The value of x for this Point. | |
190 float x() const { return float_point_.x; } | |
191 | |
192 /// Setter function for setting the value of x. | |
193 /// @param[in] in_x A new x value. | |
194 void set_x(float in_x) { | |
195 float_point_.x = in_x; | |
196 } | |
197 | |
198 /// Getter function for returning the value of y. | |
199 /// @return The value of y for this Point. | |
200 float y() const { return float_point_.y; } | |
201 | |
202 /// Setter function for setting the value of y. | |
203 /// @param[in] in_y A new y value. | |
204 void set_y(float in_y) { | |
205 float_point_.y = in_y; | |
206 } | |
207 | |
208 /// Adds two Points (this and other) together by adding their x values and | |
209 /// y values. | |
210 /// @param[in] other A Point. | |
211 /// @return A new Point containing the result. | |
212 FloatPoint operator+(const FloatPoint& other) const { | |
213 return FloatPoint(x() + other.x(), y() + other.y()); | |
214 } | |
215 | |
216 /// Subtracts one Point from another Point by subtracting their x values | |
217 /// and y values. Returnes a new point with the result. | |
218 /// @param[in] other A FloatPoint. | |
219 /// @return A new Point containing the result. | |
220 FloatPoint operator-(const FloatPoint& other) const { | |
221 return FloatPoint(x() - other.x(), y() - other.y()); | |
222 } | |
223 | |
224 /// Adds two Points (this and other) together by adding their x and y | |
225 /// values. Returns this point as the result. | |
226 /// @param[in] other A Point. | |
227 /// @return This Point containing the result. | |
228 FloatPoint& operator+=(const FloatPoint& other) { | |
229 float_point_.x += other.x(); | |
230 float_point_.y += other.y(); | |
231 return *this; | |
232 } | |
233 | |
234 /// Subtracts one Point from another Point by subtracting their x values | |
235 /// and y values. Returns this point as the result. | |
236 /// @param[in] other A Point. | |
237 /// @return This Point containing the result. | |
238 FloatPoint& operator-=(const FloatPoint& other) { | |
239 float_point_.x -= other.x(); | |
240 float_point_.y -= other.y(); | |
241 return *this; | |
242 } | |
243 | |
244 /// Swaps the coordinates of two Points. | |
245 /// @param[in] other A Point. | |
246 void swap(FloatPoint& other) { | |
247 float x = float_point_.x; | |
248 float y = float_point_.y; | |
249 float_point_.x = other.float_point_.x; | |
250 float_point_.y = other.float_point_.y; | |
251 other.float_point_.x = x; | |
252 other.float_point_.y = y; | |
253 } | |
254 | |
255 private: | |
256 PP_FloatPoint float_point_; | |
257 }; | |
258 | |
135 } // namespace pp | 259 } // namespace pp |
136 | 260 |
137 /// Determines whether the x and y values of two Points are equal. | 261 /// Determines whether the x and y values of two Points are equal. |
138 /// @param[in] lhs The Point on the left-hand side of the equation. | 262 /// @param[in] lhs The Point on the left-hand side of the equation. |
139 /// @param[in] rhs The Point on the right-hand side of the equation. | 263 /// @param[in] rhs The Point on the right-hand side of the equation. |
140 /// @return true if they are equal, false if unequal. | 264 /// @return true if they are equal, false if unequal. |
141 inline bool operator==(const pp::Point& lhs, const pp::Point& rhs) { | 265 inline bool operator==(const pp::Point& lhs, const pp::Point& rhs) { |
142 return lhs.x() == rhs.x() && lhs.y() == rhs.y(); | 266 return lhs.x() == rhs.x() && lhs.y() == rhs.y(); |
143 } | 267 } |
144 | 268 |
145 /// Determines whether two Points have different coordinates. | 269 /// Determines whether two Points have different coordinates. |
146 /// @param[in] lhs The Point on the left-hand side of the equation. | 270 /// @param[in] lhs The Point on the left-hand side of the equation. |
147 /// @param[in] rhs The Point on the right-hand side of the equation. | 271 /// @param[in] rhs The Point on the right-hand side of the equation. |
148 /// @return true if the coordinates of lhs are equal to the coordinates | 272 /// @return true if the coordinates of lhs are equal to the coordinates |
149 /// of rhs, otherwise false. | 273 /// of rhs, otherwise false. |
150 inline bool operator!=(const pp::Point& lhs, const pp::Point& rhs) { | 274 inline bool operator!=(const pp::Point& lhs, const pp::Point& rhs) { |
151 return !(lhs == rhs); | 275 return !(lhs == rhs); |
152 } | 276 } |
153 | 277 |
278 /// Determines whether the x and y values of two FloatPoints are equal. | |
279 /// @param[in] lhs The Point on the left-hand side of the equation. | |
280 /// @param[in] rhs The Point on the right-hand side of the equation. | |
281 /// @return true if they are equal, false if unequal. | |
282 inline bool operator==(const pp::FloatPoint& lhs, const pp::FloatPoint& rhs) { | |
283 return lhs.x() == rhs.x() && lhs.y() == rhs.y(); | |
284 } | |
285 | |
286 /// Determines whether two Points have different coordinates. | |
287 /// @param[in] lhs The Point on the left-hand side of the equation. | |
288 /// @param[in] rhs The Point on the right-hand side of the equation. | |
289 /// @return true if the coordinates of lhs are equal to the coordinates | |
290 /// of rhs, otherwise false. | |
291 inline bool operator!=(const pp::FloatPoint& lhs, const pp::FloatPoint& rhs) { | |
292 return !(lhs == rhs); | |
293 } | |
294 | |
154 #endif // PPAPI_CPP_POINT_H_ | 295 #endif // PPAPI_CPP_POINT_H_ |
OLD | NEW |