00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00079
00080
00081 DimensionF(float sourceWidth, float sourceHeight) :
00082 width(sourceWidth), height(sourceHeight){}
00083
00084
00085
00086
00087
00088 explicit DimensionF(float sourceArray[2]) :
00089 width(sourceArray[0]), height(sourceArray[1]){}
00090
00091
00092
00093
00094
00095 explicit DimensionF(const DimensionI& source);
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 inline void set(float sourceWidth, float sourceHeight){
00106 width = sourceWidth;
00107 height = sourceHeight;
00108 }
00109
00110
00111
00112
00113
00114 inline void set(float sourceArray[2]){
00115 width = sourceArray[0];
00116 height = sourceArray[1];
00117 }
00118
00119
00120
00121
00122
00123 void set(const DimensionI& source);
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 inline DimensionF operator +(const DimensionF& addDimension) const{
00134 return DimensionF(width + addDimension.width,
00135 height + addDimension.height);
00136 }
00137
00138
00139
00140
00141
00142
00143 inline DimensionF operator -(const DimensionF& subDimension) const{
00144 return DimensionF(width - subDimension.width,
00145 height - subDimension.height);
00146 }
00147
00148
00149
00150
00151
00152
00153 inline DimensionF operator *(const DimensionF& mulDimension) const{
00154 return DimensionF(width * mulDimension.width,
00155 height * mulDimension.height);
00156 }
00157
00158
00159
00160
00161
00162
00163 inline DimensionF operator *(float mulValue) const{
00164 return DimensionF(width * mulValue, height * mulValue);
00165 }
00166
00167
00168
00169
00170
00171
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
00182
00183 inline DimensionF operator +() const{ return *this; }
00184
00185
00186
00187
00188
00189 inline DimensionF operator -() const{ return DimensionF(-width, -height); }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 inline DimensionF& operator +=(const DimensionF& addDimension){
00200 width += addDimension.width;
00201 height += addDimension.height;
00202 return (*this);
00203 }
00204
00205
00206
00207
00208
00209
00210 inline DimensionF& operator -=(const DimensionF& subDimension){
00211 width -= subDimension.width;
00212 height -= subDimension.height;
00213 return (*this);
00214 }
00215
00216
00217
00218
00219
00220
00221 inline DimensionF& operator *=(const DimensionF& mulDimension){
00222 width *= mulDimension.width;
00223 height *= mulDimension.height;
00224 return (*this);
00225 }
00226
00227
00228
00229
00230
00231
00232 inline DimensionF& operator *=(float mulValue){
00233 width *= mulValue;
00234 height *= mulValue;
00235 return (*this);
00236 }
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 inline bool operator ==(const DimensionF& target) const{
00247 return ((width == target.width) && (height == target.height));
00248 }
00249
00250
00251
00252
00253
00254
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
00266
00267
00268 inline bool operator !=(const DimensionF& target) const{
00269 return ((width != target.width) || (height != target.height));
00270 }
00271
00272
00273
00274
00275
00276
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
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 }
00303 #endif // End of DIMENSION_F_H_
00304