BWAPI
|
00001 // Copyright (c) 2000 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/Cartesian_kernel/include/CGAL/Cartesian/Segment_3.h $ 00019 // $Id: Segment_3.h 49057 2009-04-30 14:03:52Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri 00023 00024 #ifndef CGAL_CARTESIAN_SEGMENT_3_H 00025 #define CGAL_CARTESIAN_SEGMENT_3_H 00026 00027 #include <CGAL/array.h> 00028 #include <CGAL/Handle_for.h> 00029 00030 CGAL_BEGIN_NAMESPACE 00031 00032 template < class R_ > 00033 class SegmentC3 00034 { 00035 typedef typename R_::Point_3 Point_3; 00036 typedef typename R_::Direction_3 Direction_3; 00037 typedef typename R_::Vector_3 Vector_3; 00038 typedef typename R_::Line_3 Line_3; 00039 typedef typename R_::Segment_3 Segment_3; 00040 00041 typedef cpp0x::array<Point_3, 2> Rep; 00042 typedef typename R_::template Handle<Rep>::type Base; 00043 00044 Base base; 00045 00046 public: 00047 typedef R_ R; 00048 00049 SegmentC3() {} 00050 00051 SegmentC3(const Point_3 &sp, const Point_3 &ep) 00052 : base(CGAL::make_array(sp, ep)) {} 00053 00054 bool has_on(const Point_3 &p) const; 00055 bool collinear_has_on(const Point_3 &p) const; 00056 00057 bool operator==(const SegmentC3 &s) const; 00058 bool operator!=(const SegmentC3 &s) const; 00059 00060 const Point_3 & source() const 00061 { 00062 return get(base)[0]; 00063 } 00064 const Point_3 & target() const 00065 { 00066 return get(base)[1]; 00067 } 00068 00069 const Point_3 & start() const; 00070 const Point_3 & end() const; 00071 00072 const Point_3 & min BOOST_PREVENT_MACRO_SUBSTITUTION () const; 00073 const Point_3 & max BOOST_PREVENT_MACRO_SUBSTITUTION () const; 00074 const Point_3 & vertex(int i) const; 00075 const Point_3 & point(int i) const; 00076 const Point_3 & operator[](int i) const; 00077 00078 Direction_3 direction() const; 00079 Vector_3 to_vector() const; 00080 Line_3 supporting_line() const; 00081 Segment_3 opposite() const; 00082 00083 bool is_degenerate() const; 00084 }; 00085 00086 template < class R > 00087 inline 00088 bool 00089 SegmentC3<R>::operator==(const SegmentC3<R> &s) const 00090 { 00091 if (CGAL::identical(base, s.base)) 00092 return true; 00093 return source() == s.source() && target() == s.target(); 00094 } 00095 00096 template < class R > 00097 inline 00098 bool 00099 SegmentC3<R>::operator!=(const SegmentC3<R> &s) const 00100 { 00101 return !(*this == s); 00102 } 00103 00104 template < class R > 00105 const typename SegmentC3<R>::Point_3 & 00106 SegmentC3<R>::start() const 00107 { 00108 return source(); 00109 } 00110 00111 template < class R > 00112 const typename SegmentC3<R>::Point_3 & 00113 SegmentC3<R>::end() const 00114 { 00115 return target(); 00116 } 00117 00118 template < class R > 00119 inline 00120 const typename SegmentC3<R>::Point_3 & 00121 SegmentC3<R>::min BOOST_PREVENT_MACRO_SUBSTITUTION () const 00122 { 00123 return lexicographically_xyz_smaller(source(),target()) ? source() 00124 : target(); 00125 } 00126 00127 template < class R > 00128 inline 00129 const typename SegmentC3<R>::Point_3 & 00130 SegmentC3<R>::max BOOST_PREVENT_MACRO_SUBSTITUTION () const 00131 { 00132 return lexicographically_xyz_smaller(source(),target()) ? target() 00133 : source(); 00134 } 00135 00136 template < class R > 00137 inline 00138 const typename SegmentC3<R>::Point_3 & 00139 SegmentC3<R>::vertex(int i) const 00140 { 00141 return (i%2 == 0) ? source() : target(); 00142 } 00143 00144 template < class R > 00145 inline 00146 const typename SegmentC3<R>::Point_3 & 00147 SegmentC3<R>::point(int i) const 00148 { 00149 return vertex(i); 00150 } 00151 00152 template < class R > 00153 inline 00154 const typename SegmentC3<R>::Point_3 & 00155 SegmentC3<R>::operator[](int i) const 00156 { 00157 return vertex(i); 00158 } 00159 00160 template < class R > 00161 inline 00162 typename SegmentC3<R>::Vector_3 00163 SegmentC3<R>::to_vector() const 00164 { 00165 return target() - source(); 00166 } 00167 00168 template < class R > 00169 inline 00170 typename SegmentC3<R>::Direction_3 00171 SegmentC3<R>::direction() const 00172 { 00173 return Direction_3( target() - source() ); 00174 } 00175 00176 template < class R > 00177 inline 00178 typename SegmentC3<R>::Line_3 00179 SegmentC3<R>::supporting_line() const 00180 { 00181 return Line_3(*this); 00182 } 00183 00184 template < class R > 00185 inline 00186 typename SegmentC3<R>::Segment_3 00187 SegmentC3<R>::opposite() const 00188 { 00189 return SegmentC3<R>(target(), source()); 00190 } 00191 00192 template < class R > 00193 inline 00194 bool 00195 SegmentC3<R>::is_degenerate() const 00196 { 00197 return source() == target(); 00198 } 00199 00200 template < class R > 00201 inline 00202 bool 00203 SegmentC3<R>:: 00204 has_on(const typename SegmentC3<R>::Point_3 &p) const 00205 { 00206 return are_ordered_along_line(source(), p, target()); 00207 } 00208 00209 template < class R > 00210 inline 00211 bool 00212 SegmentC3<R>:: 00213 collinear_has_on(const typename SegmentC3<R>::Point_3 &p) const 00214 { 00215 return collinear_are_ordered_along_line(source(), p, target()); 00216 } 00217 00218 CGAL_END_NAMESPACE 00219 00220 #endif // CGAL_CARTESIAN_SEGMENT_3_H