| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include "ui/gfx/transform.h" | 8 #include "ui/gfx/transform.h" |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // Taken from SkMatrix44. | 25 // Taken from SkMatrix44. |
| 26 const double kTooSmallForDeterminant = 1e-8; | 26 const double kTooSmallForDeterminant = 1e-8; |
| 27 | 27 |
| 28 double TanDegrees(double degrees) { | 28 double TanDegrees(double degrees) { |
| 29 double radians = degrees * M_PI / 180; | 29 double radians = degrees * M_PI / 180; |
| 30 return std::tan(radians); | 30 return std::tan(radians); |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 Transform::Transform( |
| 36 double col1row1, double col2row1, double col3row1, double col4row1, |
| 37 double col1row2, double col2row2, double col3row2, double col4row2, |
| 38 double col1row3, double col2row3, double col3row3, double col4row3, |
| 39 double col1row4, double col2row4, double col3row4, double col4row4) |
| 40 : matrix_(SkMatrix44::kUninitialized_Constructor) |
| 41 { |
| 42 matrix_.setDouble(0, 0, col1row1); |
| 43 matrix_.setDouble(1, 0, col1row2); |
| 44 matrix_.setDouble(2, 0, col1row3); |
| 45 matrix_.setDouble(3, 0, col1row4); |
| 46 |
| 47 matrix_.setDouble(0, 1, col2row1); |
| 48 matrix_.setDouble(1, 1, col2row2); |
| 49 matrix_.setDouble(2, 1, col2row3); |
| 50 matrix_.setDouble(3, 1, col2row4); |
| 51 |
| 52 matrix_.setDouble(0, 2, col3row1); |
| 53 matrix_.setDouble(1, 2, col3row2); |
| 54 matrix_.setDouble(2, 2, col3row3); |
| 55 matrix_.setDouble(3, 2, col3row4); |
| 56 |
| 57 matrix_.setDouble(0, 3, col4row1); |
| 58 matrix_.setDouble(1, 3, col4row2); |
| 59 matrix_.setDouble(2, 3, col4row3); |
| 60 matrix_.setDouble(3, 3, col4row4); |
| 61 } |
| 62 |
| 63 Transform::Transform( |
| 64 double col1row1, double col2row1, |
| 65 double col1row2, double col2row2, |
| 66 double x_translation, double y_translation) |
| 67 : matrix_(SkMatrix44::kIdentity_Constructor) |
| 68 { |
| 69 matrix_.setDouble(0, 0, col1row1); |
| 70 matrix_.setDouble(1, 0, col1row2); |
| 71 matrix_.setDouble(0, 1, col2row1); |
| 72 matrix_.setDouble(1, 1, col2row2); |
| 73 matrix_.setDouble(0, 3, x_translation); |
| 74 matrix_.setDouble(1, 3, y_translation); |
| 75 } |
| 76 |
| 35 void Transform::RotateAboutXAxis(double degrees) { | 77 void Transform::RotateAboutXAxis(double degrees) { |
| 36 double radians = degrees * M_PI / 180; | 78 double radians = degrees * M_PI / 180; |
| 37 double cosTheta = std::cos(radians); | 79 double cosTheta = std::cos(radians); |
| 38 double sinTheta = std::sin(radians); | 80 double sinTheta = std::sin(radians); |
| 39 if (matrix_.isIdentity()) { | 81 if (matrix_.isIdentity()) { |
| 40 matrix_.set3x3(1, 0, 0, | 82 matrix_.set3x3(1, 0, 0, |
| 41 0, cosTheta, sinTheta, | 83 0, cosTheta, sinTheta, |
| 42 0, -sinTheta, cosTheta); | 84 0, -sinTheta, cosTheta); |
| 43 } else { | 85 } else { |
| 44 SkMatrix44 rot; | 86 SkMatrix44 rot; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 return false; | 294 return false; |
| 253 } | 295 } |
| 254 | 296 |
| 255 return true; | 297 return true; |
| 256 } | 298 } |
| 257 | 299 |
| 258 void Transform::Transpose() { | 300 void Transform::Transpose() { |
| 259 matrix_.transpose(); | 301 matrix_.transpose(); |
| 260 } | 302 } |
| 261 | 303 |
| 304 void Transform::FlattenTo2d() { |
| 305 matrix_.setDouble(2, 0, 0.0); |
| 306 matrix_.setDouble(2, 1, 0.0); |
| 307 matrix_.setDouble(0, 2, 0.0); |
| 308 matrix_.setDouble(1, 2, 0.0); |
| 309 matrix_.setDouble(2, 2, 1.0); |
| 310 matrix_.setDouble(3, 2, 0.0); |
| 311 matrix_.setDouble(2, 3, 0.0); |
| 312 } |
| 313 |
| 262 void Transform::TransformPoint(Point& point) const { | 314 void Transform::TransformPoint(Point& point) const { |
| 263 TransformPointInternal(matrix_, point); | 315 TransformPointInternal(matrix_, point); |
| 264 } | 316 } |
| 265 | 317 |
| 266 void Transform::TransformPoint(Point3F& point) const { | 318 void Transform::TransformPoint(Point3F& point) const { |
| 267 TransformPointInternal(matrix_, point); | 319 TransformPointInternal(matrix_, point); |
| 268 } | 320 } |
| 269 | 321 |
| 270 bool Transform::TransformPointReverse(Point& point) const { | 322 bool Transform::TransformPointReverse(Point& point) const { |
| 271 // TODO(sad): Try to avoid trying to invert the matrix. | 323 // TODO(sad): Try to avoid trying to invert the matrix. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 matrix_.getDouble(2, 1), | 442 matrix_.getDouble(2, 1), |
| 391 matrix_.getDouble(2, 2), | 443 matrix_.getDouble(2, 2), |
| 392 matrix_.getDouble(2, 3), | 444 matrix_.getDouble(2, 3), |
| 393 matrix_.getDouble(3, 0), | 445 matrix_.getDouble(3, 0), |
| 394 matrix_.getDouble(3, 1), | 446 matrix_.getDouble(3, 1), |
| 395 matrix_.getDouble(3, 2), | 447 matrix_.getDouble(3, 2), |
| 396 matrix_.getDouble(3, 3)); | 448 matrix_.getDouble(3, 3)); |
| 397 } | 449 } |
| 398 | 450 |
| 399 } // namespace gfx | 451 } // namespace gfx |
| OLD | NEW |