float point exception, waiting for debugging

This commit is contained in:
2024-06-30 02:51:24 -04:00
parent c5f5f969a4
commit e513e78d1d
32 changed files with 915 additions and 0 deletions

52
src/position.cc Normal file
View File

@ -0,0 +1,52 @@
#include "position.h"
position::position(): x{0}, y{0} {}
position::position(int nx, int ny): x{nx}, y{ny} {}
position position::operator+(const position &other) const {
position result{x + other.x, y + other.y};
return result;
}
position &position::operator=(const position &other) {
x = other.x;
y = other.y;
return *this;
}
position &position::operator+=(const position &other) {
return *this = *this + other;
}
bool position::operator==(const position &other) const {
return x == other.x && y == other.y;
}
bool position::operator!=(const position &other) const {
return x != other.x || y != other.y;
}
bool position::operator<(const position &other) const {
return y < other.y || x < other.x;
}
size_t find(const std::vector<position> &sorted_list,
const position &target) {
int l = 0;
int r = sorted_list.size() - 1;
while (l <= r) {
int mid = l + (l + r) / 2;
if (target == sorted_list[mid])
return mid;
if (target < sorted_list[mid])
l = mid + 1;
else
r = mid - 1;
}
return sorted_list.size();
}