BWAPI
|
00001 // Copyright (c) 1999 Utrecht University (The Netherlands), 00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany), 00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg 00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), 00005 // and Tel-Aviv University (Israel). All rights reserved. 00006 // 00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00008 // modify it under the terms of the GNU Lesser General Public License as 00009 // published by the Free Software Foundation; version 2.1 of the License. 00010 // See the file LICENSE.LGPL distributed with CGAL. 00011 // 00012 // Licensees holding a valid commercial license may use this file in 00013 // accordance with the commercial license agreement provided with the software. 00014 // 00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 // 00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Kernel_23/include/CGAL/Line_2.h $ 00019 // $Id: Line_2.h 49257 2009-05-09 16:08:19Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri 00023 00024 #ifndef CGAL_LINE_2_H 00025 #define CGAL_LINE_2_H 00026 00027 #include <boost/static_assert.hpp> 00028 #include <boost/type_traits.hpp> 00029 #include <CGAL/Kernel/Return_base_tag.h> 00030 #include <CGAL/Dimension.h> 00031 00032 CGAL_BEGIN_NAMESPACE 00033 00034 template <class R_> 00035 class Line_2 : public R_::Kernel_base::Line_2 00036 { 00037 typedef typename R_::RT RT; 00038 typedef typename R_::FT FT; 00039 typedef typename R_::Point_2 Point_2; 00040 typedef typename R_::Segment_2 Segment_2; 00041 typedef typename R_::Ray_2 Ray_2; 00042 typedef typename R_::Vector_2 Vector_2; 00043 typedef typename R_::Direction_2 Direction_2; 00044 typedef typename R_::Aff_transformation_2 Aff_transformation_2; 00045 typedef typename R_::Kernel_base::Line_2 RLine_2; 00046 00047 typedef Line_2 Self; 00048 BOOST_STATIC_ASSERT((boost::is_same<Self, typename R_::Line_2>::value)); 00049 00050 public: 00051 00052 typedef Dimension_tag<2> Ambient_dimension; 00053 typedef Dimension_tag<1> Feature_dimension; 00054 00055 typedef RLine_2 Rep; 00056 00057 const Rep& rep() const 00058 { 00059 return *this; 00060 } 00061 00062 Rep& rep() 00063 { 00064 return *this; 00065 } 00066 00067 typedef R_ R; 00068 00069 Line_2() {} 00070 00071 Line_2(const RLine_2& l) // conversion impl -> interface class 00072 : RLine_2(l) {} 00073 00074 Line_2(const Point_2 &p, const Point_2 &q) 00075 : RLine_2(typename R::Construct_line_2()(Return_base_tag(), p,q)) {} 00076 00077 Line_2(const RT &a, const RT &b, const RT &c) 00078 : RLine_2(typename R::Construct_line_2()(Return_base_tag(), a,b,c)) {} 00079 00080 explicit Line_2(const Segment_2& s) 00081 : RLine_2(typename R::Construct_line_2()(Return_base_tag(), s)) {} 00082 00083 explicit Line_2(const Ray_2& r) 00084 : RLine_2(typename R::Construct_line_2()(Return_base_tag(), r)) {} 00085 00086 Line_2(const Point_2 &p, const Direction_2 &d) 00087 : RLine_2(typename R::Construct_line_2()(Return_base_tag(), p,d)) {} 00088 00089 Line_2(const Point_2 &p, const Vector_2 &v) 00090 : RLine_2(typename R::Construct_line_2()(Return_base_tag(), p,v)) {} 00091 00092 00093 // FIXME : Use Qrt<> here. 00094 RT a() const 00095 { 00096 return R().compute_a_2_object()(*this); 00097 } 00098 00099 RT b() const 00100 { 00101 return R().compute_b_2_object()(*this); 00102 } 00103 00104 RT c() const 00105 { 00106 return R().compute_c_2_object()(*this); 00107 } 00108 00109 Line_2 00110 transform(const Aff_transformation_2 &t) const 00111 { 00112 return Line_2(t.transform(point(0)), 00113 t.transform(direction())); 00114 } 00115 00116 Line_2 00117 opposite() const 00118 { 00119 return R().construct_opposite_line_2_object()(*this); 00120 } 00121 00122 Direction_2 00123 direction() const 00124 { 00125 return R().construct_direction_2_object()(*this); 00126 } 00127 00128 Vector_2 00129 to_vector() const 00130 { 00131 return R().construct_vector_2_object()(*this); 00132 } 00133 00134 Line_2 00135 perpendicular(const Point_2 &p) const 00136 { 00137 return R().construct_perpendicular_line_2_object()(*this,p); 00138 } 00139 00140 Point_2 00141 projection(const Point_2& p) const 00142 { 00143 return R().construct_projected_point_2_object()(*this,p); 00144 } 00145 00146 typename R::Boolean 00147 is_horizontal() const 00148 { 00149 return R().is_horizontal_2_object()(*this); 00150 } 00151 00152 typename R::Boolean 00153 is_vertical() const 00154 { 00155 return R().is_vertical_2_object()(*this); 00156 } 00157 00158 typename R::Boolean 00159 is_degenerate() const 00160 { return R().is_degenerate_2_object()(*this); } 00161 00162 typename R::Oriented_side 00163 oriented_side(const Point_2 &p) const 00164 { 00165 return R().oriented_side_2_object()(*this,p); 00166 } 00167 00168 typename R::Boolean 00169 has_on_boundary(const Point_2 &p) const 00170 { 00171 return oriented_side(p) == ON_ORIENTED_BOUNDARY; 00172 } 00173 00174 typename R::Boolean 00175 has_on_positive_side(const Point_2 &p) const 00176 { 00177 return oriented_side(p) == ON_POSITIVE_SIDE; 00178 } 00179 00180 typename R::Boolean 00181 has_on_negative_side(const Point_2 &p) const 00182 { 00183 return oriented_side(p) == ON_NEGATIVE_SIDE; 00184 } 00185 00186 typename R::Boolean 00187 has_on(const Point_2 &p) const 00188 { 00189 return has_on_boundary(p); 00190 } 00191 00192 FT 00193 x_at_y(const FT &y) const 00194 { 00195 return R().compute_x_at_y_2_object()(*this, y); 00196 } 00197 00198 FT 00199 y_at_x(const FT &y) const 00200 { 00201 return R().compute_y_at_x_2_object()(*this, y); 00202 } 00203 00204 Point_2 00205 point() const 00206 { 00207 return R().construct_point_2_object()(*this); 00208 } 00209 00210 Point_2 00211 point(int i) const 00212 { 00213 return R().construct_point_2_object()(*this,i); 00214 } 00215 00216 typename R::Boolean 00217 operator==(const Line_2 &l) const 00218 { 00219 return R().equal_2_object()(*this, l); 00220 } 00221 00222 typename R::Boolean 00223 operator!=(const Line_2 &l) const 00224 { 00225 return !(*this == l); 00226 } 00227 00228 }; 00229 00230 00231 template <class R > 00232 std::ostream& 00233 insert(std::ostream& os, const Line_2<R>& l) 00234 { 00235 switch(os.iword(IO::mode)) { 00236 case IO::ASCII : 00237 return os << l.a() << ' ' << l.b() << ' ' << l.c(); 00238 case IO::BINARY : 00239 write(os, l.a()); 00240 write(os, l.b()); 00241 write(os, l.c()); 00242 return os; 00243 default: 00244 return os << "Line_2(" << l.a() 00245 << ", " << l.b() << ", " << l.c() <<')'; 00246 } 00247 } 00248 00249 template < class R > 00250 std::ostream & 00251 operator<<(std::ostream &os, const Line_2<R> &l) 00252 { 00253 return insert(os, l); 00254 } 00255 00256 00257 template <class R > 00258 std::istream& 00259 extract(std::istream& is, Line_2<R>& l) 00260 { 00261 typename R::RT a, b, c; 00262 switch(is.iword(IO::mode)) { 00263 case IO::ASCII : 00264 is >> a >> b >> c; 00265 break; 00266 case IO::BINARY : 00267 read(is, a); 00268 read(is, b); 00269 read(is, c); 00270 break; 00271 default: 00272 std::cerr << "" << std::endl; 00273 std::cerr << "Stream must be in ascii or binary mode" << std::endl; 00274 break; 00275 } 00276 if (is) 00277 l = Line_2<R>(a, b, c); 00278 return is; 00279 } 00280 00281 00282 template < class R > 00283 std::istream & 00284 operator>>(std::istream &is, Line_2<R> &l) 00285 { 00286 return extract(is, l); 00287 } 00288 00289 CGAL_END_NAMESPACE 00290 00291 #endif // CGAL_LINE_2_H