diff options
author | Aki <please@ignore.pl> | 2022-11-12 14:28:39 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-11-12 14:28:39 +0100 |
commit | c6d17ef545978bec555c8af8ef5eaef82c44e5f1 (patch) | |
tree | 461fff66de35a9f26aebde8cffc6386efa8e104f /battles/src/Point.cpp | |
parent | 0e57ea98049658b4d82488c43d71b4ced534c2af (diff) | |
download | kurator-c6d17ef545978bec555c8af8ef5eaef82c44e5f1.zip kurator-c6d17ef545978bec555c8af8ef5eaef82c44e5f1.tar.gz kurator-c6d17ef545978bec555c8af8ef5eaef82c44e5f1.tar.bz2 |
Implemented very basic linear move-to-dest component
Diffstat (limited to 'battles/src/Point.cpp')
-rw-r--r-- | battles/src/Point.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/battles/src/Point.cpp b/battles/src/Point.cpp new file mode 100644 index 0000000..9ffa81c --- /dev/null +++ b/battles/src/Point.cpp @@ -0,0 +1,65 @@ +#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)); +} + + +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 |