BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Homogeneous/DirectionH3.h
Go to the documentation of this file.
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/Homogeneous_kernel/include/CGAL/Homogeneous/DirectionH3.h $
00019 // $Id: DirectionH3.h 49057 2009-04-30 14:03:52Z spion $
00020 // 
00021 //
00022 // Author(s)     : Stefan Schirra
00023  
00024 #ifndef CGAL_HOMOGENEOUS_DIRECTION_3_H
00025 #define CGAL_HOMOGENEOUS_DIRECTION_3_H
00026 
00027 #include <CGAL/array.h>
00028 
00029 CGAL_BEGIN_NAMESPACE
00030 
00031 template < class R_ >
00032 class DirectionH3
00033 {
00034    typedef typename R_::RT                   RT;
00035    typedef typename R_::FT                   FT;
00036    typedef typename R_::Point_3              Point_3;
00037    typedef typename R_::Vector_3             Vector_3;
00038    typedef typename R_::Segment_3            Segment_3;
00039    typedef typename R_::Line_3               Line_3;
00040    typedef typename R_::Ray_3                Ray_3;
00041 
00042     typedef cpp0x::array<RT, 4>              Rep;
00043     typedef typename R_::template Handle<Rep>::type  Base;
00044  
00045     Base base;
00046 
00047 public:
00048 
00049     typedef R_                 R;
00050 
00051   DirectionH3() {}
00052 
00053   //DirectionH3(const Point_3 & p )
00054     //: base(p) {}
00055 
00056   DirectionH3(const Vector_3 & v )
00057   { *this = v.direction(); }
00058 
00059   DirectionH3(const Line_3 & l )
00060   { *this = l.rep().direction(); }
00061 
00062   DirectionH3(const Ray_3 & r )
00063   { *this = r.direction(); }
00064 
00065   DirectionH3(const Segment_3 & s )
00066   { *this = s.direction(); }
00067 
00068   // the fourth argument is not documented.  Should go away ?
00069   DirectionH3(const RT& x, const RT& y,
00070               const RT& z, const RT& w = RT(1) )
00071     : base( w >= RT(0) ? CGAL::make_array(x, y, z, w)
00072                        : CGAL::make_array<RT>(-x, -y, -z, -w) ) {}
00073 
00074   bool  is_degenerate() const;
00075 
00076   bool  operator==( const DirectionH3<R>& d) const;
00077   bool  operator!=( const DirectionH3<R>& d) const;
00078 
00079   Vector_3    to_vector() const;
00080   Vector_3    vector() const { return to_vector(); }
00081 
00082   const RT & dx() const { return get(base)[0]; }
00083   const RT & dy() const { return get(base)[1]; }
00084   const RT & dz() const { return get(base)[2]; }
00085   const RT & x()  const { return get(base)[0]; }
00086   const RT & y()  const { return get(base)[1]; }
00087   const RT & z()  const { return get(base)[2]; }
00088   const RT & hx() const { return get(base)[0]; }
00089   const RT & hy() const { return get(base)[1]; }
00090   const RT & hz() const { return get(base)[2]; }
00091 };
00092 
00093 template <class R >
00094 CGAL_KERNEL_INLINE
00095 bool
00096 DirectionH3<R>::operator==( const DirectionH3<R>& d) const
00097 {
00098   return ( ( hx()*d.hy() == hy()*d.hx() )
00099         &&( hx()*d.hz() == hz()*d.hx() )
00100         &&( hy()*d.hz() == hz()*d.hy() )
00101         &&( CGAL_NTS sign( hx() ) == CGAL_NTS sign( d.hx() ) )
00102         &&( CGAL_NTS sign( hy() ) == CGAL_NTS sign( d.hy() ) )
00103         &&( CGAL_NTS sign( hz() ) == CGAL_NTS sign( d.hz() ) ) );
00104 }
00105 
00106 template <class R >
00107 inline
00108 bool
00109 DirectionH3<R>::operator!=( const DirectionH3<R>& d) const
00110 { return !operator==(d); }
00111 
00112 template <class R >
00113 CGAL_KERNEL_INLINE
00114 bool
00115 DirectionH3<R>::is_degenerate() const
00116 { return ((hx() == RT(0)) && (hy() == RT(0)) && (hz() == RT(0))); }
00117 
00118 template <class R >
00119 inline
00120 typename DirectionH3<R>::Vector_3
00121 DirectionH3<R>::to_vector() const
00122 { return Vector_3(dx(), dy(), dz(), RT(1)); }
00123 
00124 template <class R>
00125 CGAL_KERNEL_INLINE
00126 DirectionH3<R>
00127 cross_product( const DirectionH3<R>& d1,
00128                const DirectionH3<R>& d2)
00129 { return cross_product(d1.to_vector(),d2.to_vector()).direction(); }
00130 
00131 CGAL_END_NAMESPACE
00132 
00133 #endif // CGAL_HOMOGENEOUS_DIRECTION_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines