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

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

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