00001 // Copyright (C) 2001, 2002, 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_POINT2D_HXX 00029 # define OLENA_CORE_POINT2D_HXX 00030 00031 # include <oln/core/point1d.hh> 00032 # include <oln/core/dpoint2d.hh> 00033 # include <iostream> 00034 00035 00036 namespace oln { 00037 00038 inline 00039 point2d::point2d() 00040 { 00041 nth(0) = 0; 00042 nth(1) = 0; 00043 } 00044 00045 inline 00046 point2d::point2d(coord row, coord col) 00047 { 00048 nth(0) = row; 00049 nth(1) = col; 00050 } 00051 00052 inline 00053 point2d::point2d(const point1d& p, coord row) 00054 { 00055 nth(0) = row; 00056 nth(1) = p.col(); 00057 } 00058 00059 inline coord 00060 point2d::row() const 00061 { 00062 return nth(0); 00063 } 00064 00065 inline coord& 00066 point2d::row() 00067 { 00068 return nth(0); 00069 } 00070 00071 inline coord 00072 point2d::col() const 00073 { 00074 return nth(1); 00075 } 00076 00077 inline coord& 00078 point2d::col() 00079 { 00080 return nth(1); 00081 } 00082 00083 inline point2d& 00084 point2d::plus_assign_dp(const dpoint2d& dp) 00085 { 00086 row() += dp.row(); 00087 col() += dp.col(); 00088 return *this; 00089 } 00090 00091 inline point2d& 00092 point2d::minus_assign_dp(const dpoint2d& dp) 00093 { 00094 row() -= dp.row(); 00095 col() -= dp.col(); 00096 return *this; 00097 } 00098 00099 inline dpoint2d 00100 point2d::minus_p(const point2d& p) const 00101 { 00102 dpoint2d dp(row() - p.row(), col() - p.col()); 00103 return dp; 00104 } 00105 00106 inline point2d 00107 point2d::plus_dp(const dpoint2d& dp) const 00108 { 00109 point2d p = *this; 00110 p += dp; 00111 return p; 00112 } 00113 00114 inline point2d 00115 point2d::minus_dp(const dpoint2d& dp) const 00116 { 00117 point2d p = *this; 00118 p -= dp; 00119 return p; 00120 } 00121 00122 inline point2d 00123 point2d::minus() const 00124 { 00125 point2d p(-row(), -col()); 00126 return p; 00127 } 00128 00129 00130 } // end of oln 00131 00132 00133 inline std::ostream& 00134 operator<<(std::ostream& o, const oln::point2d& p) 00135 { 00136 return o << '(' << p.row() << ',' << p.col() << ')'; 00137 } 00138 00139 00140 00141 #endif // ! OLENA_CORE_POINT2D_HXX