Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

Point2i.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * 二要素整数位置ヘッダ
00022  * @author Junpee
00023  */
00024 
00025 #ifndef POINT_2I_H_
00026 #define POINT_2I_H_
00027 
00028 namespace Lamp{
00029 
00030 class Point2f;
00031 
00032 //------------------------------------------------------------------------------
00033 /**
00034  * 二要素整数位置
00035  *
00036  * このクラスは継承しないで下さい。
00037  */
00038 class Point2i{
00039 public:
00040     //--------------------------------------------------------------------------
00041     // メンバ変数
00042     //--------------------------------------------------------------------------
00043     /// メンバ変数
00044     union{
00045         /// 各要素
00046         struct{
00047             /// X値
00048             int x;
00049             /// Y値
00050             int y;
00051         };
00052 
00053         /// 配列
00054         int array[2];
00055     };
00056 
00057     //--------------------------------------------------------------------------
00058     // 定数
00059     //--------------------------------------------------------------------------
00060     /// ゼロ位置
00061     static const Point2i zero;
00062 
00063     /// 単位位置
00064     static const Point2i unit;
00065 
00066     //--------------------------------------------------------------------------
00067     // コンストラクタ
00068     //--------------------------------------------------------------------------
00069     /**
00070      * コンストラクタ
00071      *
00072      * このコンストラクタは初期値の設定を行わないため値は不定です。
00073      */
00074     Point2i(){}
00075 
00076     /**
00077      * コンストラクタ
00078      * @param sourceX X値の初期値
00079      * @param sourceY Y値の初期値
00080      */
00081     Point2i(int sourceX, int sourceY) : x(sourceX), y(sourceY){}
00082 
00083     /**
00084      * コンストラクタ
00085      * @param sourceArray 初期値配列
00086      */
00087     explicit Point2i(int sourceArray[2]) :
00088         x(sourceArray[0]), y(sourceArray[1]){}
00089 
00090     /**
00091      * コンストラクタ
00092      * @param source 初期化する位置
00093      */
00094     explicit Point2i(const Point2f& source);
00095 
00096     //--------------------------------------------------------------------------
00097     // 値の設定
00098     //--------------------------------------------------------------------------
00099     /**
00100      * 値の設定
00101      * @param sourceX X値の設定値
00102      * @param sourceY Y値の設定値
00103      */
00104     inline void set(int sourceX, int sourceY){
00105         x = sourceX;
00106         y = sourceY;
00107     }
00108 
00109     /**
00110      * 値の設定
00111      * @param sourceArray 設定値配列
00112      */
00113     inline void set(int sourceArray[2]){
00114         x = sourceArray[0];
00115         y = sourceArray[1];
00116     }
00117 
00118     /**
00119      * 値の設定
00120      * @param source 設定する位置
00121      */
00122     void set(const Point2f& source);
00123 
00124     //--------------------------------------------------------------------------
00125     // 演算
00126     //--------------------------------------------------------------------------
00127     /**
00128      * 加算
00129      * @param addPoint 加算する位置
00130      * @return 加算された位置
00131      */
00132     inline Point2i operator +(const Point2i& addPoint) const{
00133         return Point2i(x + addPoint.x, y + addPoint.y);
00134     }
00135 
00136     /**
00137      * 減算
00138      * @param subPoint 減算する位置
00139      * @return 減算された位置
00140      */
00141     inline Point2i operator -(const Point2i& subPoint) const{
00142         return Point2i(x - subPoint.x, y - subPoint.y);
00143     }
00144 
00145     /**
00146      * 乗算
00147      * @param mulPoint 乗算する位置
00148      * @return 乗算された位置
00149      */
00150     inline Point2i operator *(const Point2i& mulPoint) const{
00151         return Point2i(x * mulPoint.x, y * mulPoint.y);
00152     }
00153 
00154     /**
00155      * 乗算
00156      * @param mulValue 乗算する値
00157      * @return 乗算された位置
00158      */
00159     inline Point2i operator *(float mulValue) const{
00160         return Point2i((int)(x * mulValue), (int)(y * mulValue));
00161     }
00162 
00163     /**
00164      * 乗算
00165      * @param mulValue 乗算する値
00166      * @param mulPoint 乗算される位置
00167      * @return 乗算された位置
00168      */
00169     inline friend Point2i operator *(float mulValue, const Point2i& mulPoint){
00170         return Point2i((int)(mulPoint.x * mulValue),
00171             (int)(mulPoint.y * mulValue));
00172     }
00173 
00174     /**
00175      * 乗算
00176      * @param mulValue 乗算する値
00177      * @return 乗算された位置
00178      */
00179     inline Point2i operator *(int mulValue) const{
00180         return Point2i(x * mulValue, y * mulValue);
00181     }
00182 
00183     /**
00184      * 乗算
00185      * @param mulValue 乗算する値
00186      * @param mulPoint 乗算される位置
00187      * @return 乗算された位置
00188      */
00189     inline friend Point2i operator *(int mulValue, const Point2i& mulPoint){
00190         return Point2i(mulPoint.x * mulValue, mulPoint.y * mulValue);
00191     }
00192 
00193     /**
00194      * +演算子
00195      * @return 位置のコピー
00196      */
00197     inline Point2i operator +() const{ return *this; }
00198 
00199     /**
00200      * -演算子
00201      * @return 値の符号が反転した位置
00202      */
00203     inline Point2i operator -() const{ return Point2i(-x, -y); }
00204 
00205     //--------------------------------------------------------------------------
00206     // 代入演算
00207     //--------------------------------------------------------------------------
00208     /**
00209      * 代入加算
00210      * @param addPoint 加算する位置
00211      * @return 加算された位置
00212      */
00213     inline Point2i& operator +=(const Point2i& addPoint){
00214         x += addPoint.x;
00215         y += addPoint.y;
00216         return (*this);
00217     }
00218 
00219     /**
00220      * 代入減算
00221      * @param subPoint 減算する位置
00222      * @return 減算された位置
00223      */
00224     inline Point2i& operator -=(const Point2i& subPoint){
00225         x -= subPoint.x;
00226         y -= subPoint.y;
00227         return (*this);
00228     }
00229 
00230     /**
00231      * 代入乗算
00232      * @param mulPoint 乗算する位置
00233      * @return 乗算された位置
00234      */
00235     inline Point2i& operator *=(const Point2i& mulPoint){
00236         x *= mulPoint.x;
00237         y *= mulPoint.y;
00238         return (*this);
00239     }
00240 
00241     /**
00242      * 代入乗算
00243      * @param mulValue 乗算する値
00244      * @return 乗算された位置
00245      */
00246     inline Point2i& operator *=(float mulValue){
00247         x = (int)(x * mulValue);
00248         y = (int)(y * mulValue);
00249         return (*this);
00250     }
00251 
00252     /**
00253      * 代入乗算
00254      * @param mulValue 乗算する値
00255      * @return 乗算された位置
00256      */
00257     inline Point2i& operator *=(int mulValue){
00258         x *= mulValue;
00259         y *= mulValue;
00260         return (*this);
00261     }
00262 
00263     //--------------------------------------------------------------------------
00264     // 論理演算
00265     //--------------------------------------------------------------------------
00266     /**
00267      * 同じ値かどうか
00268      * @param target 比較する位置
00269      * @return 同じ値であればtrueを返す
00270      */
00271     inline bool operator ==(const Point2i& target) const{
00272         return ((x == target.x) && (y == target.y));
00273     }
00274 
00275     /**
00276      * 同じ値でないかどうか
00277      * @param target 比較する位置
00278      * @return 同じ値でなければtrueを返す
00279      */
00280     inline bool operator !=(const Point2i& target) const{
00281         return ((x != target.x) || (y != target.y));
00282     }
00283 
00284     //--------------------------------------------------------------------------
00285     // その他
00286     //--------------------------------------------------------------------------
00287     /**
00288      * 文字列化
00289      * @return 位置の文字列表記
00290      */
00291     inline String toString() const{
00292         String returnString;
00293         returnString.format("( %d, %d )", x, y);
00294         return returnString;
00295     }
00296 
00297 };
00298 
00299 //------------------------------------------------------------------------------
00300 } // End of namespace Lamp
00301 #endif // End of POINT_2I_H_
00302 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:33 2005 for Lamp by doxygen 1.3.2