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/Segment_3.h $ 00019 // $Id: Segment_3.h 42932 2008-04-17 10:13:31Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri, Stefan Schirra 00023 00024 #ifndef CGAL_SEGMENT_3_H 00025 #define CGAL_SEGMENT_3_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/Bbox_3.h> 00031 #include <CGAL/Dimension.h> 00032 00033 CGAL_BEGIN_NAMESPACE 00034 00035 template <class R_> 00036 class Segment_3 : public R_::Kernel_base::Segment_3 00037 { 00038 typedef typename R_::RT RT; 00039 typedef typename R_::FT FT; 00040 typedef typename R_::Point_3 Point_3; 00041 typedef typename R_::Vector_3 Vector_3; 00042 typedef typename R_::Direction_3 Direction_3; 00043 typedef typename R_::Line_3 Line_3; 00044 typedef typename R_::Aff_transformation_3 Aff_transformation_3; 00045 00046 typedef Segment_3 Self; 00047 BOOST_STATIC_ASSERT((boost::is_same<Self, typename R_::Segment_3>::value)); 00048 00049 public: 00050 00051 typedef Dimension_tag<3> Ambient_dimension; 00052 typedef Dimension_tag<1> Feature_dimension; 00053 00054 typedef typename R_::Kernel_base::Segment_3 Rep; 00055 00056 const Rep& rep() const 00057 { 00058 return *this; 00059 } 00060 00061 Rep& rep() 00062 { 00063 return *this; 00064 } 00065 00066 typedef R_ R; 00067 00068 Segment_3() {} 00069 00070 Segment_3(const Rep& s) 00071 : Rep(s) {} 00072 00073 Segment_3(const Point_3& sp, const Point_3& ep) 00074 : Rep(typename R::Construct_segment_3()(Return_base_tag(), sp, ep)) {} 00075 00076 // FIXME TODO : Use Qrt here ! 00077 //typename Qualified_result_of<typename R::Construct_source_3, Segment_3>::type 00078 Point_3 00079 source() const 00080 { 00081 return R_().construct_source_3_object()(*this); 00082 } 00083 00084 //typename Qualified_result_of<typename R::Construct_target_3, Segment_3>::type 00085 Point_3 00086 target() const 00087 { 00088 return R_().construct_target_3_object()(*this); 00089 } 00090 00091 //typename Qualified_result_of<typename R::Construct_source_3, Segment_3>::type 00092 Point_3 00093 start() const 00094 { 00095 return source(); 00096 } 00097 00098 //typename Qualified_result_of<typename R::Construct_target_3, Segment_3>::type 00099 Point_3 00100 end() const 00101 { 00102 return target(); 00103 } 00104 00105 //typename Qualified_result_of<typename R::Construct_min_vertex_2, Segment_2>::type 00106 Point_3 00107 min BOOST_PREVENT_MACRO_SUBSTITUTION () const; 00108 00109 //typename Qualified_result_of<typename R::Construct_max_vertex_2, Segment_2>::type 00110 Point_3 00111 max BOOST_PREVENT_MACRO_SUBSTITUTION () const; 00112 00113 //typename Qualified_result_of<typename R::Construct_vertex_2, Segment_2, int>::type 00114 Point_3 00115 vertex(int i) const; 00116 00117 //typename Qualified_result_of<typename R::Construct_vertex_2, Segment_2, int>::type 00118 Point_3 00119 point(int i) const 00120 { return vertex(i); } 00121 00122 //typename Qualified_result_of<typename R::Construct_vertex_2, Segment_2, int>::type 00123 Point_3 00124 operator[](int i) const 00125 { return vertex(i); } 00126 00127 00128 Segment_3 transform(const Aff_transformation_3 &t) const 00129 { 00130 return Segment_3(t.transform(this->source()), t.transform(this->target())); 00131 } 00132 00133 FT squared_length() const 00134 { 00135 return squared_distance(this->target(), this->source()); 00136 } 00137 00138 Vector_3 to_vector() const 00139 { 00140 return R().construct_vector_3_object()(*this); 00141 } 00142 00143 bool has_on(const Point_3 &p) const 00144 { // TODO : use one predicate. 00145 return R_().are_ordered_along_line_3_object()(source(), 00146 p, 00147 target()); 00148 } 00149 00150 Segment_3 opposite() const 00151 { 00152 return R().construct_opposite_segment_3_object()(*this); 00153 } 00154 00155 Direction_3 direction() const 00156 { 00157 typename R::Construct_vector_3 construct_vector; 00158 return Direction_3( construct_vector( source(), target())); 00159 } 00160 00161 bool is_degenerate() const 00162 { 00163 return R().is_degenerate_3_object()(*this); 00164 } 00165 00166 Bbox_3 bbox() const 00167 { 00168 return R().construct_bbox_3_object()(*this); 00169 } 00170 00171 Line_3 00172 supporting_line() const 00173 { 00174 return R().construct_line_3_object()(*this); 00175 } 00176 00177 }; 00178 00179 template < class R_ > 00180 CGAL_KERNEL_INLINE 00181 //typename Qualified_result_of<typename R_::Construct_min_vertex_2, Segment_2<R_> >::type 00182 typename R_::Point_3 00183 Segment_3<R_>::min BOOST_PREVENT_MACRO_SUBSTITUTION () const 00184 { 00185 typename R_::Less_xyz_3 less_xyz; 00186 return less_xyz(source(),target()) ? source() : target(); 00187 } 00188 00189 template < class R_ > 00190 CGAL_KERNEL_INLINE 00191 //typename Qualified_result_of<typename R_::Construct_max_vertex_2, Segment_2<R_> >::type 00192 typename R_::Point_3 00193 Segment_3<R_>::max BOOST_PREVENT_MACRO_SUBSTITUTION () const 00194 { 00195 typename R_::Less_xyz_3 less_xyz; 00196 return less_xyz(source(),target()) ? target() : source(); 00197 } 00198 00199 template < class R_ > 00200 CGAL_KERNEL_INLINE 00201 //typename Qualified_result_of<typename R_::Construct_vertex_2, Segment_2<R_>, int >::type 00202 typename R_::Point_3 00203 Segment_3<R_>::vertex(int i) const 00204 { 00205 return (i%2 == 0) ? source() : target(); 00206 } 00207 00208 00209 template < class R > 00210 std::ostream & 00211 operator<<(std::ostream &os, const Segment_3<R> &s) 00212 { 00213 switch(os.iword(IO::mode)) { 00214 case IO::ASCII : 00215 return os << s.source() << ' ' << s.target(); 00216 case IO::BINARY : 00217 return os << s.source() << s.target(); 00218 default: 00219 return os << "Segment_3(" << s.source() << ", " << s.target() << ")"; 00220 } 00221 } 00222 00223 template < class R > 00224 std::istream & 00225 operator>>(std::istream &is, Segment_3<R> &s) 00226 { 00227 typename R::Point_3 p, q; 00228 00229 is >> p >> q; 00230 00231 if (is) 00232 s = Segment_3<R>(p, q); 00233 return is; 00234 } 00235 00236 CGAL_END_NAMESPACE 00237 00238 #endif // CGAL_SEGMENT_3_H