box_2d.tpp

Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2008 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
00024 */
00030 #include <claw/rectangle.hpp>
00031 
00032 /*----------------------------------------------------------------------------*/
00036 template<class T>
00037 claw::math::box_2d<T>::box_2d()
00038 {
00039 
00040 } // box_2d::box_2d() [constructor]
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 } // box_2d::box_2d() [copy constructor]
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 } // box_2d::box_2d() [constructor from rectangle]
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 } // box_2d::box_2d() [constructor from coordinates]
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 } // box_2d::box_2d() [constructor with values]
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 } // box_2d::operator==()
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 } // box_2d::operator!=()
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 } // box_2d::operator+()
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 } // box_2d::operator-()
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 } // box_2d::operator+=()
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 } // box_2d::operator-=()
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 } // box_2d::width()
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 } // box_2d::height()

Generated on Thu Jun 26 09:35:04 2008 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.5.6