|
BWAPI
|
00001 // Copyright (c) 2006 Foundation for Research and Technology-Hellas (Greece). 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/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_2/Construct_storage_site_2.h $ 00015 // $Id: Construct_storage_site_2.h 44317 2008-07-22 12:29:01Z spion $ 00016 // 00017 // 00018 // Author(s) : Menelaos Karavelas <mkaravel@iacm.forth.gr> 00019 00020 #ifndef CGAL_SEGMENT_DELAUNAY_GRAPH_2_CONSTRUCT_STORAGE_SITE_2_H 00021 #define CGAL_SEGMENT_DELAUNAY_GRAPH_2_CONSTRUCT_STORAGE_SITE_2_H 1 00022 00023 #include <CGAL/Segment_Delaunay_graph_2/basic.h> 00024 00025 00026 CGAL_BEGIN_NAMESPACE 00027 00028 CGAL_SEGMENT_DELAUNAY_GRAPH_2_BEGIN_NAMESPACE 00029 00030 template<class STraits> 00031 class Construct_storage_site_2 00032 { 00033 public: 00034 typedef STraits Storage_traits; 00035 typedef typename Storage_traits::Storage_site_2 Storage_site_2; 00036 typedef typename Storage_traits::Point_handle Point_handle; 00037 typedef typename Storage_traits::Geom_traits Geom_traits; 00038 00039 typedef Storage_site_2 result_type; 00040 00041 protected: 00042 typedef typename Geom_traits::Intersections_tag ITag; 00043 00044 result_type construct(const Point_handle& h1, 00045 const Point_handle& h2, 00046 const Point_handle& h3, 00047 const Point_handle& h4, const Tag_true&) const { 00048 return Storage_site_2::construct_storage_site_2(h1, h2, h3, h4); 00049 } 00050 00051 inline 00052 result_type construct(const Point_handle& h1, 00053 const Point_handle& h2, 00054 const Point_handle& h3, 00055 const Point_handle& h4, 00056 const Point_handle& h5, 00057 const Point_handle& h6, const Tag_true&) const { 00058 return Storage_site_2::construct_storage_site_2(h1, h2, h3, h4, h5, h6); 00059 } 00060 00061 inline 00062 result_type construct(const Point_handle& h1, 00063 const Point_handle& h2, 00064 const Point_handle& h3, 00065 const Point_handle& h4, 00066 bool is_first_exact, const Tag_true&) const { 00067 return Storage_site_2::construct_storage_site_2(h1, h2, h3, h4, 00068 is_first_exact); 00069 } 00070 00071 00072 result_type construct(const Point_handle&, 00073 const Point_handle&, 00074 const Point_handle&, 00075 const Point_handle&, const Tag_false&) const { 00076 CGAL_error(); 00077 return Storage_site_2(); 00078 } 00079 00080 inline 00081 result_type construct(const Point_handle&, 00082 const Point_handle&, 00083 const Point_handle&, 00084 const Point_handle&, 00085 const Point_handle&, 00086 const Point_handle&, const Tag_false&) const { 00087 CGAL_error(); 00088 return Storage_site_2(); 00089 } 00090 00091 inline 00092 result_type construct(const Point_handle&, 00093 const Point_handle&, 00094 const Point_handle&, 00095 const Point_handle&, 00096 bool /* is_first_exact */, const Tag_false&) const { 00097 CGAL_error(); 00098 return Storage_site_2(); 00099 } 00100 00101 public: 00102 inline 00103 result_type operator()(const Point_handle& h) const { 00104 return Storage_site_2::construct_storage_site_2(h); 00105 } 00106 00107 inline 00108 result_type operator()(const Point_handle& h1, 00109 const Point_handle& h2) const { 00110 return Storage_site_2::construct_storage_site_2(h1, h2); 00111 } 00112 00113 inline 00114 result_type operator()(const Point_handle& h1, 00115 const Point_handle& h2, 00116 const Point_handle& h3, 00117 const Point_handle& h4) const { 00118 return construct(h1, h2, h3, h4, ITag()); 00119 } 00120 00121 inline 00122 result_type operator()(const Point_handle& h1, 00123 const Point_handle& h2, 00124 const Point_handle& h3, 00125 const Point_handle& h4, 00126 const Point_handle& h5, 00127 const Point_handle& h6) const { 00128 return construct(h1, h2, h3, h4, h5, h6, ITag()); 00129 } 00130 00131 inline 00132 result_type operator()(const Point_handle& h1, 00133 const Point_handle& h2, 00134 const Point_handle& h3, 00135 const Point_handle& h4, 00136 bool is_first_exact) const { 00137 return construct(h1, h2, h3, h4, is_first_exact, ITag()); 00138 } 00139 00140 // constructs the point of intersection 00141 inline 00142 result_type operator()(const Storage_site_2& ss0, 00143 const Storage_site_2& ss1) const { 00144 CGAL_precondition( ss0.is_segment() && ss1.is_segment() ); 00145 return Storage_site_2::construct_storage_site_2 00146 ( ss0.source_of_supporting_site(), 00147 ss0.target_of_supporting_site(), 00148 ss1.source_of_supporting_site(), 00149 ss1.target_of_supporting_site() ); 00150 } 00151 00152 Storage_site_2 00153 split_on_point_first_subsegment(const Storage_site_2& s, 00154 const Storage_site_2& p) const 00155 { 00156 // Splits the first storage site which is a segment using the 00157 // second storage site which is an exact point 00158 // Two new storage sites are created, corresponding to the two 00159 // subsegments 00160 CGAL_precondition( s.is_segment() && p.is_point() ); 00161 00162 // computing the first sub-segment 00163 if ( s.is_input(0) ) { 00164 if ( p.is_input() ) { 00165 // both segment and point are input 00166 return operator()(s.source_of_supporting_site(), p.point()); 00167 } else { 00168 // segment is input but point is intersection of two segments 00169 Storage_site_2 supp0 = s.supporting_site(); 00170 Storage_site_2 supp1 = p.supporting_site(0); 00171 00172 typename Geom_traits::Are_parallel_2 are_parallel = 00173 Geom_traits().are_parallel_2_object(); 00174 00175 if ( are_parallel(supp0.site(), supp1.site()) ) { 00176 supp1 = p.supporting_site(1); 00177 } 00178 return operator()( supp0.source_of_supporting_site(), 00179 supp0.target_of_supporting_site(), 00180 supp1.source_of_supporting_site(), 00181 supp1.target_of_supporting_site(), 00182 true ); 00183 } 00184 } else { 00185 if ( p.is_input() ) { 00186 // point is input but source of segment is not 00187 return operator()( s.source_of_supporting_site(), 00188 p.point(), 00189 s.source_of_crossing_site(0), 00190 s.target_of_crossing_site(0), 00191 false ); 00192 } else { 00193 Storage_site_2 supp0 = s.supporting_site(); 00194 Storage_site_2 supp1 = p.supporting_site(0); 00195 00196 typename Geom_traits::Are_parallel_2 are_parallel = 00197 Geom_traits().are_parallel_2_object(); 00198 00199 if ( are_parallel(supp0.site(), supp1.site()) ) { 00200 supp1 = p.supporting_site(1); 00201 } 00202 00203 return operator()( supp0.source_of_supporting_site(), 00204 supp0.target_of_supporting_site(), 00205 s.source_of_crossing_site(0), 00206 s.target_of_crossing_site(0), 00207 supp1.source_of_supporting_site(), 00208 supp1.target_of_supporting_site() ); 00209 } 00210 } 00211 } 00212 00213 Storage_site_2 00214 split_on_point_second_subsegment(const Storage_site_2& s, 00215 const Storage_site_2& p) const 00216 { 00217 CGAL_precondition( s.is_segment() && p.is_point() ); 00218 00219 // computing the second sub-segment 00220 if ( s.is_input(1) ) { 00221 if ( p.is_input() ) { 00222 // both segment and point are input 00223 return operator()(p.point(), s.target_of_supporting_site()); 00224 } else { 00225 // segment is input but point is intersection of two segments 00226 Storage_site_2 supp0 = s.supporting_site(); 00227 Storage_site_2 supp1 = p.supporting_site(0); 00228 00229 typename Geom_traits::Are_parallel_2 are_parallel = 00230 Geom_traits().are_parallel_2_object(); 00231 00232 if ( are_parallel(supp0.site(), supp1.site()) ) { 00233 supp1 = p.supporting_site(1); 00234 } 00235 return operator()( supp0.source_of_supporting_site(), 00236 supp0.target_of_supporting_site(), 00237 supp1.source_of_supporting_site(), 00238 supp1.target_of_supporting_site(), 00239 false ); 00240 } 00241 } else { 00242 if ( p.is_input() ) { 00243 // point is input but source of segment is not 00244 return operator()( p.point(), 00245 s.target_of_supporting_site(), 00246 s.source_of_crossing_site(1), 00247 s.target_of_crossing_site(1), 00248 true ); 00249 } else { 00250 Storage_site_2 supp0 = s.supporting_site(); 00251 Storage_site_2 supp1 = p.supporting_site(0); 00252 00253 typename Geom_traits::Are_parallel_2 are_parallel = 00254 Geom_traits().are_parallel_2_object(); 00255 00256 if ( are_parallel(supp0.site(), supp1.site()) ) { 00257 supp1 = p.supporting_site(1); 00258 } 00259 00260 return operator()( supp0.source_of_supporting_site(), 00261 supp0.target_of_supporting_site(), 00262 supp1.source_of_supporting_site(), 00263 supp1.target_of_supporting_site(), 00264 s.source_of_crossing_site(1), 00265 s.target_of_crossing_site(1) ); 00266 } 00267 } 00268 } 00269 00270 Storage_site_2 00271 construct_first_subsegment(const Storage_site_2& ss0, 00272 const Storage_site_2& ss1, 00273 const Tag_true&) const 00274 { 00275 if ( ss0.is_input(0) ) { 00276 return Storage_site_2::construct_storage_site_2 00277 ( ss0.source_of_supporting_site(), 00278 ss0.target_of_supporting_site(), 00279 ss1.source_of_supporting_site(), 00280 ss1.target_of_supporting_site(), true ); 00281 } else { 00282 return Storage_site_2::construct_storage_site_2 00283 ( ss0.source_of_supporting_site(), 00284 ss0.target_of_supporting_site(), 00285 ss0.source_of_crossing_site(0), 00286 ss0.target_of_crossing_site(0), 00287 ss1.source_of_supporting_site(), 00288 ss1.target_of_supporting_site() ); 00289 } 00290 } 00291 00292 Storage_site_2 00293 construct_second_subsegment(const Storage_site_2& ss0, 00294 const Storage_site_2& ss1, 00295 const Tag_true&) const 00296 { 00297 if ( ss0.is_input(1) ) { 00298 return Storage_site_2::construct_storage_site_2 00299 ( ss0.source_of_supporting_site(), 00300 ss0.target_of_supporting_site(), 00301 ss1.source_of_supporting_site(), 00302 ss1.target_of_supporting_site(), false ); 00303 } else { 00304 return Storage_site_2::construct_storage_site_2 00305 ( ss0.source_of_supporting_site(), 00306 ss0.target_of_supporting_site(), 00307 ss1.source_of_supporting_site(), 00308 ss1.target_of_supporting_site(), 00309 ss0.source_of_crossing_site(1), 00310 ss0.target_of_crossing_site(1) ); 00311 } 00312 } 00313 00314 Storage_site_2 00315 construct_first_subsegment(const Storage_site_2&, 00316 const Storage_site_2&, 00317 const Tag_false&) const 00318 { 00319 CGAL_error(); 00320 return Storage_site_2(); 00321 } 00322 00323 Storage_site_2 00324 construct_second_subsegment(const Storage_site_2&, 00325 const Storage_site_2&, 00326 const Tag_false&) const 00327 { 00328 CGAL_error(); 00329 return Storage_site_2(); 00330 } 00331 00332 // constructs the subsegment with supporting segment ss0 and 00333 // endpoints the point of intersection of ss1 and ss0; the boolean 00334 // determines if the first or segment subsegment is constructed 00335 inline 00336 result_type operator()(const Storage_site_2& ss0, 00337 const Storage_site_2& ss1, 00338 bool first) const { 00339 // CGAL_precondition( ss0.is_segment() && ss1.is_segment() ); 00340 CGAL_precondition( ss0.is_segment() ); 00341 if ( ss1.is_point() ) { 00342 if ( first ) { 00343 return split_on_point_first_subsegment(ss0, ss1); 00344 } else { 00345 return split_on_point_second_subsegment(ss0, ss1); 00346 } 00347 } 00348 00349 if ( first ) { 00350 return construct_first_subsegment(ss0, ss1, ITag()); 00351 } else { 00352 return construct_second_subsegment(ss0, ss1, ITag()); 00353 } 00354 } 00355 00356 }; 00357 00358 //---------------------------------------------------------------------- 00359 //---------------------------------------------------------------------- 00360 00361 00362 CGAL_SEGMENT_DELAUNAY_GRAPH_2_END_NAMESPACE 00363 00364 CGAL_END_NAMESPACE 00365 00366 #endif // CGAL_SEGMENT_DELAUNAY_GRAPH_2_CONSTRUCT_STORAGE_SITE_2_H
1.7.6.1