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 UI_GFX_POINT3_F_H_
6 #define UI_GFX_POINT3_F_H_
10 #include "ui/base/ui_export.h"
11 #include "ui/gfx/point_f.h"
12 #include "ui/gfx/vector3d_f.h"
16 // A point has an x, y and z coordinate.
17 class UI_EXPORT Point3F
{
19 Point3F() : x_(0), y_(0), z_(0) {}
21 Point3F(float x
, float y
, float z
) : x_(x
), y_(y
), z_(z
) {}
23 explicit Point3F(const PointF
& point
) : x_(point
.x()), y_(point
.y()), z_(0) {}
27 float x() const { return x_
; }
28 float y() const { return y_
; }
29 float z() const { return z_
; }
31 void set_x(float x
) { x_
= x
; }
32 void set_y(float y
) { y_
= y
; }
33 void set_z(float z
) { z_
= z
; }
35 void SetPoint(float x
, float y
, float z
) {
41 // Returns the squared euclidean distance between two points.
42 float SquaredDistanceTo(const Point3F
& other
) const {
43 float dx
= x_
- other
.x_
;
44 float dy
= y_
- other
.y_
;
45 float dz
= z_
- other
.z_
;
46 return dx
* dx
+ dy
* dy
+ dz
* dz
;
49 PointF
AsPointF() const { return PointF(x_
, y_
); }
51 // Returns a string representation of 3d point.
52 std::string
ToString() const;
59 // copy/assign are allowed.
62 inline bool operator==(const Point3F
& lhs
, const Point3F
& rhs
) {
63 return lhs
.x() == rhs
.x() && lhs
.y() == rhs
.y() && lhs
.z() == rhs
.z();
66 inline bool operator!=(const Point3F
& lhs
, const Point3F
& rhs
) {
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
);
73 // Subtract a vector from a point, producing a new point offset by the vector's
75 UI_EXPORT Point3F
operator-(const Point3F
& lhs
, const Vector3dF
& rhs
);
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
);
81 inline Point3F
PointAtOffsetFromOrigin(const Vector3dF
& offset
) {
82 return Point3F(offset
.x(), offset
.y(), offset
.z());
87 #endif // UI_GFX_POINT3_F_H_