1/*
2 Copyright (C) 2006 Mauricio Piacentini <mauricio@tabuleiro.com>
3 Modeled after qpoint.h
4 Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
5
6 Kmahjongg is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19*/
20
21#ifndef TILECOORD_H
22#define TILECOORD_H
23
24
25#include <QHash>
26
27/**
28* This class implements
29*
30* longer description
31*
32* @author Mauricio Piacentini <mauricio@tabuleiro.com>
33*/
34class TileCoord
35{
36public:
37 /**
38 * Method description
39 */
40 TileCoord();
41 /**
42 * Method description
43 *
44 * @param xpos blah blah
45 * @param ypos blah blah
46 * @param zpos blah blah
47 */
48 TileCoord(int xpos, int ypos, int zpos);
49 /**
50 * Method description
51 *
52 * @return @c true if reason?
53 * @return @c false if reson
54 */
55 /**
56 * Method description @return int */
57 int x() const;
58 /**
59 * Method description @return int */
60 int y() const;
61 /**
62 * Method description @return int */
63 int z() const;
64 /**
65 * Method description @param x */
66 void setX(int x);
67 /**
68 * Method description @param y */
69 void setY(int y);
70 /**
71 * Method description @param y */
72 void setZ(int y);
73
74 /**
75 * Method description
76 */
77 int &rx();
78 /**
79 * Method description @return int */
80 int &ry();
81 /**
82 * Method description @return int */
83 int &rz();
84 /**
85 * Method description
86 *
87 * @param t blah
88 * @return TileCoord blah
89 */
90 TileCoord &operator+=(const TileCoord &t);
91 /**
92 * Method description
93 *
94 * @param t blah
95 * @return TileCoord blah
96 */
97 TileCoord &operator-=(const TileCoord &t);
98 /**
99 * Method description
100 *
101 * @param c blah
102 * @return TileCoord blah
103 */
104 TileCoord &operator*=(qreal c);
105 /**
106 * Method description
107 *
108 * @param c blah
109 * @return TileCoord blah
110 */
111 TileCoord &operator/=(qreal c);
112 /**
113 * Method equals */
114 friend inline bool operator==(const TileCoord &, const TileCoord &);
115 /**
116 * Method not equal */
117 friend inline bool operator!=(const TileCoord &, const TileCoord &);
118 /**
119 * Method addition */
120 friend inline const TileCoord operator+(const TileCoord &, const TileCoord &);
121 /**
122 * Method subtraction */
123 friend inline const TileCoord operator-(const TileCoord &, const TileCoord &);
124 /**
125 * Method multiplication */
126 friend inline const TileCoord operator*(const TileCoord &, qreal);
127 /**
128 * Method multiplication */
129 friend inline const TileCoord operator*(qreal, const TileCoord &);
130 /**
131 * Method subtraction */
132 friend inline const TileCoord operator-(const TileCoord &);
133 /**
134 * Method division */
135 friend inline const TileCoord operator/(const TileCoord &, qreal);
136
137private:
138 int yp;
139 int xp;
140 int zp;
141};
142
143inline uint qHash(const TileCoord &key) { return qHash(QString("X%1Y%2Z%3").arg(key.x()).arg(key.y()).arg(key.z())); }
144
145inline TileCoord::TileCoord()
146{ xp=0; yp=0; zp=0; }
147
148inline TileCoord::TileCoord(int xpos, int ypos, int zpos)
149{ xp = xpos; yp = ypos; zp = zpos; }
150
151inline int TileCoord::x() const
152{ return xp; }
153
154inline int TileCoord::y() const
155{ return yp; }
156
157inline int TileCoord::z() const
158{ return zp; }
159
160inline void TileCoord::setX(int xpos)
161{ xp = xpos; }
162
163inline void TileCoord::setY(int ypos)
164{ yp = ypos; }
165
166inline void TileCoord::setZ(int zpos)
167{ zp = zpos; }
168
169inline int &TileCoord::rx()
170{ return xp; }
171
172inline int &TileCoord::ry()
173{ return yp; }
174
175inline int &TileCoord::rz()
176{ return zp; }
177
178inline TileCoord &TileCoord::operator+=(const TileCoord &p)
179{ xp+=p.xp; yp+=p.yp; zp+=p.zp; return *this; }
180
181inline TileCoord &TileCoord::operator-=(const TileCoord &p)
182{ xp-=p.xp; yp-=p.yp; zp-=p.zp; return *this; }
183
184inline TileCoord &TileCoord::operator*=(qreal c)
185{ xp = qRound(xp*c); yp = qRound(yp*c); zp = qRound(zp*c); return *this; }
186
187inline bool operator==(const TileCoord &p1, const TileCoord &p2)
188{ return p1.xp == p2.xp && p1.yp == p2.yp && p1.zp == p2.zp; }
189
190inline bool operator!=(const TileCoord &p1, const TileCoord &p2)
191{ return p1.xp != p2.xp || p1.yp != p2.yp || p1.zp != p2.zp; }
192
193inline const TileCoord operator+(const TileCoord &p1, const TileCoord &p2)
194{ return TileCoord(p1.xp+p2.xp, p1.yp+p2.yp, p1.zp+p2.zp); }
195
196inline const TileCoord operator-(const TileCoord &p1, const TileCoord &p2)
197{ return TileCoord(p1.xp-p2.xp, p1.yp-p2.yp, p1.zp-p2.zp); }
198
199inline const TileCoord operator*(const TileCoord &p, qreal c)
200{ return TileCoord(qRound(p.xp*c), qRound(p.yp*c), qRound(p.zp*c)); }
201
202inline const TileCoord operator*(qreal c, const TileCoord &p)
203{ return TileCoord(qRound(p.xp*c), qRound(p.yp*c), qRound(p.zp*c)); }
204
205inline const TileCoord operator-(const TileCoord &p)
206{ return TileCoord(-p.xp, -p.yp, -p.zp); }
207
208inline TileCoord &TileCoord::operator/=(qreal c)
209{
210 Q_ASSERT(!qFuzzyCompare(c, 0));
211 xp = qRound(xp/c);
212 yp = qRound(yp/c);
213 zp = qRound(zp/c);
214 return *this;
215}
216
217inline const TileCoord operator/(const TileCoord &p, qreal c)
218{
219 Q_ASSERT(!qFuzzyCompare(c, 0));
220 return TileCoord(qRound(p.xp/c), qRound(p.yp/c), qRound(p.zp/c));
221}
222
223#endif // TILECOORD_H
224