21#include "absl/strings/str_cat.h"
30 return Vec2d(std::cos(angle), std::sin(angle));
48 return std::hypot(
x_ - other.
x_,
y_ - other.
y_);
52 const double dx =
x_ - other.
x_;
53 const double dy =
y_ - other.
y_;
54 return dx * dx + dy * dy;
58 return x_ * other.
y() -
y_ * other.
x();
62 return x_ * other.
x() +
y_ * other.
y();
126 return absl::StrCat(
"vec2d ( x = ",
x_,
" y = ",
y_,
" )");
Implements a class of 2-dimensional vectors.
double LengthSquare() const
Gets the squared length of the vector
void SelfRotate(const double angle)
rotate the vector itself by angle.
double DistanceSquareTo(const Vec2d &other) const
Returns the squared distance to the given vector
Vec2d operator*(const double ratio) const
Multiplies Vec2d by a scalar
static Vec2d CreateUnitVec2d(const double angle)
Creates a unit-vector with a given angle to the positive x semi-axis
Vec2d & operator-=(const Vec2d &other)
Subtracts another Vec2d to the current one
Vec2d & operator*=(const double ratio)
Multiplies this Vec2d by a scalar
double InnerProd(const Vec2d &other) const
Returns the inner product between these two Vec2d.
Vec2d operator/(const double ratio) const
Divides Vec2d by a scalar
double Length() const
Gets the length of the vector
Vec2d operator+(const Vec2d &other) const
Sums two Vec2d
std::string DebugString() const
Returns a human-readable string representing this object
double y() const
Getter for y component
Vec2d rotate(const double angle) const
rotate the vector by angle.
double Angle() const
Gets the angle between the vector and the positive x semi-axis
constexpr Vec2d() noexcept
Constructor returning the zero vector.
double DistanceTo(const Vec2d &other) const
Returns the distance to the given vector
double x() const
Getter for x component
Vec2d & operator/=(const double ratio)
Divides this Vec2d by a scalar
bool operator==(const Vec2d &other) const
Compares two Vec2d
double CrossProd(const Vec2d &other) const
Returns the "cross" product between these two Vec2d (non-standard).
void Normalize()
Returns the unit vector that is co-linear with this vector
Vec2d & operator+=(const Vec2d &other)
Sums another Vec2d to the current one
Vec2d operator-(const Vec2d &other) const
Subtracts two Vec2d
constexpr double kMathEpsilon
Angle< T > operator*(Angle< T > lhs, Scalar rhs)
Multiplies an Angle by a scalar