Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
vector2d_f.cc
Go to the documentation of this file.
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
3// found in the LICENSE file.
4
5#include "vector2d_f.h"
6
7#include <cmath>
8
9#include "base/string_utils.h"
10
11namespace gfx {
12
13std::string Vector2dF::ToString() const {
14 return base::StringPrintf("[%f %f]", x_, y_);
15}
16
17bool Vector2dF::IsZero() const {
18 return x_ == 0 && y_ == 0;
19}
20
21void Vector2dF::Add(const Vector2dF& other) {
22 x_ += other.x_;
23 y_ += other.y_;
24}
25
26void Vector2dF::Subtract(const Vector2dF& other) {
27 x_ -= other.x_;
28 y_ -= other.y_;
29}
30
32 return static_cast<double>(x_) * x_ + static_cast<double>(y_) * y_;
33}
34
35float Vector2dF::Length() const {
36 return static_cast<float>(std::sqrt(LengthSquared()));
37}
38
39void Vector2dF::Scale(float x_scale, float y_scale) {
40 x_ *= x_scale;
41 y_ *= y_scale;
42}
43
44double CrossProduct(const Vector2dF& lhs, const Vector2dF& rhs) {
45 return static_cast<double>(lhs.x()) * rhs.y() -
46 static_cast<double>(lhs.y()) * rhs.x();
47}
48
49double DotProduct(const Vector2dF& lhs, const Vector2dF& rhs) {
50 return static_cast<double>(lhs.x()) * rhs.x() +
51 static_cast<double>(lhs.y()) * rhs.y();
52}
53
54Vector2dF ScaleVector2d(const Vector2dF& v, float x_scale, float y_scale) {
55 Vector2dF scaled_v(v);
56 scaled_v.Scale(x_scale, y_scale);
57 return scaled_v;
58}
59
60} // namespace gfx
void Add(const Vector2dF &other)
Definition vector2d_f.cc:21
constexpr float y() const
Definition vector2d_f.h:29
bool IsZero() const
Definition vector2d_f.cc:17
void Scale(float scale)
Definition vector2d_f.h:59
float Length() const
Definition vector2d_f.cc:35
std::string ToString() const
Definition vector2d_f.cc:13
constexpr float x() const
Definition vector2d_f.h:26
void Subtract(const Vector2dF &other)
Definition vector2d_f.cc:26
double LengthSquared() const
Definition vector2d_f.cc:31
std::string StringPrintf(const std::string &format, Args... args)
Definition insets.cc:10
double DotProduct(const Vector2dF &lhs, const Vector2dF &rhs)
Definition vector2d_f.cc:49
Vector2dF ScaleVector2d(const Vector2dF &v, float x_scale, float y_scale)
Definition vector2d_f.cc:54
double CrossProduct(const Vector2dF &lhs, const Vector2dF &rhs)
Definition vector2d_f.cc:44