Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_BASE_MATH_UTIL_H_ | 5 #ifndef CC_BASE_MATH_UTIL_H_ |
| 6 #define CC_BASE_MATH_UTIL_H_ | 6 #define CC_BASE_MATH_UTIL_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 namespace cc { | 29 namespace cc { |
| 30 | 30 |
| 31 struct HomogeneousCoordinate { | 31 struct HomogeneousCoordinate { |
| 32 HomogeneousCoordinate(SkMScalar x, SkMScalar y, SkMScalar z, SkMScalar w) { | 32 HomogeneousCoordinate(SkMScalar x, SkMScalar y, SkMScalar z, SkMScalar w) { |
| 33 vec[0] = x; | 33 vec[0] = x; |
| 34 vec[1] = y; | 34 vec[1] = y; |
| 35 vec[2] = z; | 35 vec[2] = z; |
| 36 vec[3] = w; | 36 vec[3] = w; |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool ShouldBeClipped() const { return w() <= 0.0; } | 39 bool ShouldBeClipped() const { return w() <= 0.0; } |
|
danakj
2013/09/09 17:57:45
We're going to be left in this weird limbo world w
| |
| 40 | 40 |
| 41 gfx::PointF CartesianPoint2d() const { | 41 gfx::PointF CartesianPoint2d() const { |
| 42 if (w() == 1.0) | 42 if (w() == 1.0) |
| 43 return gfx::PointF(x(), y()); | 43 return gfx::PointF(x(), y()); |
| 44 | 44 |
| 45 // For now, because this code is used privately only by MathUtil, it should | 45 // For now, because this code is used privately only by MathUtil, it should |
| 46 // never be called when w == 0, and we do not yet need to handle that case. | 46 // never be called when w == 0, and we do not yet need to handle that case. |
| 47 DCHECK(w()); | 47 DCHECK(w()); |
| 48 double inv_w = 1.0 / w(); | 48 SkMScalar inv_w = 1.0 / w(); |
| 49 return gfx::PointF(x() * inv_w, y() * inv_w); | 49 return gfx::PointF(x() * inv_w, y() * inv_w); |
| 50 } | 50 } |
| 51 | 51 |
| 52 gfx::Point3F CartesianPoint3d() const { | 52 gfx::Point3F CartesianPoint3d() const { |
| 53 if (w() == 1) | 53 if (w() == 1) |
| 54 return gfx::Point3F(x(), y(), z()); | 54 return gfx::Point3F(x(), y(), z()); |
| 55 | 55 |
| 56 // For now, because this code is used privately only by MathUtil, it should | 56 // For now, because this code is used privately only by MathUtil, it should |
| 57 // never be called when w == 0, and we do not yet need to handle that case. | 57 // never be called when w == 0, and we do not yet need to handle that case. |
| 58 DCHECK(w()); | 58 DCHECK(w()); |
| 59 double inv_w = 1.0 / w(); | 59 SkMScalar inv_w = 1.0 / w(); |
| 60 return gfx::Point3F(x() * inv_w, y() * inv_w, z() * inv_w); | 60 return gfx::Point3F(x() * inv_w, y() * inv_w, z() * inv_w); |
| 61 } | 61 } |
| 62 | 62 |
| 63 SkMScalar x() const { return vec[0]; } | 63 SkMScalar x() const { return vec[0]; } |
| 64 SkMScalar y() const { return vec[1]; } | 64 SkMScalar y() const { return vec[1]; } |
| 65 SkMScalar z() const { return vec[2]; } | 65 SkMScalar z() const { return vec[2]; } |
| 66 SkMScalar w() const { return vec[3]; } | 66 SkMScalar w() const { return vec[3]; } |
| 67 | 67 |
| 68 SkMScalar vec[4]; | 68 SkMScalar vec[4]; |
| 69 }; | 69 }; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 | 175 |
| 176 // Returns a base::Value representation of the floating point value. | 176 // Returns a base::Value representation of the floating point value. |
| 177 // If the value is inf, returns max double/float representation. | 177 // If the value is inf, returns max double/float representation. |
| 178 static scoped_ptr<base::Value> AsValueSafely(double value); | 178 static scoped_ptr<base::Value> AsValueSafely(double value); |
| 179 static scoped_ptr<base::Value> AsValueSafely(float value); | 179 static scoped_ptr<base::Value> AsValueSafely(float value); |
| 180 }; | 180 }; |
| 181 | 181 |
| 182 } // namespace cc | 182 } // namespace cc |
| 183 | 183 |
| 184 #endif // CC_BASE_MATH_UTIL_H_ | 184 #endif // CC_BASE_MATH_UTIL_H_ |
| OLD | NEW |