Chromium Code Reviews| Index: ui/gfx/point3.h |
| diff --git a/ui/gfx/point3.h b/ui/gfx/point3.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bd1ad59c413bbbaf74206d9acb17f28fba051b9c |
| --- /dev/null |
| +++ b/ui/gfx/point3.h |
| @@ -0,0 +1,95 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef UI_GFX_POINT3_H_ |
| +#define UI_GFX_POINT3_H_ |
| +#pragma once |
| + |
| +#include <cmath> |
| + |
| +#include "base/basictypes.h" |
| +#include "ui/gfx/point.h" |
| + |
| +namespace gfx { |
| + |
| +// A point has an x, y and z coordinate. |
| +template <typename T> |
| +class Point3 { |
| + public: |
| + Point3() |
| + : x_(0), y_(0), z_(0) |
|
sky
2011/06/17 16:38:23
Move the member initializer list to 20.
|
| + {} |
| + |
| + Point3(const T& x, const T& y, const T& z) |
|
sky
2011/06/17 16:38:23
We generally don't use references for primitive ty
|
| + : x_(x), y_(y), z_(z) |
|
sky
2011/06/17 16:38:23
If you can't fit the constructor and member initia
|
| + {} |
| + |
| + Point3(const Point& point) |
| + : x_(point.x()) |
|
sky
2011/06/17 16:38:23
trailing commas, not leading. And 4 space indent.
|
| + , y_(point.y()) |
| + , z_(0) |
| + {} |
| + |
| + ~Point3() {} |
| + |
| + T x() { return x_; } |
|
sky
2011/06/17 16:38:23
These functions should be const.
|
| + T y() { return y_; } |
| + T z() { return z_; } |
| + |
| + void set_x(const T& x) { x_ = x; } |
| + void set_y(const T& y) { y_ = y; } |
| + void set_z(const T& z) { z_ = z; } |
| + |
| + void SetPoint(const T& x, const T& y, const T& z) { |
|
sky
2011/06/17 16:38:23
no reference.
|
| + x_ = x; |
| + y_ = y; |
| + z_ = z; |
| + } |
| + |
| + void SetPoint(const Point3<T>& other) { |
| + x_ = other.x_; |
| + y_ = other.y_; |
| + z_ = other.z_; |
| + } |
| + |
| + void Add(const Point3<T>& other) { |
| + x_ += other.x_; |
| + y_ += other.y_; |
| + z_ += other.z_; |
| + } |
| + |
| + void Multiply(const T& s) { |
|
sky
2011/06/17 16:38:23
no reference.
|
| + x_ *= s; |
| + y_ *= s; |
| + z_ *= s; |
| + } |
| + |
| + T Dist2(const Point3<T>& other) const { |
|
sky
2011/06/17 16:38:23
Add a description as what this does isn't obvious
wjmaclean
2011/06/17 16:58:07
Rename "DistanceSquared"? "NormSquared"? (Or use "
|
| + T dx = x_ - other.x_; |
| + T dy = y_ - other.y_; |
| + T dz = z_ - other.z_; |
| + return dx * dx + dy * dy + dz * dz; |
| + } |
| + |
| + Point AsPoint() { |
| + return Point( |
| + static_cast<int>(std::floor(x_)), |
|
sky
2011/06/17 16:38:23
77/78 should be 4 space indented. Or better yet, a
|
| + static_cast<int>(std::floor(y_))); |
| + } |
| + |
| + private: |
| + T x_; |
| + T y_; |
| + T z_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Point3); |
|
sky
2011/06/17 16:38:23
I know I mentioned not enabling assignment operato
|
| +}; |
| + |
| +// Could point this at Skia and we'd be ok. |
| +typedef Point3<float> Point3f; |
| +typedef Point3<double> Point3d; |
| + |
| +} // namespace gfx |
| + |
| +#endif // UI_GFX_POINT3_H_ |