Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
accessibility
gfx
geometry
vector2d.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.h
"
6
7
#include <cmath>
8
9
#include "
base/numerics/clamped_math.h
"
10
#include "
base/string_utils.h
"
11
12
namespace
gfx
{
13
14
bool
Vector2d::IsZero
()
const
{
15
return
x_ == 0 && y_ == 0;
16
}
17
18
void
Vector2d::Add
(
const
Vector2d
& other) {
19
x_ = base::ClampAdd(other.x_, x_);
20
y_ = base::ClampAdd(other.y_, y_);
21
}
22
23
void
Vector2d::Subtract
(
const
Vector2d
& other) {
24
x_ = base::ClampSub(x_, other.x_);
25
y_ = base::ClampSub(y_, other.y_);
26
}
27
28
int64_t
Vector2d::LengthSquared
()
const
{
29
return
static_cast<
int64_t
>
(x_) * x_ +
static_cast<
int64_t
>
(y_) * y_;
30
}
31
32
float
Vector2d::Length
()
const
{
33
return
static_cast<
float
>
(std::sqrt(
static_cast<
double
>
(
LengthSquared
())));
34
}
35
36
std::string
Vector2d::ToString
()
const
{
37
return
base::StringPrintf
(
"[%d %d]"
, x_, y_);
38
}
39
40
}
// namespace gfx
clamped_math.h
gfx::Vector2d
Definition
vector2d.h:22
gfx::Vector2d::IsZero
bool IsZero() const
Definition
vector2d.cc:14
gfx::Vector2d::Subtract
void Subtract(const Vector2d &other)
Definition
vector2d.cc:23
gfx::Vector2d::Add
void Add(const Vector2d &other)
Definition
vector2d.cc:18
gfx::Vector2d::Length
float Length() const
Definition
vector2d.cc:32
gfx::Vector2d::ToString
std::string ToString() const
Definition
vector2d.cc:36
gfx::Vector2d::LengthSquared
int64_t LengthSquared() const
Definition
vector2d.cc:28
base::StringPrintf
std::string StringPrintf(const std::string &format, Args... args)
Definition
string_utils.h:18
gfx
Definition
insets.cc:10
string_utils.h
vector2d.h
Generated on Fri Apr 26 2024 06:14:39 for Flutter Engine by
1.9.8