Performance histograms for extension content verification
[chromium-blink-merge.git] / ui / gfx / geometry / point3_f.h
blob45bae6e8d328638da2c3bfac693f5855110bbf28
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_
8 #include <string>
10 #include "ui/gfx/geometry/point_f.h"
11 #include "ui/gfx/geometry/vector3d_f.h"
12 #include "ui/gfx/gfx_export.h"
14 namespace gfx {
16 // A point has an x, y and z coordinate.
17 class GFX_EXPORT Point3F {
18 public:
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) {}
25 ~Point3F() {}
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) {
44 x_ = x;
45 y_ = y;
46 z_ = z;
49 // Offset the point by the given vector.
50 void operator+=(const Vector3dF& v) {
51 x_ += v.x();
52 y_ += v.y();
53 z_ += v.z();
56 // Offset the point by the given vector's inverse.
57 void operator-=(const Vector3dF& v) {
58 x_ -= v.x();
59 y_ -= v.y();
60 z_ -= v.z();
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;
76 private:
77 float x_;
78 float y_;
79 float z_;
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) {
89 return !(lhs == 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
96 // inverse.
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,
108 float x_scale,
109 float y_scale,
110 float z_scale) {
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);
118 } // namespace gfx
120 #endif // UI_GFX_GEOMETRY_POINT3_F_H_