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

RectangleF.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 RECTANGLE_F_H_
00026 #define RECTANGLE_F_H_
00027 
00028 namespace Lamp{
00029 
00030 class RectangleI;
00031 
00032 //------------------------------------------------------------------------------
00033 /**
00034  * 実数矩形
00035  *
00036  * このクラスは継承しないで下さい。
00037  */
00038 class RectangleF{
00039 public:
00040     //--------------------------------------------------------------------------
00041     // メンバ変数
00042     //--------------------------------------------------------------------------
00043     /// メンバ変数
00044     union{
00045         /// 各要素
00046         struct{
00047             /// X値
00048             float x;
00049             /// Y値
00050             float y;
00051             /// 幅
00052             float width;
00053             /// 高さ
00054             float height;
00055         };
00056 
00057         /// 配列
00058         float array[4];
00059     };
00060 
00061     //--------------------------------------------------------------------------
00062     // 定数
00063     //--------------------------------------------------------------------------
00064     /// ゼロ矩形
00065     static const RectangleF zero;
00066 
00067     /// 単位矩形
00068     static const RectangleF unit;
00069 
00070     //--------------------------------------------------------------------------
00071     // コンストラクタ
00072     //--------------------------------------------------------------------------
00073     /**
00074      * コンストラクタ
00075      *
00076      * このコンストラクタは初期値の設定を行わないため値は不定です。
00077      */
00078     RectangleF(){}
00079 
00080     /**
00081      * コンストラクタ
00082      * @param sourceX X値の初期値
00083      * @param sourceY Y値の初期値
00084      * @param sourceWidth 幅の初期値
00085      * @param sourceHeight 高さの初期値
00086      */
00087     RectangleF(float sourceX, float sourceY,
00088         float sourceWidth, float sourceHeight) :
00089         x(sourceX), y(sourceY), width(sourceWidth), height(sourceHeight){}
00090 
00091     /**
00092      * コンストラクタ
00093      * @param sourceArray 初期値配列
00094      */
00095     explicit RectangleF(float sourceArray[4]) :
00096         x(sourceArray[0]), y(sourceArray[1]),
00097         width(sourceArray[2]), height(sourceArray[3]){}
00098 
00099     /**
00100      * コンストラクタ
00101      * @param source 設定する矩形
00102      */
00103     explicit RectangleF(const RectangleI& source);
00104 
00105     //--------------------------------------------------------------------------
00106     // 値の設定
00107     //--------------------------------------------------------------------------
00108     /**
00109      * 値の設定
00110      * @param sourceX X値の設定値
00111      * @param sourceY Y値の設定値
00112      * @param sourceWidth 幅の設定値
00113      * @param sourceHeight 高さの設定値
00114      */
00115     inline void set(float sourceX, float sourceY,
00116         float sourceWidth, float sourceHeight){
00117         x = sourceX;
00118         y = sourceY;
00119         width = sourceWidth;
00120         height = sourceHeight;
00121     }
00122 
00123     /**
00124      * 値の設定
00125      * @param sourceArray 設定値配列
00126      */
00127     inline void set(float sourceArray[4]){
00128         x = sourceArray[0];
00129         y = sourceArray[1];
00130         width = sourceArray[2];
00131         height = sourceArray[3];
00132     }
00133 
00134     /**
00135      * 値の設定
00136      * @param source 設定する矩形
00137      */
00138     void set(const RectangleI& source);
00139 
00140     //--------------------------------------------------------------------------
00141     // 論理演算
00142     //--------------------------------------------------------------------------
00143     /**
00144      * 同じ値かどうか
00145      * @param target 比較する矩形
00146      * @return 同じ値であればtrueを返す
00147      */
00148     inline bool operator ==(const RectangleF& target) const{
00149         return ((x == target.x) && (y == target.y) &&
00150             (width == target.width) && (height == target.height));
00151     }
00152 
00153     /**
00154      * 同じ値かどうか
00155      * @param target 比較する矩形
00156      * @param epsilon 誤差
00157      * @return 誤差の範囲内で同じ値であればtrueを返す
00158      */
00159     inline bool epsilonEquals(const RectangleF& target, float epsilon) const{
00160         Assert(epsilon >= 0.f);
00161         return (
00162             (Math::abs(x - target.x) <= epsilon) &&
00163             (Math::abs(y - target.y) <= epsilon) &&
00164             (Math::abs(width - target.width) <= epsilon) &&
00165             (Math::abs(height - target.height) <= epsilon));
00166     }
00167 
00168     /**
00169      * 同じ値でないかどうか
00170      * @param target 比較する矩形
00171      * @return 同じ値でなければtrueを返す
00172      */
00173     inline bool operator !=(const RectangleF& target) const{
00174         return ((x != target.x) || (y != target.y) ||
00175             (width != target.width) || (height != target.height));
00176     }
00177 
00178     /**
00179      * 同じ値でないかどうか
00180      * @param target 比較する矩形
00181      * @param epsilon 誤差
00182      * @return 誤差の範囲内で同じでない値であればtrueを返す
00183      */
00184     inline bool notEpsilonEquals(
00185         const RectangleF& target, float epsilon) const{
00186         Assert(epsilon >= 0.f);
00187         return (
00188             (Math::abs(x - target.x) > epsilon) ||
00189             (Math::abs(y - target.y) > epsilon) ||
00190             (Math::abs(width - target.width) > epsilon) ||
00191             (Math::abs(height - target.height) > epsilon));
00192     }
00193 
00194     //--------------------------------------------------------------------------
00195     // その他
00196     //--------------------------------------------------------------------------
00197     /**
00198      * 文字列化
00199      * @return 矩形の文字列表記
00200      */
00201     inline String toString() const{
00202         String returnString;
00203         returnString.format("( %.8f, %.8f, %.8f, %.8f )", x, y, width, height);
00204         return returnString;
00205     }
00206 
00207 };
00208 
00209 //------------------------------------------------------------------------------
00210 } // End of namespace Lamp
00211 #endif // End of RECTANGLE_F_H_
00212 //------------------------------------------------------------------------------

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