23 return std::sqrt(pow(
x, 2) + pow(
y, 2));
36 Vec2 out = *
this * scale;
42 Vec2 dist = target - *
this;
48 Vec2 dist = target - *
this;
66 Vec2 output =
XandY(this->
x * scale, this->
y * scale);
72 return x*other.
x +
y*other.
y ;
107 output.
x = mag * sin(dir);
108 output.
y = mag * cos(dir);
Header containing the 2d Vector class.
A Utility 2D Vector class.
Vec2 & operator+=(Vec2 const &obj)
Adds another vector to this one.
Vec2()
Construct a new Vec 2 object.
double y
Stores the Y component of the Vector.
Vec2 operator*(double const &scale) const
Returns a vector after scaling it.
double x
Stores the X component of the Vector.
Vec2 operator-(Vec2 const &obj) const
Returns the difference of 2 vectors.
double angleTo(Vec2 target) const
Gets the angle from this vector to another.
double direction() const
Gets the direction of the Vector.
Vec2 & operator*=(double const &scale)
Changes the vector by a scale.
Vec2 operator+(Vec2 const &obj) const
Returns the sum of 2 vectors.
double magnitude() const
Gets the magnitude of the Vector.
Vec2 & operator-=(Vec2 const &obj)
Substracts another vector from this one.
double distTo(Vec2 target) const
Gets the distance from this vector to another.
static Vec2 dirAndMag(double dir, double mag)
Constructs a vector with the specified direction and magnitude.
Vec2 normalize() const
Returns a unit Vector with the same direction.
static Vec2 XandY(double x, double y)
Constructs a vector with the specified x and y components.