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/Triangle_3.h $ 00019 // $Id: Triangle_3.h 49057 2009-04-30 14:03:52Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri 00023 00024 #ifndef CGAL_CARTESIAN_TRIANGLE_3_H 00025 #define CGAL_CARTESIAN_TRIANGLE_3_H 00026 00027 #include <CGAL/Handle_for.h> 00028 #include <CGAL/array.h> 00029 00030 CGAL_BEGIN_NAMESPACE 00031 00032 template <class R_> 00033 class TriangleC3 00034 { 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_::Plane_3 Plane_3; 00039 typedef typename R_::Triangle_3 Triangle_3; 00040 00041 typedef cpp0x::array<Point_3, 3> Rep; 00042 typedef typename R_::template Handle<Rep>::type Base; 00043 00044 Base base; 00045 00046 public: 00047 typedef R_ R; 00048 00049 TriangleC3() {} 00050 00051 TriangleC3(const Point_3 &p, const Point_3 &q, const Point_3 &r) 00052 : base(CGAL::make_array(p, q, r)) {} 00053 00054 bool operator==(const TriangleC3 &t) const; 00055 bool operator!=(const TriangleC3 &t) const; 00056 00057 Plane_3 supporting_plane() const; 00058 00059 bool has_on(const Point_3 &p) const; 00060 bool is_degenerate() const; 00061 00062 const Point_3 & vertex(int i) const; 00063 const Point_3 & operator[](int i) const; 00064 00065 FT squared_area() const; 00066 }; 00067 00068 template < class R > 00069 bool 00070 TriangleC3<R>::operator==(const TriangleC3<R> &t) const 00071 { 00072 if (CGAL::identical(base, t.base)) 00073 return true; 00074 00075 int i; 00076 for(i=0; i<3; i++) 00077 if ( vertex(0) == t.vertex(i) ) 00078 break; 00079 00080 return (i<3) && vertex(1) == t.vertex(i+1) && vertex(2) == t.vertex(i+2); 00081 } 00082 00083 template < class R > 00084 inline 00085 bool 00086 TriangleC3<R>::operator!=(const TriangleC3<R> &t) const 00087 { 00088 return !(*this == t); 00089 } 00090 00091 template < class R > 00092 const typename TriangleC3<R>::Point_3 & 00093 TriangleC3<R>::vertex(int i) const 00094 { 00095 if (i<0) i=(i%3)+3; 00096 else if (i>2) i=i%3; 00097 return (i==0) ? get(base)[0] : 00098 (i==1) ? get(base)[1] : 00099 get(base)[2]; 00100 } 00101 00102 template < class R > 00103 inline 00104 const typename TriangleC3<R>::Point_3 & 00105 TriangleC3<R>::operator[](int i) const 00106 { 00107 return vertex(i); 00108 } 00109 00110 template < class R > 00111 CGAL_KERNEL_MEDIUM_INLINE 00112 typename TriangleC3<R>::FT 00113 TriangleC3<R>::squared_area() const 00114 { 00115 return CGALi::squared_area(vertex(0), vertex(1), vertex(2), R()); 00116 } 00117 00118 template < class R > 00119 inline 00120 typename TriangleC3<R>::Plane_3 00121 TriangleC3<R>::supporting_plane() const 00122 { 00123 return Plane_3(vertex(0), vertex(1), vertex(2)); 00124 } 00125 00126 template < class R > 00127 inline 00128 bool 00129 TriangleC3<R>:: 00130 has_on(const typename TriangleC3<R>::Point_3 &p) const 00131 { 00132 return R().has_on_3_object() 00133 (static_cast<const typename R::Triangle_3>(*this), p); 00134 } 00135 00136 template < class R > 00137 bool 00138 TriangleC3<R>::is_degenerate() const 00139 { 00140 return collinear(vertex(0),vertex(1),vertex(2)); 00141 } 00142 00143 CGAL_END_NAMESPACE 00144 00145 #endif // CGAL_CARTESIAN_TRIANGLE_3_H