1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker
5*635a8641SAndroid Build Coastguard Worker #include "ui/gfx/geometry/point3_f.h"
6*635a8641SAndroid Build Coastguard Worker
7*635a8641SAndroid Build Coastguard Worker #include "base/strings/stringprintf.h"
8*635a8641SAndroid Build Coastguard Worker
9*635a8641SAndroid Build Coastguard Worker namespace gfx {
10*635a8641SAndroid Build Coastguard Worker
ToString() const11*635a8641SAndroid Build Coastguard Worker std::string Point3F::ToString() const {
12*635a8641SAndroid Build Coastguard Worker return base::StringPrintf("%f,%f,%f", x_, y_, z_);
13*635a8641SAndroid Build Coastguard Worker }
14*635a8641SAndroid Build Coastguard Worker
operator +(const Point3F & lhs,const Vector3dF & rhs)15*635a8641SAndroid Build Coastguard Worker Point3F operator+(const Point3F& lhs, const Vector3dF& rhs) {
16*635a8641SAndroid Build Coastguard Worker float x = lhs.x() + rhs.x();
17*635a8641SAndroid Build Coastguard Worker float y = lhs.y() + rhs.y();
18*635a8641SAndroid Build Coastguard Worker float z = lhs.z() + rhs.z();
19*635a8641SAndroid Build Coastguard Worker return Point3F(x, y, z);
20*635a8641SAndroid Build Coastguard Worker }
21*635a8641SAndroid Build Coastguard Worker
22*635a8641SAndroid Build Coastguard Worker // Subtract a vector from a point, producing a new point offset by the vector's
23*635a8641SAndroid Build Coastguard Worker // inverse.
operator -(const Point3F & lhs,const Vector3dF & rhs)24*635a8641SAndroid Build Coastguard Worker Point3F operator-(const Point3F& lhs, const Vector3dF& rhs) {
25*635a8641SAndroid Build Coastguard Worker float x = lhs.x() - rhs.x();
26*635a8641SAndroid Build Coastguard Worker float y = lhs.y() - rhs.y();
27*635a8641SAndroid Build Coastguard Worker float z = lhs.z() - rhs.z();
28*635a8641SAndroid Build Coastguard Worker return Point3F(x, y, z);
29*635a8641SAndroid Build Coastguard Worker }
30*635a8641SAndroid Build Coastguard Worker
31*635a8641SAndroid Build Coastguard Worker // Subtract one point from another, producing a vector that represents the
32*635a8641SAndroid Build Coastguard Worker // distances between the two points along each axis.
operator -(const Point3F & lhs,const Point3F & rhs)33*635a8641SAndroid Build Coastguard Worker Vector3dF operator-(const Point3F& lhs, const Point3F& rhs) {
34*635a8641SAndroid Build Coastguard Worker float x = lhs.x() - rhs.x();
35*635a8641SAndroid Build Coastguard Worker float y = lhs.y() - rhs.y();
36*635a8641SAndroid Build Coastguard Worker float z = lhs.z() - rhs.z();
37*635a8641SAndroid Build Coastguard Worker return Vector3dF(x, y, z);
38*635a8641SAndroid Build Coastguard Worker }
39*635a8641SAndroid Build Coastguard Worker
40*635a8641SAndroid Build Coastguard Worker } // namespace gfx
41