diff options
author | root <root@bpcserver.bpcserver> | 2024-02-27 21:53:44 -0600 |
---|---|---|
committer | root <root@bpcserver.bpcserver> | 2024-02-27 21:53:44 -0600 |
commit | afa02f645056c5823b0d8a29d37c1ff10aedce7a (patch) | |
tree | 0bc89e7909c17d8f33538ac9f31a641872b89f40 /coordinate.cpp |
Diffstat (limited to 'coordinate.cpp')
-rw-r--r-- | coordinate.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/coordinate.cpp b/coordinate.cpp new file mode 100644 index 0000000..54a225c --- /dev/null +++ b/coordinate.cpp @@ -0,0 +1,45 @@ +// Programmer: Brett Weiland +// Date: 4/30/23 +// File: coordinate.cpp +// Assignment: SP-B-finalProject +// Purpose: function for computing info and interacting with coordinates and directions. + +#include <cmath> +#include "coordinate.h" + +int coordinate::get_x() const { return x; } +int coordinate::get_y() const { return y; } +void coordinate::set_x(const int pos_x) { x = pos_x; } +void coordinate::set_y(const int pos_y) { y = pos_y; } +coordinate::coordinate() : x(0), y(0) {} ; +coordinate::coordinate(int pos_x, int pos_y) : x(pos_x), y(pos_y) {}; + +void coordinate::set_xy(const int pos_x, const int pos_y) { + x = pos_x; + y = pos_y; +} + + +int coordinate::getSteps(const coordinate &objective) const { + int steps1, steps2; + steps1 = abs(this->get_x() - objective.get_x()); + steps2 = abs(this->get_y() - objective.get_y()); + return (steps1 > steps2) ? steps1 : steps2; //no max function allowed +} + + +direction::TYPE coordinate::getDirection(const coordinate &objective) const { + return ( + (this->get_y() > objective.get_y()) | + ((this->get_x() < objective.get_x()) << 1) | + ((this->get_y() < objective.get_y()) << 2) | + ((this->get_x() > objective.get_x()) << 3)); +} + +void coordinate::stepDirection(const direction::TYPE path) { + y -= ((path & (1 << direction::N)) >> direction::N); + y += ((path & (1 << direction::S)) >> direction::S); + x += ((path & (1 << direction::E)) >> direction::E); + x -= ((path & (1 << direction::W)) >> direction::W); +} + |