00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2001, 2002, 2003 Stéphane Del Pino 00003 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2, or (at your option) 00007 // any later version. 00008 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: Edge.hpp,v 1.9 2007/05/20 23:02:47 delpinux Exp $ 00019 00020 00021 #ifndef LINE_HPP 00022 #define LINE_HPP 00023 00024 #include <Vertex.hpp> 00025 #include <utility> 00026 00040 class Edge 00041 { 00042 public: 00043 enum { 00044 NumberOfVertices = 2 00045 }; 00046 00047 typedef std::pair<Vertex*, Vertex*> Pair; 00048 private: 00049 Edge::Pair __verticesPair; 00051 size_t __reference; 00053 public: 00054 real_t lenght() const 00055 { 00056 return Norm(*__verticesPair.first - *__verticesPair.second); 00057 } 00058 00065 const size_t& reference() const 00066 { 00067 return __reference; 00068 } 00069 00076 size_t& reference() 00077 { 00078 return __reference; 00079 } 00080 00087 inline Vertex& operator() (const size_t& i) 00088 { 00089 ASSERT (i<2); 00090 switch(i) { 00091 case 0: 00092 return *(__verticesPair.first); 00093 case 1: 00094 return *(__verticesPair.second); 00095 } 00096 return *(__verticesPair.first); // Never reached 00097 } 00098 00105 inline const Vertex& operator() (const size_t& i) const 00106 { 00107 ASSERT (i<2); 00108 switch(i) { 00109 case 0: 00110 return *(__verticesPair.first); 00111 case 1: 00112 return *(__verticesPair.second); 00113 } 00114 return *(__verticesPair.first); // Never reached 00115 } 00116 00124 inline bool operator==(const Edge& e) const 00125 { 00126 return (__verticesPair==e.__verticesPair); 00127 } 00128 00136 inline bool operator<(const Edge& e) const 00137 { 00138 if (__verticesPair.first == e.__verticesPair.first) { 00139 return (__verticesPair.second < e.__verticesPair.second); 00140 } else { 00141 return (__verticesPair.first < e.__verticesPair.first); 00142 } 00143 } 00144 00152 inline const Edge& operator=(const Edge& e) 00153 { 00154 __verticesPair = e.__verticesPair; 00155 __reference = e.__reference; 00156 00157 return *this; 00158 } 00159 00161 inline operator Pair&() 00162 { 00163 return __verticesPair; 00164 } 00165 00172 inline operator const Pair&() const 00173 { 00174 return __verticesPair; 00175 } 00176 00184 Vertex* firstCommonVertex(const Edge::Pair& e) const 00185 { 00186 if ((__verticesPair.first == e.first) 00187 or (__verticesPair.first == e.second)) { 00188 return __verticesPair.first; 00189 } 00190 00191 if ((__verticesPair.second == e.first) 00192 or (__verticesPair.second == e.second)) { 00193 return __verticesPair.second; 00194 } 00195 00196 return 0; 00197 } 00198 00204 Edge() 00205 { 00206 ; 00207 } 00208 00214 Edge(const Edge& E) 00215 : __verticesPair(E.__verticesPair), 00216 __reference(E.__reference) 00217 { 00218 ; 00219 } 00220 00232 Edge(const Vertex& v1, const Vertex& v2, 00233 const size_t& reference=0) 00234 : __reference(reference) 00235 { 00236 Vertex* V1 = const_cast<Vertex*>((&v1<&v2) ? &v1 : &v2); 00237 Vertex* V2 = const_cast<Vertex*>((&v1>&v2) ? &v1 : &v2); 00238 __verticesPair = Pair(V1, V2); 00239 } 00240 00247 Edge(const Edge::Pair& vp, 00248 const size_t& reference=0) 00249 : __verticesPair(vp), 00250 __reference(reference) 00251 { 00252 ; 00253 } 00254 00259 ~Edge() 00260 { 00261 ; 00262 } 00263 00272 friend std::ostream& operator << (std::ostream& os, 00273 const Edge& e); 00274 }; 00275 00276 #endif // LINE_HPP 00277
1.5.6