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/Ray_3.h $ 00019 // $Id: Ray_3.h 49057 2009-04-30 14:03:52Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri 00023 00024 #ifndef CGAL_CARTESIAN_RAY_3_H 00025 #define CGAL_CARTESIAN_RAY_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 RayC3 00034 { 00035 typedef typename R_::FT FT; 00036 typedef typename R_::Point_3 Point_3; 00037 typedef typename R_::Direction_3 Direction_3; 00038 typedef typename R_::Vector_3 Vector_3; 00039 typedef typename R_::Line_3 Line_3; 00040 typedef typename R_::Ray_3 Ray_3; 00041 00042 typedef cpp0x::array<Point_3, 2> Rep; 00043 typedef typename R_::template Handle<Rep>::type Base; 00044 00045 Base base; 00046 00047 public: 00048 typedef R_ R; 00049 00050 RayC3() {} 00051 00052 RayC3(const Point_3 &sp, const Point_3 &secondp) 00053 : base(CGAL::make_array(sp, secondp)) {} 00054 00055 RayC3(const Point_3 &sp, const Vector_3 &v) 00056 : base(CGAL::make_array(sp, sp + v)) {} 00057 00058 RayC3(const Point_3 &sp, const Direction_3 &d) 00059 : base(CGAL::make_array(sp, sp + d.to_vector())) {} 00060 00061 RayC3(const Point_3 &sp, const Line_3 &l) 00062 : base(CGAL::make_array(sp, sp + l.to_vector())) {} 00063 00064 typename R::Boolean operator==(const RayC3 &r) const; 00065 typename R::Boolean operator!=(const RayC3 &r) const; 00066 00067 const Point_3 & source() const 00068 { 00069 return get(base)[0]; 00070 } 00071 const Point_3 & second_point() const 00072 { 00073 return get(base)[1]; 00074 } 00075 Point_3 point(int i) const; 00076 00077 Direction_3 direction() const; 00078 Vector_3 to_vector() const; 00079 Line_3 supporting_line() const; 00080 Ray_3 opposite() const; 00081 00082 typename R::Boolean is_degenerate() const; 00083 typename R::Boolean has_on(const Point_3 &p) const; 00084 typename R::Boolean collinear_has_on(const Point_3 &p) const; 00085 }; 00086 00087 template < class R > 00088 inline 00089 typename R::Boolean 00090 RayC3<R>::operator==(const RayC3<R> &r) const 00091 { 00092 if (CGAL::identical(base, r.base)) 00093 return true; 00094 return source() == r.source() && direction() == r.direction(); 00095 } 00096 00097 template < class R > 00098 inline 00099 typename R::Boolean 00100 RayC3<R>::operator!=(const RayC3<R> &r) const 00101 { 00102 return !(*this == r); 00103 } 00104 00105 template < class R > 00106 CGAL_KERNEL_INLINE 00107 typename RayC3<R>::Point_3 00108 RayC3<R>::point(int i) const 00109 { 00110 CGAL_kernel_precondition( i >= 0 ); 00111 if (i == 0) return source(); 00112 if (i == 1) return second_point(); 00113 return source() + FT(i) * (second_point() - source()); 00114 } 00115 00116 template < class R > 00117 inline 00118 typename RayC3<R>::Vector_3 00119 RayC3<R>::to_vector() const 00120 { 00121 return second_point() - source(); 00122 } 00123 00124 template < class R > 00125 inline 00126 typename RayC3<R>::Direction_3 00127 RayC3<R>::direction() const 00128 { 00129 return Direction_3( second_point() - source() ); 00130 } 00131 00132 template < class R > 00133 inline 00134 typename RayC3<R>::Line_3 00135 RayC3<R>::supporting_line() const 00136 { 00137 return Line_3(*this); 00138 } 00139 00140 template < class R > 00141 inline 00142 typename RayC3<R>::Ray_3 00143 RayC3<R>::opposite() const 00144 { 00145 return RayC3<R>( source(), - direction() ); 00146 } 00147 00148 template < class R > 00149 typename R::Boolean 00150 RayC3<R>:: 00151 has_on(const typename RayC3<R>::Point_3 &p) const 00152 { 00153 return (p == source()) || 00154 ( collinear(source(), p, second_point()) 00155 && ( Direction_3(p - source()) == direction() )); 00156 } 00157 00158 template < class R > 00159 inline 00160 typename R::Boolean 00161 RayC3<R>::is_degenerate() const 00162 { 00163 return source() == second_point(); 00164 } 00165 00166 template < class R > 00167 inline 00168 typename R::Boolean 00169 RayC3<R>:: 00170 collinear_has_on(const typename RayC3<R>::Point_3 &p) const 00171 { 00172 CGAL_kernel_exactness_precondition( collinear(source(), p, second_point()) ); 00173 00174 typename R::Comparison_result cx = compare_x(source(), second_point()); 00175 if (cx != EQUAL) 00176 return cx != compare_x(p, source()); 00177 00178 typename R::Comparison_result cy = compare_y(source(), second_point()); 00179 if (cy != EQUAL) 00180 return cy != compare_y(p, source()); 00181 00182 typename R::Comparison_result cz = compare_z(source(), second_point()); 00183 if (cz != EQUAL) 00184 return cz != compare_z(p, source()); 00185 00186 return true; // p == source() 00187 } 00188 00189 CGAL_END_NAMESPACE 00190 00191 #endif // CGAL_CARTESIAN_RAY_3_H