Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef UI_GFX_POINT3_H_ | |
| 6 #define UI_GFX_POINT3_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <cmath> | |
| 10 | |
| 11 #include "ui/gfx/point.h" | |
| 12 | |
| 13 namespace gfx { | |
| 14 | |
| 15 // A point has an x, y and z coordinate. | |
| 16 class Point3f { | |
| 17 public: | |
| 18 Point3f() : x_(0), y_(0), z_(0) | |
| 19 {} | |
|
sky
2011/06/17 18:43:41
Either { on the previous line, or {} on the previo
| |
| 20 | |
| 21 Point3f(float x, float y, float z) : x_(x), y_(y), z_(z) | |
| 22 {} | |
| 23 | |
| 24 Point3f(const Point& point) : x_(point.x()), y_(point.y()), z_(0) | |
| 25 {} | |
| 26 | |
| 27 Point3f(const Point3f& other) : x_(other.x_), y_(other.y_), z_(other.z_) | |
|
sky
2011/06/17 18:43:41
These aren't going to fit when you move { onto 27,
| |
| 28 {} | |
| 29 | |
| 30 ~Point3f() {} | |
| 31 | |
| 32 Point3f& operator=(const Point3f& other) { | |
|
sky
2011/06/17 18:43:41
Same thing on this, can't you use the one generate
| |
| 33 x_ = other.x_; | |
| 34 y_ = other.y_; | |
| 35 z_ = other.z_; | |
| 36 return *this; | |
| 37 } | |
| 38 | |
| 39 float x() const { return x_; } | |
| 40 float y() const { return y_; } | |
| 41 float z() const { return z_; } | |
| 42 | |
| 43 void set_x(float x) { x_ = x; } | |
| 44 void set_y(float y) { y_ = y; } | |
| 45 void set_z(float z) { z_ = z; } | |
| 46 | |
| 47 void SetPoint(float x, float y, float z) { | |
| 48 x_ = x; | |
| 49 y_ = y; | |
| 50 z_ = z; | |
| 51 } | |
| 52 | |
| 53 // Returns the squared euclidean distance between two points. | |
| 54 float SquaredDistanceTo(const Point3f& other) const { | |
| 55 float dx = x_ - other.x_; | |
| 56 float dy = y_ - other.y_; | |
| 57 float dz = z_ - other.z_; | |
| 58 return dx * dx + dy * dy + dz * dz; | |
| 59 } | |
| 60 | |
| 61 Point AsPoint() { | |
|
sky
2011/06/17 18:43:41
const
| |
| 62 return Point(static_cast<int>(std::floor(x_)), | |
| 63 static_cast<int>(std::floor(y_))); | |
| 64 } | |
| 65 | |
| 66 private: | |
| 67 float x_; | |
| 68 float y_; | |
| 69 float z_; | |
| 70 | |
| 71 // copy/assign are allowed. | |
| 72 }; | |
| 73 | |
| 74 } // namespace gfx | |
| 75 | |
| 76 #endif // UI_GFX_POINT3_H_ | |
| OLD | NEW |