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

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

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