Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: cc/base/math_util.cc

Issue 130443005: [#5] Pass gfx structs by const ref (gfx::Vector2dF) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated the review comments Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/base/math_util.h ('k') | cc/input/input_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "cc/base/math_util.h" 5 #include "cc/base/math_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 10
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 return gfx::Vector2dF(fallback_value, fallback_value); 485 return gfx::Vector2dF(fallback_value, fallback_value);
486 float x_scale = ScaleOnAxis(transform.matrix().getDouble(0, 0), 486 float x_scale = ScaleOnAxis(transform.matrix().getDouble(0, 0),
487 transform.matrix().getDouble(1, 0), 487 transform.matrix().getDouble(1, 0),
488 transform.matrix().getDouble(2, 0)); 488 transform.matrix().getDouble(2, 0));
489 float y_scale = ScaleOnAxis(transform.matrix().getDouble(0, 1), 489 float y_scale = ScaleOnAxis(transform.matrix().getDouble(0, 1),
490 transform.matrix().getDouble(1, 1), 490 transform.matrix().getDouble(1, 1),
491 transform.matrix().getDouble(2, 1)); 491 transform.matrix().getDouble(2, 1));
492 return gfx::Vector2dF(x_scale, y_scale); 492 return gfx::Vector2dF(x_scale, y_scale);
493 } 493 }
494 494
495 float MathUtil::SmallestAngleBetweenVectors(gfx::Vector2dF v1, 495 float MathUtil::SmallestAngleBetweenVectors(const gfx::Vector2dF& v1,
496 gfx::Vector2dF v2) { 496 const gfx::Vector2dF& v2) {
497 double dot_product = gfx::DotProduct(v1, v2) / v1.Length() / v2.Length(); 497 double dot_product = gfx::DotProduct(v1, v2) / v1.Length() / v2.Length();
498 // Clamp to compensate for rounding errors. 498 // Clamp to compensate for rounding errors.
499 dot_product = std::max(-1.0, std::min(1.0, dot_product)); 499 dot_product = std::max(-1.0, std::min(1.0, dot_product));
500 return static_cast<float>(Rad2Deg(std::acos(dot_product))); 500 return static_cast<float>(Rad2Deg(std::acos(dot_product)));
501 } 501 }
502 502
503 gfx::Vector2dF MathUtil::ProjectVector(gfx::Vector2dF source, 503 gfx::Vector2dF MathUtil::ProjectVector(const gfx::Vector2dF& source,
504 gfx::Vector2dF destination) { 504 const gfx::Vector2dF& destination) {
505 float projected_length = 505 float projected_length =
506 gfx::DotProduct(source, destination) / destination.LengthSquared(); 506 gfx::DotProduct(source, destination) / destination.LengthSquared();
507 return gfx::Vector2dF(projected_length * destination.x(), 507 return gfx::Vector2dF(projected_length * destination.x(),
508 projected_length * destination.y()); 508 projected_length * destination.y());
509 } 509 }
510 510
511 scoped_ptr<base::Value> MathUtil::AsValue(gfx::Size s) { 511 scoped_ptr<base::Value> MathUtil::AsValue(gfx::Size s) {
512 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue()); 512 scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
513 res->SetDouble("width", s.width()); 513 res->SetDouble("width", s.width());
514 res->SetDouble("height", s.height()); 514 res->SetDouble("height", s.height());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( 606 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue(
607 std::min(value, std::numeric_limits<double>::max()))); 607 std::min(value, std::numeric_limits<double>::max())));
608 } 608 }
609 609
610 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { 610 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) {
611 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( 611 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue(
612 std::min(value, std::numeric_limits<float>::max()))); 612 std::min(value, std::numeric_limits<float>::max())));
613 } 613 }
614 614
615 } // namespace cc 615 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/math_util.h ('k') | cc/input/input_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698