File indexing completed on 2024-04-21 04:03:16

0001 /*
0002     SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "coord.h"
0008 
0009 Coord::Coord(int x, int y)
0010 : x(x)
0011 , y(y)
0012 {
0013 }
0014 
0015 Coord Coord::operator+(const Coord& other) const
0016 {
0017     return Coord(x + other.x, y + other.y);
0018 }
0019 
0020 Coord Coord::operator-(const Coord& other) const
0021 {
0022     return Coord(x - other.x, y - other.y);
0023 }
0024 
0025 Coord Coord::operator*(int n) const
0026 {
0027     return Coord(x * n, y * n);
0028 }
0029 
0030 Coord& Coord::operator+=(const Coord& other)
0031 {
0032     x += other.x;
0033     y += other.y;
0034     return *this;
0035 }
0036 
0037 Coord& Coord::operator-=(const Coord& other)
0038 {
0039     x -= other.x;
0040     y -= other.y;
0041     return *this;
0042 }
0043 
0044 bool Coord::operator==(const Coord& other) const
0045 {
0046     return x == other.x && y == other.y;
0047 }
0048 
0049 bool Coord::operator!=(const Coord& other) const
0050 {
0051     return !operator==(other);
0052 }
0053 
0054 bool Coord::valid() const
0055 {
0056     return x != -1 && y != -1;
0057 }
0058 
0059 Coord Coord::invalid()
0060 {
0061     return Coord(-1, -1);
0062 }
0063 
0064 QDebug& operator<<(QDebug& os, const Coord& c)
0065 {
0066     os << "(" << c.x << "," << c.y << ")";
0067     return os;
0068 }
0069 
0070 uint qHash(const Coord& c)
0071 {
0072     return (uint) c.x * 100 + c.y;
0073 }