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_GEOMETRY_POINT3_F_H_
6 #define UI_GFX_GEOMETRY_POINT3_F_H_
10 #include "ui/gfx/geometry/point_f.h"
11 #include "ui/gfx/geometry/vector3d_f.h"
12 #include "ui/gfx/gfx_export.h"
16 // A point has an x, y and z coordinate.
17 class GFX_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 void Scale(float scale
) {
28 Scale(scale
, scale
, scale
);
31 void Scale(float x_scale
, float y_scale
, float z_scale
) {
32 SetPoint(x() * x_scale
, y() * y_scale
, z() * z_scale
);
35 float x() const { return x_
; }
36 float y() const { return y_
; }
37 float z() const { return z_
; }
39 void set_x(float x
) { x_
= x
; }
40 void set_y(float y
) { y_
= y
; }
41 void set_z(float z
) { z_
= z
; }
43 void SetPoint(float x
, float y
, float z
) {
49 // Offset the point by the given vector.
50 void operator+=(const Vector3dF
& v
) {
56 // Offset the point by the given vector's inverse.
57 void operator-=(const Vector3dF
& v
) {
63 // Returns the squared euclidean distance between two points.
64 float SquaredDistanceTo(const Point3F
& other
) const {
65 float dx
= x_
- other
.x_
;
66 float dy
= y_
- other
.y_
;
67 float dz
= z_
- other
.z_
;
68 return dx
* dx
+ dy
* dy
+ dz
* dz
;
71 PointF
AsPointF() const { return PointF(x_
, y_
); }
73 // Returns a string representation of 3d point.
74 std::string
ToString() const;
81 // copy/assign are allowed.
84 inline bool operator==(const Point3F
& lhs
, const Point3F
& rhs
) {
85 return lhs
.x() == rhs
.x() && lhs
.y() == rhs
.y() && lhs
.z() == rhs
.z();
88 inline bool operator!=(const Point3F
& lhs
, const Point3F
& rhs
) {
92 // Add a vector to a point, producing a new point offset by the vector.
93 GFX_EXPORT Point3F
operator+(const Point3F
& lhs
, const Vector3dF
& rhs
);
95 // Subtract a vector from a point, producing a new point offset by the vector's
97 GFX_EXPORT Point3F
operator-(const Point3F
& lhs
, const Vector3dF
& rhs
);
99 // Subtract one point from another, producing a vector that represents the
100 // distances between the two points along each axis.
101 GFX_EXPORT Vector3dF
operator-(const Point3F
& lhs
, const Point3F
& rhs
);
103 inline Point3F
PointAtOffsetFromOrigin(const Vector3dF
& offset
) {
104 return Point3F(offset
.x(), offset
.y(), offset
.z());
107 inline Point3F
ScalePoint(const Point3F
& p
,
111 return Point3F(p
.x() * x_scale
, p
.y() * y_scale
, p
.z() * z_scale
);
114 inline Point3F
ScalePoint(const Point3F
& p
, float scale
) {
115 return ScalePoint(p
, scale
, scale
, scale
);
120 #endif // UI_GFX_GEOMETRY_POINT3_F_H_