size_2d.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa AKIYAMA
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_GEOM_SIZE2D_H
00033 #define RCSC_GEOM_SIZE2D_H
00034 
00035 #include <ostream>
00036 #include <cmath>
00037 
00038 namespace rcsc {
00039 
00044 class Size2D {
00045 private:
00047     double M_length;
00048 
00050     double M_width;
00051 
00052 public:
00053 
00057     Size2D()
00058         : M_length( 0.0 )
00059         , M_width( 0.0 )
00060       { }
00061 
00067     Size2D( const double & length,
00068             const double & width )
00069         : M_length( std::fabs( length ) )
00070         , M_width( std::fabs( width ) )
00071       { }
00072 
00079     const
00080     Size2D & assign( const double & length,
00081                      const double & width )
00082       {
00083           M_length = std::fabs( length );
00084           M_width = std::fabs( width );
00085           return *this;
00086       }
00087 
00093     const
00094     Size2D & setLength( const double & length )
00095       {
00096           M_length = std::fabs( length );
00097           return *this;
00098       }
00099 
00105     const
00106     Size2D & setWidth( const double & width )
00107       {
00108           M_width = std::fabs( width );
00109           return *this;
00110       }
00111 
00116     const
00117     double & length() const
00118       {
00119           return M_length;
00120       }
00121 
00126     const
00127     double & width() const
00128       {
00129           return M_width;
00130       }
00131 
00136     double diagonal() const
00137       {
00138           return std::sqrt( length() * length()
00139                             + width() * width() );
00140       }
00141 
00147     std::ostream & print( std::ostream & os ) const
00148       {
00149           os << "(" << length() << ", " << width() << ")";
00150           return os;
00151       }
00152 
00153 };
00154 
00155 } // end of namespace
00156 
00157 #endif

librcscに対してThu May 1 15:41:20 2008に生成されました。  doxygen 1.5.0