diff options
author | Aki <please@ignore.pl> | 2022-12-03 00:44:07 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-12-03 00:44:07 +0100 |
commit | 18a763bcb19c5ece4b7b7d079dab07a1d915deb6 (patch) | |
tree | 137278522c98f5cb5cf4067886444b20b3eaf82d /sim/src/Point.cpp | |
parent | 18eba7f30381c05ee1c03bec5f537ec7d4dc9815 (diff) | |
download | kurator-18a763bcb19c5ece4b7b7d079dab07a1d915deb6.zip kurator-18a763bcb19c5ece4b7b7d079dab07a1d915deb6.tar.gz kurator-18a763bcb19c5ece4b7b7d079dab07a1d915deb6.tar.bz2 |
Moved battles module files to sim
Diffstat (limited to 'sim/src/Point.cpp')
-rw-r--r-- | sim/src/Point.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/sim/src/Point.cpp b/sim/src/Point.cpp new file mode 100644 index 0000000..31aecae --- /dev/null +++ b/sim/src/Point.cpp @@ -0,0 +1,72 @@ +#include <kurator/battles/Point.h> + +#include <cmath> + + +namespace kurator +{ +namespace battles +{ + + +double +Point::magnitude() const +{ + return std::sqrt(std::pow(x, 2) + std::pow(y, 2)); +} + + +double +Point::distance(const Point& other) const +{ + return std::sqrt(std::pow(other.x - x, 2) + std::pow(other.y - y, 2)); +} + + +double +Point::angle() const +{ + return std::atan2(y, x); // (+x, _) is 0 +} + + +Point +Point::rotate(const double angle) const +{ + return { + x * std::cos(angle) - y * std::sin(angle), + x * std::sin(angle) + y * std::cos(angle), + }; +} + + +Point +Point::scale(const double _scale) const +{ + return {x * _scale, y * _scale}; +} + + +Point +Point::normalized() const +{ + return scale(1.0 / magnitude()); +} + + +Point +Point::operator-(const Point& other) const +{ + return {x - other.x, y - other.y}; +} + + +Point +Point::operator+(const Point& other) const +{ + return {x + other.x, y + other.y}; +} + + +} // namespace battles +} // namespace kurator |