PixelLightAPI  .
Vector2i.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Vector2i.h                                     *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLMATH_VECTOR2I_H__
00024 #define __PLMATH_VECTOR2I_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLCore/String/String.h>
00032 #include "PLMath/PLMath.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLMath {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Classes                                               ]
00043 //[-------------------------------------------------------]
00044 /**
00045 *  @brief
00046 *    2D integer vector
00047 */
00048 class Vector2i {
00049 
00050 
00051     //[-------------------------------------------------------]
00052     //[ Public static data                                    ]
00053     //[-------------------------------------------------------]
00054     public:
00055         static PLMATH_API const Vector2i Zero;          /**<  0,  0 */
00056         static PLMATH_API const Vector2i One;           /**<  1,  1 */
00057         static PLMATH_API const Vector2i NegativeOne;   /**< -1, -1 */
00058         static PLMATH_API const Vector2i UnitX;         /**<  1,  0 */
00059         static PLMATH_API const Vector2i UnitY;         /**<  0,  1 */
00060         static PLMATH_API const Vector2i NegativeUnitX; /**< -1,  0 */
00061         static PLMATH_API const Vector2i NegativeUnitY; /**<  0, -1 */
00062 
00063 
00064     //[-------------------------------------------------------]
00065     //[ Public data                                           ]
00066     //[-------------------------------------------------------]
00067     public:
00068         /**
00069         *  @brief
00070         *    Some direct vector element accesses
00071         */
00072         union {
00073             /**
00074             *  @brief
00075             *    Vector element array access
00076             */
00077             int nV[2];
00078 
00079             /**
00080             *  @brief
00081             *    Known vector element names when dealing with positions or directions
00082             */
00083             struct {
00084                 int x, y;
00085             };
00086 
00087             /**
00088             *  @brief
00089             *    Known vector element names when dealing with sizes
00090             */
00091             struct {
00092                 int width, height;
00093             };
00094         };
00095 
00096 
00097     //[-------------------------------------------------------]
00098     //[ Public functions                                      ]
00099     //[-------------------------------------------------------]
00100     public:
00101         /**
00102         *  @brief
00103         *    Default constructor setting all components to 0
00104         */
00105         inline Vector2i();
00106 
00107         /**
00108         *  @brief
00109         *    Constructor
00110         *
00111         *  @param[in] nX
00112         *    X component
00113         *  @param[in] nY
00114         *    Y component
00115         */
00116         inline Vector2i(int nX, int nY);
00117 
00118         /**
00119         *  @brief
00120         *    Destructor
00121         */
00122         inline ~Vector2i();
00123 
00124         //[-------------------------------------------------------]
00125         //[ Get and set                                           ]
00126         //[-------------------------------------------------------]
00127         inline operator int *();
00128         inline operator const int *() const;
00129         inline int &operator [](int nIndex);
00130         inline const int &operator [](int nIndex) const;
00131 
00132         /**
00133         *  @brief
00134         *    Set vector
00135         *
00136         *  @param[in] nX
00137         *    X component
00138         *  @param[in] nY
00139         *    Y component
00140         */
00141         inline void Set(int nX, int nY);
00142 
00143         /**
00144         *  @brief
00145         *    Set X component
00146         *
00147         *  @param[in] nX
00148         *    X component
00149         */
00150         inline void SetX(int nX);
00151 
00152         /**
00153         *  @brief
00154         *    Set Y component
00155         *
00156         *  @param[in] nY
00157         *    Y component
00158         */
00159         inline void SetY(int nY);
00160 
00161         /**
00162         *  @brief
00163         *    Assignment operator
00164         *
00165         *  @param[in] vV
00166         *    Source vector to copy
00167         *
00168         *  @return
00169         *    This vector
00170         */
00171         inline Vector2i &operator =(const Vector2i &vV);
00172 
00173         /**
00174         *  @brief
00175         *    Compare operator
00176         *
00177         *  @param[in] vV
00178         *    Vector to compare with
00179         *
00180         *  @return
00181         *    'true' if equal, else 'false'
00182         */
00183         inline bool operator ==(const Vector2i &vV) const;
00184 
00185         /**
00186         *  @brief
00187         *    Compare operator
00188         *
00189         *  @param[in] vV
00190         *    Vector to compare with
00191         *
00192         *  @return
00193         *    'true' if not equal, else 'false'
00194         */
00195         inline bool operator !=(const Vector2i &vV) const;
00196 
00197         /**
00198         *  @brief
00199         *    Compares two vectors lexicographically
00200         *
00201         *  @param[in] vV
00202         *    Vector to compare with
00203         *
00204         *  @return
00205         *    'true' if ALL components of this vector are less, else 'false'
00206         *
00207         *  @note
00208         *    - A lexicographical order for 2-dimensional vectors is used (see http://en.wikipedia.org/wiki/Ordered_vector_space)
00209         */
00210         inline bool operator <(const Vector2i &vV) const;
00211 
00212         /**
00213         *  @brief
00214         *    Compares two vectors lexicographically
00215         *
00216         *  @param[in] vV
00217         *    Vector to compare with
00218         *
00219         *  @return
00220         *    'true' if ALL components of this vector are greater, else 'false'
00221         *
00222         *  @see
00223         *    - "operator <"
00224         */
00225         inline bool operator >(const Vector2i &vV) const;
00226 
00227         /**
00228         *  @brief
00229         *    Compares two vectors lexicographically
00230         *
00231         *  @param[in] vV
00232         *    Vector to compare with
00233         *
00234         *  @return
00235         *    'true' if ALL components of this vector are less or equal, else 'false'
00236         *
00237         *  @see
00238         *    - "operator <"
00239         */
00240         inline bool operator <=(const Vector2i &vV) const;
00241 
00242         /**
00243         *  @brief
00244         *    Compares two vectors lexicographically
00245         *
00246         *  @param[in] vV
00247         *    Vector to compare with
00248         *
00249         *  @return
00250         *    'true' if ALL components of this vector are greater or equal, else 'false'
00251         *
00252         *  @see
00253         *    - "operator <"
00254         */
00255         inline bool operator >=(const Vector2i &vV) const;
00256 
00257         /**
00258         *  @brief
00259         *    Addition operator
00260         *
00261         *  @param[in] vV
00262         *    Vector to add
00263         *
00264         *  @return
00265         *    The resulting vector
00266         */
00267         inline Vector2i operator +(const Vector2i &vV) const;
00268 
00269         /**
00270         *  @brief
00271         *    Addition operator
00272         *
00273         *  @param[in] vV
00274         *    Vector to add
00275         *
00276         *  @return
00277         *    This vector
00278         */
00279         inline Vector2i &operator +=(const Vector2i &vV);
00280 
00281         /**
00282         *  @brief
00283         *    Subtraction operator
00284         *
00285         *  @param[in] vV
00286         *    Vector to subtract
00287         *
00288         *  @return
00289         *    The resulting vector
00290         */
00291         inline Vector2i operator -(const Vector2i &vV) const;
00292 
00293         /**
00294         *  @brief
00295         *    Subtraction operator
00296         *
00297         *  @param[in] vV
00298         *    Vector to subtract
00299         *
00300         *  @return
00301         *    This vector
00302         */
00303         inline Vector2i &operator -=(const Vector2i &vV);
00304 
00305         /**
00306         *  @brief
00307         *    Multiplication operator
00308         *
00309         *  @param[in] fFactor
00310         *    Floating point factor
00311         *
00312         *  @return
00313         *    The resulting vector
00314         */
00315         inline Vector2i operator *(float fFactor) const;
00316 
00317         /**
00318         *  @brief
00319         *    Multiplication operator
00320         *
00321         *  @param[in] fFactor
00322         *    Floating point factor
00323         *
00324         *  @return
00325         *    This vector
00326         */
00327         inline Vector2i &operator *=(float fFactor);
00328 
00329         /**
00330         *  @brief
00331         *    Division operator
00332         *
00333         *  @param[in] fFactor
00334         *    Floating point divisor
00335         *
00336         *  @return
00337         *    The resulting vector
00338         */
00339         inline Vector2i operator /(float fFactor) const;
00340 
00341         /**
00342         *  @brief
00343         *    Division operator
00344         *
00345         *  @param[in] fFactor
00346         *    Floating point divisor
00347         *
00348         *  @return
00349         *    This vector
00350         */
00351         inline Vector2i &operator /=(float fFactor);
00352 
00353         /**
00354         *  @brief
00355         *    To string
00356         *
00357         *  @return
00358         *    String with the data
00359         */
00360         PLMATH_API PLCore::String ToString() const;
00361 
00362         /**
00363         *  @brief
00364         *    From string
00365         *
00366         *  @param[in] sString
00367         *    String with the data
00368         */
00369         PLMATH_API bool FromString(const PLCore::String &sString);
00370 
00371 
00372 };
00373 
00374 
00375 //[-------------------------------------------------------]
00376 //[ Namespace                                             ]
00377 //[-------------------------------------------------------]
00378 } // PLMath
00379 
00380 
00381 //[-------------------------------------------------------]
00382 //[ Implementation                                        ]
00383 //[-------------------------------------------------------]
00384 #include "PLMath/Vector2i.inl"
00385 #include "PLMath/TypeVector2i.inl"
00386 
00387 
00388 #endif // __PLMATH_VECTOR2I_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:01
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported