fdpoint2d.hh

00001 // Copyright (C) 2001, 2002, 2003, 2004  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016 // Boston, MA 02110-1301, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
00027 
00028 #ifndef OLENA_CORE_FDPOINT2D_HH
00029 # define OLENA_CORE_FDPOINT2D_HH
00030 
00031 # include <iostream>
00032 
00033 # include <oln/core/abstract/image.hh>
00034 # include <oln/core/fpoint2d.hh>
00035 
00036 namespace oln {
00037 
00038   // fwd decl
00039   template <class F>
00040   class dfpoint2d;
00041 
00042 
00043 
00049   template<class F>
00050   struct dpoint_traits<fdpoint2d<F> >
00051   {
00052     enum { dim = 2 };
00053     typedef fpoint2d<F> point_type;
00054   };
00055 
00060   template <class F>
00061   class fdpoint2d
00062   {
00063   private:
00064 
00065     F coord_[2];
00066 
00067 
00068   public:
00069 
00070 
00071     typedef fdpoint2d<F> exact_type;
00072 
00073     fdpoint2d()
00074     {}
00075 
00077 
00078     fdpoint2d(F row, F col)
00079     {
00080       coord_[0] = row;
00081       coord_[1] = col;
00082     }
00083 
00085     fdpoint2d(const exact_type& p)
00086     {
00087       coord_[0] = p.row();
00088       coord_[1] = p.col();
00089     }
00090 
00092 
00093     F
00094     row() const
00095     {
00096       return coord_[0];
00097     }
00098 
00100 
00101     F&
00102     row()
00103     {
00104       return coord_[0];
00105     }
00106 
00108 
00109     F
00110     col() const
00111     {
00112       return coord_[1];
00113     }
00114 
00116 
00117     F&
00118     col()
00119     {
00120       return coord_[1];
00121     }
00122 
00123     static std::string
00124     name()
00125     {
00126       return "fdpoint2d";
00127     }
00128 
00129     exact_type
00130     operator+(const exact_type& dp) const
00131     {
00132       exact_type tmp(*this);
00133       tmp += dp;
00134       return tmp;
00135     }
00136 
00141     exact_type
00142     operator-() const
00143     {
00144       exact_type dp(-row(), -col());
00145       return dp;
00146     }
00147 
00148 
00153     exact_type
00154     operator-(const exact_type& dp) const
00155     {
00156       exact_type tmp = *this;
00157       tmp -= dp;
00158       return tmp;
00159     }
00160 
00161 
00166     exact_type&
00167     operator+=(const exact_type& dp)
00168     {
00169       row() += dp.row();
00170       col() += dp.col();
00171       return *this;
00172     }
00173 
00178     exact_type&
00179     operator-=(const exact_type& dp)
00180     {
00181       row() -= dp.row();
00182       col() -= dp.col();
00183       return *this;
00184     }
00185   };
00186 
00187 
00188 } // end of oln
00189 
00191 
00192 template <class F>
00193 inline std::ostream&
00194 operator<<(std::ostream& o, const oln::fdpoint2d<F> dp)
00195 {
00196   o << "(" << dp.row() << "," << dp.col() << ")" << std::endl;
00197   return o;
00198 }
00199 
00200 
00201 #endif // !OLENA_CORE_FDPOINT2D_HH

Generated on Tue Feb 20 20:18:52 2007 for Olena by  doxygen 1.5.1