|
BWAPI
|
00001 // Copyright (c) 2005 Tel-Aviv University (Israel). 00002 // All rights reserved. 00003 // 00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under 00005 // the terms of the Q Public License version 1.0. 00006 // See the file LICENSE.QPL distributed with CGAL. 00007 // 00008 // Licensees holding a valid commercial license may use this file in 00009 // accordance with the commercial license agreement provided with the software. 00010 // 00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 // 00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Boolean_set_operations_2/include/CGAL/Polygon_with_holes_2.h $ 00015 // $Id: Polygon_with_holes_2.h 28567 2006-02-16 14:30:13Z lsaboret $ 00016 // 00017 // 00018 // Author(s) : Baruch Zukerman <baruchzu@post.tau.ac.il> 00019 00020 #ifndef CGAL_POLYGON_WITH_HOLES_2_H 00021 #define CGAL_POLYGON_WITH_HOLES_2_H 00022 00023 #include <CGAL/Polygon_2.h> 00024 #include <CGAL/General_polygon_with_holes_2.h> 00025 #include <vector> 00026 #include <algorithm> 00027 00028 CGAL_BEGIN_NAMESPACE 00029 00030 template <class Kernel, 00031 class Containter = std::vector<typename Kernel::Point_2> > 00032 class Polygon_with_holes_2 : 00033 public General_polygon_with_holes_2<CGAL::Polygon_2<Kernel, Containter> > 00034 { 00035 public: 00036 00037 typedef CGAL::Polygon_2<Kernel, Containter> Polygon_2; 00038 typedef General_polygon_with_holes_2<Polygon_2> Base; 00039 typedef typename Base::Hole_const_iterator Hole_const_iterator; 00040 typedef typename Base::Size Size; 00041 00043 Polygon_with_holes_2 () : 00044 Base() 00045 {} 00046 00048 Polygon_with_holes_2 (const Base& base) : 00049 Base (base) 00050 {} 00051 00053 explicit Polygon_with_holes_2 (const Polygon_2& pgn_boundary) : 00054 Base (pgn_boundary) 00055 {} 00056 00058 template <class HolesInputIterator> 00059 Polygon_with_holes_2 (const Polygon_2& pgn_boundary, 00060 HolesInputIterator h_begin, 00061 HolesInputIterator h_end) : 00062 Base (pgn_boundary, h_begin, h_end) 00063 {} 00064 00065 }; 00066 00067 //-----------------------------------------------------------------------// 00068 // operator<< 00069 //-----------------------------------------------------------------------// 00070 00071 template <class Kernel_, class Container_> 00072 std::ostream& operator<<(std::ostream &os, 00073 const Polygon_with_holes_2<Kernel_, Container_>& p) 00074 { 00075 typename Polygon_with_holes_2<Kernel_,Container_>::Hole_const_iterator i; 00076 00077 switch(os.iword(IO::mode)) { 00078 case IO::ASCII : 00079 os << p.outer_boundary() << ' ' << p.number_of_holes()<<' '; 00080 for (i = p.holes_begin(); i != p.holes_end(); ++i) { 00081 os << *i << ' '; 00082 } 00083 return os; 00084 00085 case IO::BINARY : 00086 os << p.outer_boundary() << p.number_of_holes(); 00087 for (i = p.holes_begin(); i != p.holes_end(); ++i) { 00088 os << *i ; 00089 } 00090 return os; 00091 00092 default: 00093 os << "Polygon_with_holes_2(" << std::endl; 00094 if(p.is_unbounded()) 00095 os << "No outer bounary" << std::endl; 00096 else 00097 { 00098 os << "Boundary(" << std::endl; 00099 os << p.outer_boundary() << std::endl; 00100 } 00101 00102 os << "Holes" << std::endl; 00103 os << p.number_of_holes()<<std::endl; 00104 for (i = p.holes_begin(); i != p.holes_end(); ++i) { 00105 os <<" "<< *i << std::endl; 00106 } 00107 00108 os << ")" << std::endl; 00109 return os; 00110 } 00111 } 00112 00113 //-----------------------------------------------------------------------// 00114 // operator>> 00115 //-----------------------------------------------------------------------// 00116 00117 template <class Kernel_, class Container_> 00118 std::istream &operator>>(std::istream &is, 00119 Polygon_with_holes_2<Kernel_, Container_>& p) 00120 { 00121 typedef CGAL::Polygon_2<Kernel_, Container_> Polygon_2; 00122 p.clear(); 00123 is >> p.outer_boundary(); 00124 00125 unsigned int n; // number of holes; 00126 is >> n; 00127 if(is) 00128 { 00129 for (unsigned int i=0; i<n; i++) 00130 { 00131 Polygon_2 hole; 00132 is >> hole; 00133 p.add_hole(hole); 00134 } 00135 } 00136 00137 return is; 00138 } 00139 00140 00141 //-----------------------------------------------------------------------// 00142 // operator== 00143 //-----------------------------------------------------------------------// 00144 template <class Kernel_, class Container_> 00145 bool operator==(const Polygon_with_holes_2<Kernel_, Container_>& p1, 00146 const Polygon_with_holes_2<Kernel_, Container_>& p2) 00147 { 00148 typedef typename 00149 Polygon_with_holes_2<Kernel_, Container_>::Hole_const_iterator HCI; 00150 typedef CGAL::Polygon_2<Kernel_, Container_> Polygon_2; 00151 if(&p1 == &p2) 00152 return (true); 00153 00154 if(p1.number_of_holes() != p2.number_of_holes()) 00155 return (false); 00156 00157 if(p1.outer_boundary() != p2.outer_boundary()) 00158 return (false); 00159 00160 std::list<Polygon_2> tmp_list(p2.holes_begin(), p2.holes_end()); 00161 00162 HCI i = p1.holes_begin(); 00163 for(; i!= p1.holes_end(); ++i) 00164 { 00165 typename std::list<Polygon_2>::iterator j = 00166 (std::find(tmp_list.begin(), tmp_list.end(), *i)); 00167 00168 if(j == tmp_list.end()) 00169 return (false); 00170 00171 tmp_list.erase(j); 00172 } 00173 00174 00175 CGAL_assertion(tmp_list.empty()); 00176 return (true); 00177 } 00178 00179 //-----------------------------------------------------------------------// 00180 // operator!= 00181 //-----------------------------------------------------------------------// 00182 template <class Kernel_, class Container_> 00183 inline bool operator!=(const Polygon_with_holes_2<Kernel_, Container_>& p1, 00184 const Polygon_with_holes_2<Kernel_, Container_>& p2) 00185 { 00186 return (!(p1==p2)); 00187 } 00188 00189 //-----------------------------------------------------------------------// 00190 // operator== 00191 //-----------------------------------------------------------------------// 00192 template <class Kernel_, class Container_> 00193 bool operator==(const Polygon_with_holes_2<Kernel_, Container_>& p1, 00194 const Polygon_2<Kernel_, Container_>& p2) 00195 { 00196 return (p1.outer_boundary() == p2 && !p1.number_of_holes()); 00197 } 00198 00199 template <class Kernel_, class Container_> 00200 inline bool operator==(const Polygon_2<Kernel_, Container_>& p1, 00201 const Polygon_with_holes_2<Kernel_, Container_>& p2) 00202 { 00203 return (p2 == p1); 00204 } 00205 00206 template <class Kernel_, class Container_> 00207 inline bool operator!=(const Polygon_with_holes_2<Kernel_, Container_>& p1, 00208 const Polygon_2<Kernel_, Container_>& p2) 00209 { 00210 return (!(p1==p2)); 00211 } 00212 00213 template <class Kernel_, class Container_> 00214 inline bool operator!=(const Polygon_2<Kernel_, Container_>& p1, 00215 const Polygon_with_holes_2<Kernel_, Container_>& p2) 00216 { 00217 return (!(p1==p2)); 00218 } 00219 00220 00221 00222 CGAL_END_NAMESPACE 00223 00224 #endif
1.7.6.1