00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031
00035 template<class T>
00036 claw::math::rectangle<T>::rectangle()
00037 {
00038
00039 }
00040
00041
00046 template<class T>
00047 template<class U>
00048 claw::math::rectangle<T>::rectangle( const rectangle<U>& that )
00049 : position(that.position), width(that.width), height(that.height)
00050 {
00051
00052 }
00053
00054
00059 template<class T>
00060 template<class U>
00061 claw::math::rectangle<T>::rectangle( const box_2d<U>& that )
00062 : position(that.left(), that.top()), width(that.width()),
00063 height(that.height())
00064 {
00065
00066 }
00067
00068
00076 template<class T>
00077 claw::math::rectangle<T>::rectangle
00078 ( const value_type& _x, const value_type& _y,
00079 const value_type& _width, const value_type& _height )
00080 : position(_x, _y), width(_width), height(_height)
00081 {
00082
00083 }
00084
00085
00092 template<class T>
00093 template<typename U>
00094 claw::math::rectangle<T>::rectangle
00095 ( const coordinate_2d<U>& pos, const value_type& _width,
00096 const value_type& _height )
00097 : position(pos), width(_width), height(_height)
00098 {
00099
00100 }
00101
00102
00108 template<class T>
00109 template<typename U>
00110 claw::math::rectangle<T>::rectangle
00111 ( const coordinate_2d<U>& pos, const coordinate_2d<U>& size )
00112 : position(pos), width(size.x), height(size.y)
00113 {
00114
00115 }
00116
00117
00137 template<class T>
00138 template<typename U>
00139 claw::math::rectangle<U> claw::math::rectangle<T>::cast_value_type_to() const
00140 {
00141 return claw::math::rectangle<U>
00142 ( position.cast_value_type_to<U>(), (U)width, (U)height );
00143 }
00144
00145
00149 template<class T>
00150 typename claw::math::rectangle<T>::value_type
00151 claw::math::rectangle<T>::area() const
00152 {
00153 return width * height;
00154 }
00155
00156
00161 template<class T>
00162 bool
00163 claw::math::rectangle<T>::includes( const coordinate_2d<value_type>& p ) const
00164 {
00165 return (position.x <= p.x) && (right() >= p.x)
00166 && (position.y <= p.y) && (bottom() >= p.y);
00167 }
00168
00169
00174 template<class T>
00175 bool claw::math::rectangle<T>::includes( const self_type& r ) const
00176 {
00177 box_2d<value_type> his_box(r);
00178
00179 return includes(his_box.first_point) && includes(his_box.second_point);
00180 }
00181
00182
00187 template<class T>
00188 bool claw::math::rectangle<T>::intersects( const self_type& r ) const
00189 {
00190 return (right() >= r.position.x)
00191 && (r.right() >= position.x)
00192 && (bottom() >= r.position.y)
00193 && (r.bottom() >= position.y);
00194 }
00195
00196
00201 template<class T>
00202 claw::math::rectangle<T>
00203 claw::math::rectangle<T>::intersection( const self_type& r ) const
00204 {
00205 self_type result;
00206
00207 if ( intersects(r) )
00208 {
00209 x_intersection(r, result);
00210 y_intersection(r, result);
00211 }
00212
00213 return result;
00214 }
00215
00216
00224 template<class T>
00225 void claw::math::rectangle<T>::set
00226 ( const value_type& new_x, const value_type& new_y,
00227 const value_type& new_width, const value_type& new_height )
00228 {
00229 position.x = new_x;
00230 position.y = new_y;
00231 width = new_width;
00232 height = new_height;
00233 }
00234
00235
00239 template<class T>
00240 typename claw::math::rectangle<T>::value_type
00241 claw::math::rectangle<T>::left() const
00242 {
00243 return position.x;
00244 }
00245
00246
00250 template<class T>
00251 typename claw::math::rectangle<T>::value_type
00252 claw::math::rectangle<T>::right() const
00253 {
00254 return position.x + width;
00255 }
00256
00257
00261 template<class T>
00262 typename claw::math::rectangle<T>::value_type
00263 claw::math::rectangle<T>::bottom() const
00264 {
00265 return position.y + height;
00266 }
00267
00268
00272 template<class T>
00273 typename claw::math::rectangle<T>::value_type
00274 claw::math::rectangle<T>::top() const
00275 {
00276 return position.y;
00277 }
00278
00279
00283 template<class T>
00284 claw::math::coordinate_2d< typename claw::math::rectangle<T>::value_type >
00285 claw::math::rectangle<T>::size() const
00286 {
00287 return claw::math::coordinate_2d<value_type>(width, height);
00288 }
00289
00290
00296 template<class T>
00297 void claw::math::rectangle<T>::x_intersection
00298 ( const self_type& r, self_type& result ) const
00299 {
00300 if (position.x <= r.position.x)
00301 {
00302 result.position.x = r.position.x;
00303
00304 if (right() >= r.right())
00305 result.width = r.width;
00306 else
00307 result.width = right() - r.position.x;
00308 }
00309 else
00310 r.x_intersection(*this, result);
00311
00312 }
00313
00314
00320 template<class T>
00321 void claw::math::rectangle<T>::y_intersection
00322 ( const self_type& r, self_type& result ) const
00323 {
00324 if (position.y <= r.position.y)
00325 {
00326 result.position.y = r.position.y;
00327
00328 if (bottom() >= r.bottom())
00329 result.height = r.height;
00330 else
00331 result.height = bottom() - r.position.y;
00332 }
00333 else
00334 r.y_intersection(*this, result);
00335
00336 }