| 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_MATH_UTIL_H_ | 5 #ifndef CC_MATH_UTIL_H_ |
| 6 #define CC_MATH_UTIL_H_ | 6 #define CC_MATH_UTIL_H_ |
| 7 | 7 |
| 8 #include <cmath> |
| 9 |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "cc/cc_export.h" | 12 #include "cc/cc_export.h" |
| 11 #include "ui/gfx/point_f.h" | 13 #include "ui/gfx/point_f.h" |
| 12 #include "ui/gfx/point3_f.h" | 14 #include "ui/gfx/point3_f.h" |
| 13 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
| 14 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" |
| 15 | 17 |
| 16 namespace base { | 18 namespace base { |
| 17 class Value; | 19 class Value; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 static const double PI_DOUBLE; | 76 static const double PI_DOUBLE; |
| 75 static const float PI_FLOAT; | 77 static const float PI_FLOAT; |
| 76 static const double EPSILON; | 78 static const double EPSILON; |
| 77 | 79 |
| 78 static double Deg2Rad(double deg) { return deg * PI_DOUBLE / 180; } | 80 static double Deg2Rad(double deg) { return deg * PI_DOUBLE / 180; } |
| 79 static double Rad2Deg(double rad) { return rad * 180 / PI_DOUBLE; } | 81 static double Rad2Deg(double rad) { return rad * 180 / PI_DOUBLE; } |
| 80 | 82 |
| 81 static float Deg2Rad(float deg) { return deg * PI_FLOAT / 180; } | 83 static float Deg2Rad(float deg) { return deg * PI_FLOAT / 180; } |
| 82 static float Rad2Deg(float rad) { return rad * 180 / PI_FLOAT; } | 84 static float Rad2Deg(float rad) { return rad * 180 / PI_FLOAT; } |
| 83 | 85 |
| 86 static float Round(float f) { return (f > 0.f) ? std::floor(f + 0.5f) : std
::ceil(f - 0.5f); } |
| 87 static double Round(double d) { return (d > 0.0) ? std::floor(d + 0.5) : st
d::ceil(d - 0.5); } |
| 88 |
| 84 // Background: Existing transform code does not do the right thing in | 89 // Background: Existing transform code does not do the right thing in |
| 85 // mapRect / mapQuad / projectQuad when there is a perspective projection th
at causes | 90 // mapRect / mapQuad / projectQuad when there is a perspective projection th
at causes |
| 86 // one of the transformed vertices to go to w < 0. In those cases, it is nec
essary to | 91 // one of the transformed vertices to go to w < 0. In those cases, it is nec
essary to |
| 87 // perform clipping in homogeneous coordinates, after applying the transform
, before | 92 // perform clipping in homogeneous coordinates, after applying the transform
, before |
| 88 // dividing-by-w to convert to cartesian coordinates. | 93 // dividing-by-w to convert to cartesian coordinates. |
| 89 // | 94 // |
| 90 // These functions return the axis-aligned rect that encloses the correctly
clipped, | 95 // These functions return the axis-aligned rect that encloses the correctly
clipped, |
| 91 // transformed polygon. | 96 // transformed polygon. |
| 92 static gfx::Rect mapClippedRect(const gfx::Transform&, const gfx::Rect&); | 97 static gfx::Rect mapClippedRect(const gfx::Transform&, const gfx::Rect&); |
| 93 static gfx::RectF mapClippedRect(const gfx::Transform&, const gfx::RectF&); | 98 static gfx::RectF mapClippedRect(const gfx::Transform&, const gfx::RectF&); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // Returns a base::Value representation of the floating point value. | 132 // Returns a base::Value representation of the floating point value. |
| 128 // If the value is inf, returns max double/float representation. | 133 // If the value is inf, returns max double/float representation. |
| 129 static scoped_ptr<base::Value> asValueSafely(double value); | 134 static scoped_ptr<base::Value> asValueSafely(double value); |
| 130 static scoped_ptr<base::Value> asValueSafely(float value); | 135 static scoped_ptr<base::Value> asValueSafely(float value); |
| 131 | 136 |
| 132 }; | 137 }; |
| 133 | 138 |
| 134 } // namespace cc | 139 } // namespace cc |
| 135 | 140 |
| 136 #endif // CC_MATH_UTIL_H_ | 141 #endif // CC_MATH_UTIL_H_ |
| OLD | NEW |