point3_f.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (c) 2012 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.
  4. #include "ui/gfx/geometry/point3_f.h"
  5. #include "base/strings/stringprintf.h"
  6. namespace gfx {
  7. std::string Point3F::ToString() const {
  8. return base::StringPrintf("%g,%g,%g", x_, y_, z_);
  9. }
  10. Point3F operator+(const Point3F& lhs, const Vector3dF& rhs) {
  11. float x = lhs.x() + rhs.x();
  12. float y = lhs.y() + rhs.y();
  13. float z = lhs.z() + rhs.z();
  14. return Point3F(x, y, z);
  15. }
  16. // Subtract a vector from a point, producing a new point offset by the vector's
  17. // inverse.
  18. Point3F operator-(const Point3F& lhs, const Vector3dF& rhs) {
  19. float x = lhs.x() - rhs.x();
  20. float y = lhs.y() - rhs.y();
  21. float z = lhs.z() - rhs.z();
  22. return Point3F(x, y, z);
  23. }
  24. // Subtract one point from another, producing a vector that represents the
  25. // distances between the two points along each axis.
  26. Vector3dF operator-(const Point3F& lhs, const Point3F& rhs) {
  27. float x = lhs.x() - rhs.x();
  28. float y = lhs.y() - rhs.y();
  29. float z = lhs.z() - rhs.z();
  30. return Vector3dF(x, y, z);
  31. }
  32. } // namespace gfx