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 UI_GFX_POINT3_F_H_ | 5 #ifndef UI_GFX_POINT3_F_H_ |
6 #define UI_GFX_POINT3_F_H_ | 6 #define UI_GFX_POINT3_F_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
| 10 #include "ui/base/ui_export.h" |
8 #include "ui/gfx/point_f.h" | 11 #include "ui/gfx/point_f.h" |
| 12 #include "ui/gfx/vector3d_f.h" |
9 | 13 |
10 namespace gfx { | 14 namespace gfx { |
11 | 15 |
12 // A point has an x, y and z coordinate. | 16 // A point has an x, y and z coordinate. |
13 class Point3F { | 17 class UI_EXPORT Point3F { |
14 public: | 18 public: |
15 Point3F() : x_(0), y_(0), z_(0) {} | 19 Point3F() : x_(0), y_(0), z_(0) {} |
16 | 20 |
17 Point3F(float x, float y, float z) : x_(x), y_(y), z_(z) {} | 21 Point3F(float x, float y, float z) : x_(x), y_(y), z_(z) {} |
18 | 22 |
19 explicit Point3F(const PointF& point) : x_(point.x()), y_(point.y()), z_(0) {} | 23 explicit Point3F(const PointF& point) : x_(point.x()), y_(point.y()), z_(0) {} |
20 | 24 |
21 ~Point3F() {} | 25 ~Point3F() {} |
22 | 26 |
23 float x() const { return x_; } | 27 float x() const { return x_; } |
(...skipping 13 matching lines...) Expand all Loading... |
37 // Returns the squared euclidean distance between two points. | 41 // Returns the squared euclidean distance between two points. |
38 float SquaredDistanceTo(const Point3F& other) const { | 42 float SquaredDistanceTo(const Point3F& other) const { |
39 float dx = x_ - other.x_; | 43 float dx = x_ - other.x_; |
40 float dy = y_ - other.y_; | 44 float dy = y_ - other.y_; |
41 float dz = z_ - other.z_; | 45 float dz = z_ - other.z_; |
42 return dx * dx + dy * dy + dz * dz; | 46 return dx * dx + dy * dy + dz * dz; |
43 } | 47 } |
44 | 48 |
45 PointF AsPointF() const { return PointF(x_, y_); } | 49 PointF AsPointF() const { return PointF(x_, y_); } |
46 | 50 |
| 51 // Returns a string representation of 3d point. |
| 52 std::string ToString() const; |
| 53 |
47 private: | 54 private: |
48 float x_; | 55 float x_; |
49 float y_; | 56 float y_; |
50 float z_; | 57 float z_; |
51 | 58 |
52 // copy/assign are allowed. | 59 // copy/assign are allowed. |
53 }; | 60 }; |
54 | 61 |
| 62 inline bool operator==(const Point3F& lhs, const Point3F& rhs) { |
| 63 return lhs.x() == rhs.x() && lhs.y() == rhs.y() && lhs.z() == rhs.z(); |
| 64 } |
| 65 |
| 66 inline bool operator!=(const Point3F& lhs, const Point3F& rhs) { |
| 67 return !(lhs == rhs); |
| 68 } |
| 69 |
| 70 // Add a vector to a point, producing a new point offset by the vector. |
| 71 UI_EXPORT Point3F operator+(const Point3F& lhs, const Vector3dF& rhs); |
| 72 |
| 73 // Subtract a vector from a point, producing a new point offset by the vector's |
| 74 // inverse. |
| 75 UI_EXPORT Point3F operator-(const Point3F& lhs, const Vector3dF& rhs); |
| 76 |
| 77 // Subtract one point from another, producing a vector that represents the |
| 78 // distances between the two points along each axis. |
| 79 UI_EXPORT Vector3dF operator-(const Point3F& lhs, const Point3F& rhs); |
| 80 |
| 81 inline Point3F PointAtOffsetFromOrigin(const Vector3dF& offset) { |
| 82 return Point3F(offset.x(), offset.y(), offset.z()); |
| 83 } |
| 84 |
55 } // namespace gfx | 85 } // namespace gfx |
56 | 86 |
57 #endif // UI_GFX_POINT3_F_H_ | 87 #endif // UI_GFX_POINT3_F_H_ |
OLD | NEW |