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

DimensionI.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 DIMENSION_I_H_
00026 #define DIMENSION_I_H_
00027 
00028 namespace Lamp{
00029 
00030 class DimensionF;
00031 
00032 //------------------------------------------------------------------------------
00033 /**
00034  * 整数寸法
00035  *
00036  * このクラスは継承しないで下さい。
00037  */
00038 class DimensionI{
00039 public:
00040     //--------------------------------------------------------------------------
00041     // メンバ変数
00042     //--------------------------------------------------------------------------
00043     /// メンバ変数
00044     union{
00045         /// 各要素
00046         struct{
00047             /// 幅
00048             int width;
00049             /// 高さ
00050             int height;
00051         };
00052 
00053         /// 配列
00054         int array[2];
00055     };
00056 
00057     //--------------------------------------------------------------------------
00058     // 定数
00059     //--------------------------------------------------------------------------
00060     /// ゼロ寸法
00061     static const DimensionI zero;
00062 
00063     /// 単位寸法
00064     static const DimensionI unit;
00065 
00066     //--------------------------------------------------------------------------
00067     // コンストラクタ
00068     //--------------------------------------------------------------------------
00069     /**
00070      * コンストラクタ
00071      *
00072      * このコンストラクタは初期値の設定を行わないため値は不定です。
00073      */
00074     DimensionI(){}
00075 
00076     /**
00077      * コンストラクタ
00078      * @param sourceWidth 幅の初期値
00079      * @param sourceHeight 高さの初期値
00080      */
00081     DimensionI(int sourceWidth, int sourceHeight) :
00082         width(sourceWidth), height(sourceHeight){}
00083 
00084     /**
00085      * コンストラクタ
00086      * @param sourceArray 初期値配列
00087      */
00088     explicit DimensionI(int sourceArray[2]) :
00089         width(sourceArray[0]), height(sourceArray[1]){}
00090 
00091     /**
00092      * コンストラクタ
00093      * @param source 設定する寸法
00094      */
00095     explicit DimensionI(const DimensionF& source);
00096 
00097     //--------------------------------------------------------------------------
00098     // 値の設定
00099     //--------------------------------------------------------------------------
00100     /**
00101      * 値の設定
00102      * @param sourceWidth 幅の設定値
00103      * @param sourceHeight 高さの設定値
00104      */
00105     inline void set(int sourceWidth, int sourceHeight){
00106         width = sourceWidth;
00107         height = sourceHeight;
00108     }
00109 
00110     /**
00111      * 値の設定
00112      * @param sourceArray 設定値配列
00113      */
00114     inline void set(int sourceArray[2]){
00115         width = sourceArray[0];
00116         height = sourceArray[1];
00117     }
00118 
00119     /**
00120      * 値の設定
00121      * @param source 設定する寸法
00122      */
00123     void set(const DimensionF& source);
00124 
00125     //--------------------------------------------------------------------------
00126     // 演算
00127     //--------------------------------------------------------------------------
00128     /**
00129      * 加算
00130      * @param addDimension 加算する寸法
00131      * @return 加算された寸法
00132      */
00133     inline DimensionI operator +(const DimensionI& addDimension) const{
00134         return DimensionI(width + addDimension.width,
00135             height + addDimension.height);
00136     }
00137 
00138     /**
00139      * 減算
00140      * @param subDimension 減算する寸法
00141      * @return 減算された寸法
00142      */
00143     inline DimensionI operator -(const DimensionI& subDimension) const{
00144         return DimensionI(width - subDimension.width,
00145             height - subDimension.height);
00146     }
00147 
00148     /**
00149      * 乗算
00150      * @param mulDimension 乗算する寸法
00151      * @return 乗算された寸法
00152      */
00153     inline DimensionI operator *(const DimensionI& mulDimension) const{
00154         return DimensionI(width * mulDimension.width,
00155             height * mulDimension.height);
00156     }
00157 
00158     /**
00159      * 乗算
00160      * @param mulValue 乗算する値
00161      * @return 乗算された寸法
00162      */
00163     inline DimensionI operator *(float mulValue) const{
00164         return DimensionI((int)(width * mulValue), (int)(height * mulValue));
00165     }
00166 
00167     /**
00168      * 乗算
00169      * @param mulValue 乗算する値
00170      * @param mulDimension 乗算される寸法
00171      * @return 乗算された寸法
00172      */
00173     inline friend DimensionI operator *(
00174         float mulValue, const DimensionI& mulDimension){
00175         return DimensionI((int)(mulDimension.width * mulValue),
00176             (int)(mulDimension.height * mulValue));
00177     }
00178 
00179     /**
00180      * 乗算
00181      * @param mulValue 乗算する値
00182      * @return 乗算された寸法
00183      */
00184     inline DimensionI operator *(int mulValue) const{
00185         return DimensionI(width * mulValue, height * mulValue);
00186     }
00187 
00188     /**
00189      * 乗算
00190      * @param mulValue 乗算する値
00191      * @param mulDimension 乗算される寸法
00192      * @return 乗算された寸法
00193      */
00194     inline friend DimensionI operator *(
00195         int mulValue, const DimensionI& mulDimension){
00196         return DimensionI(mulDimension.width * mulValue,
00197             mulDimension.height * mulValue);
00198     }
00199 
00200     /**
00201      * +演算子
00202      * @return 寸法のコピー
00203      */
00204     inline DimensionI operator +() const{ return *this; }
00205 
00206     /**
00207      * -演算子
00208      * @return 値の符号が反転した寸法
00209      */
00210     inline DimensionI operator -() const{ return DimensionI(-width, -height); }
00211 
00212     //--------------------------------------------------------------------------
00213     // 代入演算
00214     //--------------------------------------------------------------------------
00215     /**
00216      * 代入加算
00217      * @param addDimension 加算する寸法
00218      * @return 加算された寸法
00219      */
00220     inline DimensionI& operator +=(const DimensionI& addDimension){
00221         width += addDimension.width;
00222         height += addDimension.height;
00223         return (*this);
00224     }
00225 
00226     /**
00227      * 代入減算
00228      * @param subDimension 減算する寸法
00229      * @return 減算された寸法
00230      */
00231     inline DimensionI& operator -=(const DimensionI& subDimension){
00232         width -= subDimension.width;
00233         height -= subDimension.height;
00234         return (*this);
00235     }
00236 
00237     /**
00238      * 代入乗算
00239      * @param mulDimension 乗算する寸法
00240      * @return 乗算された寸法
00241      */
00242     inline DimensionI& operator *=(const DimensionI& mulDimension){
00243         width *= mulDimension.width;
00244         height *= mulDimension.height;
00245         return (*this);
00246     }
00247 
00248     /**
00249      * 代入乗算
00250      * @param mulValue 乗算する値
00251      * @return 乗算された寸法
00252      */
00253     inline DimensionI& operator *=(float mulValue){
00254         width = (int)(width * mulValue);
00255         height = (int)(height * mulValue);
00256         return (*this);
00257     }
00258 
00259     /**
00260      * 代入乗算
00261      * @param mulValue 乗算する値
00262      * @return 乗算された寸法
00263      */
00264     inline DimensionI& operator *=(int mulValue){
00265         width *= mulValue;
00266         height *= mulValue;
00267         return (*this);
00268     }
00269 
00270     //--------------------------------------------------------------------------
00271     // 論理演算
00272     //--------------------------------------------------------------------------
00273     /**
00274      * 同じ値かどうか
00275      * @param target 比較する寸法
00276      * @return 同じ値であればtrueを返す
00277      */
00278     inline bool operator ==(const DimensionI& target) const{
00279         return ((width == target.width) && (height == target.height));
00280     }
00281 
00282     /**
00283      * 同じ値でないかどうか
00284      * @param target 比較する寸法
00285      * @return 同じ値でなければtrueを返す
00286      */
00287     inline bool operator !=(const DimensionI& target) const{
00288         return ((width != target.width) || (height != target.height));
00289     }
00290 
00291     //--------------------------------------------------------------------------
00292     // その他
00293     //--------------------------------------------------------------------------
00294     /**
00295      * 文字列化
00296      * @return 寸法の文字列表記
00297      */
00298     inline String toString() const{
00299         String returnString;
00300         returnString.format("( %d, %d )", width, height);
00301         return returnString;
00302     }
00303 
00304 };
00305 
00306 //------------------------------------------------------------------------------
00307 } // End of namespace Lamp
00308 #endif // End of DIMENSION_I_H_
00309 //------------------------------------------------------------------------------

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