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