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..70e68b6b880f0a7f5f0589d981722d27ae17b01f |
| --- /dev/null |
| +++ b/ui/gfx/point3.h |
| @@ -0,0 +1,94 @@ |
| +// 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 <algorithm> |
| +#include <cmath> |
| +#include "ui/gfx/point.h" |
|
sky
2011/06/16 23:06:56
newline between 10 and 11.
|
| + |
| +namespace gfx { |
| + |
| +// A point has an x, y and z coordinate. |
| +template <typename T> |
|
sky
2011/06/16 23:06:56
Do we really need a template here? Do we plan on u
|
| +class Point3 { |
| + public: |
| + Point3(); |
| + |
| + Point3(T x, T y, T z) { |
| + data_[0] = x; |
|
sky
2011/06/16 23:06:56
Use member initializer list.
|
| + data_[1] = y; |
| + data_[2] = z; |
| + } |
| + |
| + Point3(const Point3<T>& other) { |
|
sky
2011/06/16 23:06:56
See style guide, we generally don't use copy const
|
| + memcpy(data_, other.data_, sizeof(T)*3); |
| + } |
| + |
| + Point3(const Point& other) { |
| + data_[0] = other.x(); |
| + data_[1] = other.y(); |
| + data_[2] = 0; |
| + } |
| + |
| + ~Point3() {} |
| + |
| + void swap(Point3<T>& other) { |
| + std::swap(data_, other.data_); |
| + } |
| + |
| + Point3<T>& operator=(Point3<T> other) { |
| + swap(other); |
| + return *this; |
| + } |
| + |
| + const T& operator[] (int i) const { return data_[i]; } |
| + T& operator[] (int i) { return data_[i]; } |
| + |
| + Point3<T> operator+ (const Point3<T>& other) { |
| + return Point3<T>( |
| + data_[0] + other[0], |
| + data_[1] + other[1], |
| + data_[2] + other[2]); |
| + } |
| + |
| + Point3<T> operator- (const Point3<T>& other) { |
| + return Point3<T>( |
| + data_[0] - other[0], |
| + data_[1] - other[1], |
| + data_[2] - other[2]); |
| + } |
| + |
| + Point3<T> operator* (const T& s) { |
| + return Point3<T>( |
| + data_[0] * s, |
| + data_[1] * s, |
| + data_[2] * s); |
| + } |
| + |
| + T dist2(const Point3<T>& rhs) const { |
| + return data_[0] * rhs[0] + |
| + data_[1] * rhs[1] + |
| + data_[2] * rhs[2]; |
| + } |
| + |
| + operator Point() { |
| + return Point( |
| + static_cast<int>(std::floor(data_[0])), |
| + static_cast<int>(std::floor(data_[1]))); |
| + } |
| + |
| + private: |
| + T data_[3]; |
| +}; |
| + |
| +// 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_ |