1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "nel/misc/types_nl.h"
25 // ***************************************************************************
27 * A 2D vector of sint32.
33 public: // Attributes.
38 /// Constructor which do nothing.
41 CVector2i(sint32 _x
, sint32 _y
) : x(_x
), y(_y
) {}
43 CVector2i(const CVector2i
&v
) : x(v
.x
), y(v
.y
) {}
46 CVector2i
&operator+=(const CVector2i
&v
) {x
+=v
.x
; y
+=v
.y
; return *this;}
47 CVector2i
&operator-=(const CVector2i
&v
) {x
-=v
.x
; y
-=v
.y
; return *this;}
48 CVector2i
&operator*=(sint32 i
) {x
*=i
; y
*=i
; return *this;}
49 CVector2i
&operator/=(sint32 i
) {x
/=i
; y
/=i
; return *this;}
50 CVector2i
operator+(const CVector2i
&v
) const {return CVector2i(x
+v
.x
, y
+v
.y
);}
51 CVector2i
operator-(const CVector2i
&v
) const {return CVector2i(x
-v
.x
, y
-v
.y
);}
52 CVector2i
operator*(sint32 i
) const {return CVector2i(x
*i
, y
*i
);}
53 CVector2i
operator/(sint32 i
) const {return CVector2i(x
/i
, y
/i
);}
54 CVector2i
operator-() const {return CVector2i(-x
, -y
);}
58 sint32
operator*(const CVector2i
&v
) const {return x
*v
.x
+ y
*v
.y
;}
59 // Return the norm of the vector.
60 sint32
norm() const {return (sint32
)sqrt((double)sqrnorm());}
61 // Return the square of the norm of the vector.
62 sint32
sqrnorm() const {return x
*x
+ y
*y
;}
63 // Normalize the vector.
70 /// Return the vector normalized.
71 CVector2i
normed() const
79 void set(sint32 _x
, sint32 _y
) {x
= _x
; y
=_y
;}
80 bool operator==(const CVector2i
&v
) const {return x
==v
.x
&& y
==v
.y
;}
81 bool operator!=(const CVector2i
&v
) const {return !(*this==v
);}
82 bool isNull() const {return x
==0.0f
&& y
==0.0f
;}
85 void serial(NLMISC::IStream
&i
) {i
.serial(x
,y
);}