00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 #include <claw/rectangle.hpp>
00031
00032
00036 template<class T>
00037 claw::math::box_2d<T>::box_2d()
00038 {
00039
00040 }
00041
00042
00047 template<class T>
00048 claw::math::box_2d<T>::box_2d( const self_type& that )
00049 : first_point(that.first_point), second_point(that.second_point)
00050 {
00051
00052 }
00053
00054
00059 template<class T>
00060 claw::math::box_2d<T>::box_2d( const rectangle<value_type>& that )
00061 : first_point(that.position),
00062 second_point(that.right(), that.bottom())
00063 {
00064
00065 }
00066
00067
00073 template<class T>
00074 claw::math::box_2d<T>::box_2d( const point_type& p1, const point_type& p2 )
00075 : first_point(p1), second_point(p2)
00076 {
00077
00078 }
00079
00080
00088 template<class T>
00089 claw::math::box_2d<T>::box_2d( const value_type& x1, const value_type& y1,
00090 const value_type& x2, const value_type& y2 )
00091 : first_point(x1, y1), second_point(x2, y2)
00092 {
00093
00094 }
00095
00096
00101 template<class T>
00102 bool claw::math::box_2d<T>::operator==(const self_type& that) const
00103 {
00104 return (first_point == that.first_point)
00105 && (second_point == that.second_point);
00106 }
00107
00108
00113 template<class T>
00114 bool claw::math::box_2d<T>::operator!=(const self_type& that) const
00115 {
00116 return !( *this == that );
00117 }
00118
00119
00124 template<class T>
00125 claw::math::box_2d<T>
00126 claw::math::box_2d<T>::operator+(const point_type& vect) const
00127 {
00128 return self_type( first_point + vect, second_point + vect );
00129 }
00130
00131
00136 template<class T>
00137 claw::math::box_2d<T>
00138 claw::math::box_2d<T>::operator-(const point_type& vect) const
00139 {
00140 return self_type( first_point - vect, second_point - vect );
00141 }
00142
00143
00148 template<class T>
00149 claw::math::box_2d<T>&
00150 claw::math::box_2d<T>::operator+=(const point_type& vect)
00151 {
00152 first_point += vect;
00153 second_point += vect;
00154 }
00155
00156
00161 template<class T>
00162 claw::math::box_2d<T>&
00163 claw::math::box_2d<T>::operator-=(const point_type& vect)
00164 {
00165 first_point -= vect;
00166 second_point -= vect;
00167 }
00168
00169
00173 template<class T>
00174 typename claw::math::box_2d<T>::value_type
00175 claw::math::box_2d<T>::width() const
00176 {
00177 if (first_point.x > second_point.x)
00178 return first_point.x - second_point.x + 1;
00179 else
00180 return second_point.x - first_point.x + 1;
00181 }
00182
00183
00187 template<class T>
00188 typename claw::math::box_2d<T>::value_type
00189 claw::math::box_2d<T>::height() const
00190 {
00191 if (first_point.y > second_point.y)
00192 return first_point.y - second_point.y + 1;
00193 else
00194 return second_point.y - first_point.y + 1;
00195 }