7 #ifndef INFOSV_VEC2D_HPP 8 #define INFOSV_VEC2D_HPP 10 #include <JSON/JSON.hpp> 11 #include <Utility/Constants.hpp> 13 #include <SFML/System.hpp> 55 Vec2d(
double x,
double y);
57 Vec2d(sf::Vector2f
const& sfvect);
58 Vec2d(sf::Vector2i
const& sfvect);
69 Vec2d& operator=(
Vec2d const& other) =
default;
71 operator sf::Vector2f()
const;
72 operator sf::Vector2i()
const;
77 j::Value
save()
const;
112 double angle()
const;
120 double dot(
Vec2d const& other)
const;
133 Vec2d operator*(
double c)
const;
134 Vec2d operator/(
double c)
const;
138 Vec2d& operator*=(
double c);
139 Vec2d& operator/=(
double c);
141 bool operator==(
Vec2d const& b)
const;
142 bool operator!=(
Vec2d const& b)
const;
179 double distance(
Vec2d const& x,
Vec2d const& y);
190 std::ostream& operator<<(std::ostream& out,
Vec2d const& v);
192 #endif // INFOSV_VEC2D_HPP int sign(Vec2d const &other) const
Compares the angle between another vector and this one.
Definition: Vec2d.cpp:223
static Vec2d fromRandomAngle(double min=0, double max=TAU)
Create a random vector.
Definition: Vec2d.cpp:19
double angle() const
Computes the angle of the vector in polar coordinates.
Definition: Vec2d.cpp:213
double operator[](int axis) const
Accesses the coordinates by dimension, read-write.
Definition: Vec2d.cpp:156
Bridge vector class to sf::Vector2i/f that provides some common math methods.
Definition: Vec2d.hpp:23
j::Value save() const
Save internal representation as JSON value.
Definition: Vec2d.cpp:64
static Vec2d fromJSON(j::Value json)
Construct a vector from its internal representation in JSON format.
Definition: Vec2d.cpp:24
double dot(Vec2d const &other) const
Computes the dot product between this and another vector.
Definition: Vec2d.cpp:218
Vec2d normalised() const
Computes the normalized vector.
Definition: Vec2d.cpp:192
Vec2d normal() const
Computes the normal (orthogonal) vector for this vector.
Definition: Vec2d.cpp:198
static Vec2d fromAngle(double rad)
Create a unitary Vec2d from an angle.
Definition: Vec2d.cpp:14
double length() const
Computes the length of the vector.
Definition: Vec2d.cpp:187
Vec2d operator-() const
Negation.
Definition: Vec2d.cpp:74
double lengthSquared() const
Computes the length of the vector (squared).
Definition: Vec2d.cpp:182