// 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 #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); }