• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kmahjongg

  • sources
  • kde-4.14
  • kdegames
  • kmahjongg
TileCoord.h
Go to the documentation of this file.
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 
34 class TileCoord
35 {
36 public:
40  TileCoord();
48  TileCoord(int xpos, int ypos, int zpos);
57  int x() const;
60  int y() const;
63  int z() const;
66  void setX(int x);
69  void setY(int y);
72  void setZ(int y);
73 
77  int &rx();
80  int &ry();
83  int &rz();
90  TileCoord &operator+=(const TileCoord &t);
97  TileCoord &operator-=(const TileCoord &t);
104  TileCoord &operator*=(qreal c);
111  TileCoord &operator/=(qreal c);
114  friend inline bool operator==(const TileCoord &, const TileCoord &);
117  friend inline bool operator!=(const TileCoord &, const TileCoord &);
120  friend inline const TileCoord operator+(const TileCoord &, const TileCoord &);
123  friend inline const TileCoord operator-(const TileCoord &, const TileCoord &);
126  friend inline const TileCoord operator*(const TileCoord &, qreal);
129  friend inline const TileCoord operator*(qreal, const TileCoord &);
132  friend inline const TileCoord operator-(const TileCoord &);
135  friend inline const TileCoord operator/(const TileCoord &, qreal);
136 
137 private:
138  int yp;
139  int xp;
140  int zp;
141 };
142 
143 inline uint qHash(const TileCoord &key) { return qHash(QString("X%1Y%2Z%3").arg(key.x()).arg(key.y()).arg(key.z())); }
144 
145 inline TileCoord::TileCoord()
146 { xp=0; yp=0; zp=0; }
147 
148 inline TileCoord::TileCoord(int xpos, int ypos, int zpos)
149 { xp = xpos; yp = ypos; zp = zpos; }
150 
151 inline int TileCoord::x() const
152 { return xp; }
153 
154 inline int TileCoord::y() const
155 { return yp; }
156 
157 inline int TileCoord::z() const
158 { return zp; }
159 
160 inline void TileCoord::setX(int xpos)
161 { xp = xpos; }
162 
163 inline void TileCoord::setY(int ypos)
164 { yp = ypos; }
165 
166 inline void TileCoord::setZ(int zpos)
167 { zp = zpos; }
168 
169 inline int &TileCoord::rx()
170 { return xp; }
171 
172 inline int &TileCoord::ry()
173 { return yp; }
174 
175 inline int &TileCoord::rz()
176 { return zp; }
177 
178 inline TileCoord &TileCoord::operator+=(const TileCoord &p)
179 { xp+=p.xp; yp+=p.yp; zp+=p.zp; return *this; }
180 
181 inline TileCoord &TileCoord::operator-=(const TileCoord &p)
182 { xp-=p.xp; yp-=p.yp; zp-=p.zp; return *this; }
183 
184 inline TileCoord &TileCoord::operator*=(qreal c)
185 { xp = qRound(xp*c); yp = qRound(yp*c); zp = qRound(zp*c); return *this; }
186 
187 inline bool operator==(const TileCoord &p1, const TileCoord &p2)
188 { return p1.xp == p2.xp && p1.yp == p2.yp && p1.zp == p2.zp; }
189 
190 inline bool operator!=(const TileCoord &p1, const TileCoord &p2)
191 { return p1.xp != p2.xp || p1.yp != p2.yp || p1.zp != p2.zp; }
192 
193 inline 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 
196 inline 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 
199 inline const TileCoord operator*(const TileCoord &p, qreal c)
200 { return TileCoord(qRound(p.xp*c), qRound(p.yp*c), qRound(p.zp*c)); }
201 
202 inline const TileCoord operator*(qreal c, const TileCoord &p)
203 { return TileCoord(qRound(p.xp*c), qRound(p.yp*c), qRound(p.zp*c)); }
204 
205 inline const TileCoord operator-(const TileCoord &p)
206 { return TileCoord(-p.xp, -p.yp, -p.zp); }
207 
208 inline 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 
217 inline 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
TileCoord::setZ
void setZ(int y)
Method description.
Definition: TileCoord.h:166
TileCoord::TileCoord
TileCoord()
Method description.
Definition: TileCoord.h:145
TileCoord::operator-
friend const TileCoord operator-(const TileCoord &, const TileCoord &)
Method subtraction.
Definition: TileCoord.h:196
TileCoord::operator*=
TileCoord & operator*=(qreal c)
Method description.
Definition: TileCoord.h:184
TileCoord::operator+
friend const TileCoord operator+(const TileCoord &, const TileCoord &)
Method addition.
Definition: TileCoord.h:193
TileCoord::rx
int & rx()
Method description.
Definition: TileCoord.h:169
TileCoord::operator!=
friend bool operator!=(const TileCoord &, const TileCoord &)
Method not equal.
Definition: TileCoord.h:190
TileCoord
This class implements.
Definition: TileCoord.h:34
TileCoord::y
int y() const
Method description.
Definition: TileCoord.h:154
operator*
const TileCoord operator*(const TileCoord &p, qreal c)
Definition: TileCoord.h:199
TileCoord::operator+=
TileCoord & operator+=(const TileCoord &t)
Method description.
Definition: TileCoord.h:178
TileCoord::operator*
friend const TileCoord operator*(const TileCoord &, qreal)
Method multiplication.
Definition: TileCoord.h:199
QString
TileCoord::z
int z() const
Method description.
Definition: TileCoord.h:157
TileCoord::x
int x() const
Method description.
Definition: TileCoord.h:151
TileCoord::ry
int & ry()
Method description.
Definition: TileCoord.h:172
TileCoord::operator-=
TileCoord & operator-=(const TileCoord &t)
Method description.
Definition: TileCoord.h:181
operator==
bool operator==(const TileCoord &p1, const TileCoord &p2)
Definition: TileCoord.h:187
operator!=
bool operator!=(const TileCoord &p1, const TileCoord &p2)
Definition: TileCoord.h:190
operator+
const TileCoord operator+(const TileCoord &p1, const TileCoord &p2)
Definition: TileCoord.h:193
qHash
uint qHash(const TileCoord &key)
Definition: TileCoord.h:143
operator/
const TileCoord operator/(const TileCoord &p, qreal c)
Definition: TileCoord.h:217
TileCoord::operator==
friend bool operator==(const TileCoord &, const TileCoord &)
Method equals.
Definition: TileCoord.h:187
TileCoord::operator/
friend const TileCoord operator/(const TileCoord &, qreal)
Method division.
Definition: TileCoord.h:217
TileCoord::setX
void setX(int x)
Method description.
Definition: TileCoord.h:160
operator-
const TileCoord operator-(const TileCoord &p1, const TileCoord &p2)
Definition: TileCoord.h:196
TileCoord::rz
int & rz()
Method description.
Definition: TileCoord.h:175
TileCoord::setY
void setY(int y)
Method description.
Definition: TileCoord.h:163
TileCoord::operator/=
TileCoord & operator/=(qreal c)
Method description.
Definition: TileCoord.h:208
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmahjongg

Skip menu "kmahjongg"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal