BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/predicates_d.h
Go to the documentation of this file.
00001 // Copyright (c) 2000,2001  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_d/include/CGAL/predicates_d.h $
00019 // $Id: predicates_d.h 42940 2008-04-17 13:32:52Z spion $
00020 // 
00021 //
00022 // Author(s)     : Michael Seel
00023 
00024 #ifndef CGAL_PREDICATES_D_H
00025 #define CGAL_PREDICATES_D_H
00026 
00027 #include <CGAL/basic.h>
00028 #include <CGAL/enum.h>
00029 
00030 CGAL_BEGIN_NAMESPACE
00031 
00032 /*{\Moptions outfile=predicates_d.man}*/
00033 /*{\Mtext \setopdims{4cm}{2cm}\computewidths
00034 \headerline{Linear and affine predicates}
00035 
00036 For an iterator range |[first,last)| we define |T = tuple [first,last)|
00037 as the ordered tuple $(|T[0]|,|T[1]|, \ldots |T[d-1]|)$ where 
00038 $|T[i]| = |*| |++|^{(i)}|first|$ (the element obtained by $i$ times 
00039 forwarding the iterator by operator |++| and then dereferencing it to
00040 get the value to which it points). We write |d = size [first,last)|.
00041 This extends the syntax of random access iterators to input iterators. 
00042 If we index the tuple as above then we require that 
00043 $|++|^{(d+1)}|first == last|$.
00044 
00045 In the following we require the Iterators to be globally 
00046 of value type |Point_d<R>|. Also if we are handed over an iterator
00047 range |[first,last)|, then all points in |T = tuple [first,last)|
00048 have the same dimension |dim|.
00049 }*/
00050 
00051 template <class R, class ForwardIterator, class OutputIterator>
00052 OutputIterator barycentric_coordinates(
00053   ForwardIterator first, ForwardIterator last, const Point_d<R>& p, 
00054   OutputIterator result)
00055 /*{\Xfunc returns the barycentric coordinates of a point $p \in R^d$ in a
00056 affine space of dimension $k$ spanned by the points in |tuple [first,last)|.
00057 \precond value type of |ForwardIterator| is |Point_d<R>|,
00058 |affinely_independed(first,last)| and 
00059 |affine_rank(tuple [first,last),p)==k|.}*/
00060 { typename R::Barycentric_coordinates_d coords;
00061   return coords(first,last,p,result);
00062 }
00063 
00064 template <class ForwardIterator>
00065 Orientation
00066 orientation(ForwardIterator first, ForwardIterator last)
00067 /*{\Mfunc determines the orientation of the points in the tuple 
00068 |A = tuple [first,last)| where $A$ consists of $d + 1$ points in $d$ - space. 
00069 This is the sign of the determinant
00070   \[ \left\Lvert \begin{array}{cccc}
00071   1 & 1 & 1 & 1 \\
00072   A[0] & A[1] & \dots & A[d]
00073   \end{array}  \right\Lvert  \]
00074   where |A[i]| denotes the cartesian coordinate vector of 
00075   the $i$-th point in $A$.
00076   \precond |size [first,last) == d+1| and |A[i].dimension() == d| 
00077   $\forall 0 \leq i \leq d$
00078   and the value type of |ForwardIterator| is |Point_d<R>|.}*/
00079 { typedef typename std::iterator_traits<ForwardIterator>::value_type PointD;
00080   typedef typename PointD::R R;
00081   typename R::Orientation_d or_; return or_(first,last); }
00082 
00083 template <class R, class ForwardIterator>
00084 Oriented_side side_of_oriented_sphere(
00085   ForwardIterator first, ForwardIterator last, 
00086   const Point_d<R>& x)
00087 /*{\Mfuncl determines to which side of the sphere $S$ defined by the
00088     points in |A = tuple [first,last)| the point $x$ belongs, 
00089     where $A$ consists of $d + 1$ points in $d$ - space.  
00090     The positive side is determined by the positive sign 
00091     of the determinant \[
00092     \left\Lvert \begin{array}{ccccc} 
00093     1 & 1 & 1 & 1 & 1\\
00094     |lift(A[0])| & |lift(A[1])| & \dots & |lift(A[d])| & |lift(x)| 
00095     \end{array} \right\Lvert \] 
00096     where for a point $p$ with cartesian coordinates $p_i$ we use 
00097     |lift(p)| to denote the $d + 1$-dimensional point with cartesian 
00098     coordinate vector $(p_0, \ldots,p_{d-1},\sum_{0 \le i < d}p_i^2)$. If
00099     the points in $A$ are positively oriented then the positive
00100     side is the inside of the sphere and the negative side is
00101     the outside of the sphere.  
00102 \precond value type of |ForwardIterator| is |Point_d<R>|.}*/
00103 { typename R::Side_of_oriented_sphere_d side; 
00104   return side(first,last,x); }
00105 
00106 template <class R, class ForwardIterator>
00107 Bounded_side side_of_bounded_sphere(
00108   ForwardIterator first, ForwardIterator last,
00109   const Point_d<R> &p)
00110 /*{\Mfunc determines whether the point |p| lies |ON_BOUNDED_SIDE|, 
00111 |ON_BOUNDARY|, or |ON_UNBOUNDED_SIDE| of the sphere defined by 
00112 the points in |A = tuple [first,last)| where $A$ consists of $d+1$ 
00113 points in $d$-space.
00114 \precond value type of |ForwardIterator| is |Point_d<R>| and
00115 $|orientation(first,last)| \neq |ZERO|$.}*/
00116 { typename R::Side_of_bounded_sphere_d side; 
00117   return side(first,last,p); }
00118 
00119 template <class R, class ForwardIterator>
00120 bool contained_in_simplex(
00121   ForwardIterator first, ForwardIterator last, const Point_d<R>& p) 
00122 /*{\Mfunc determines whether |p| is contained in the simplex spanned
00123 by the points in |A = tuple [first,last)|. |A| may consists of up to 
00124 $d + 1$ points. 
00125 \precond value type of |ForwardIterator| is |Point_d<R>| and
00126 the points in |A| are affinely independent.}*/
00127 { typename R::Contained_in_simplex_d contained; 
00128   return contained(first,last,p); }
00129 
00130 template <class R, class ForwardIterator>
00131 bool contained_in_affine_hull(
00132      ForwardIterator first, ForwardIterator last,
00133      const Point_d<R>& p) 
00134 /*{\Mfunc determines whether $p$ is contained in the affine hull
00135 of the points in |A = tuple [first,last)|.
00136 \precond value type of |ForwardIterator| is |Point_d<R>|.}*/
00137 { typename R::Contained_in_affine_hull_d contained; 
00138   return contained(first,last,p); }
00139 
00140 template <class ForwardIterator>
00141 int affine_rank(ForwardIterator first, ForwardIterator last)
00142 /*{\Mfunc computes the affine rank of the points in |A = tuple [first,last)|.
00143 \precond value type of |ForwardIterator| is |Point_d<R>|.}*/
00144 { typedef typename std::iterator_traits<ForwardIterator>::value_type PointD;
00145   typedef typename PointD::R R;
00146   typename R::Affine_rank_d rank; 
00147   return rank(first,last); }
00148 
00149 template <class ForwardIterator>
00150 bool affinely_independent(ForwardIterator first, ForwardIterator last)
00151 /*{\Mfunc decides whether the points in |A = tuple [first,last)| are 
00152 affinely independent. 
00153 \precond value type of |ForwardIterator| is |Point_d<R>|.}*/
00154 { typedef typename std::iterator_traits<ForwardIterator>::value_type PointD;
00155   typedef typename PointD::R R;
00156   typename R::Affinely_independent_d ind; 
00157   return ind(first,last); }
00158 
00159 template <class R>
00160 Comparison_result compare_lexicographically( 
00161   const Point_d<R>& p1, const Point_d<R>& p2)
00162 /*{\Mfunc compares the Cartesian coordiantes of points |p1| and |p2|
00163    lexicographically.}*/
00164 { typename R::Compare_lexicographically_d cmp; 
00165   return cmp(p1,p2); }
00166 
00167 template <class R>
00168 bool lexicographically_smaller( 
00169   const Point_d<R>& p1, const Point_d<R>& p2)
00170 /*{\Mfunc returns true iff $|p1| < |p2|$ in the Cartesian lexicographic
00171    order of points.}*/
00172 { typename R::Less_lexicographically_d lt;
00173   return lt(p1,p2); }
00174 
00175 template <class R>
00176 bool lexicographically_smaller_or_equal(
00177   const Point_d<R>& p1, const Point_d<R>& p2)
00178 /*{\Mfunc returns true iff $|p1| \leq |p2|$ in the Cartesian lexicographic
00179    order of points.}*/
00180 { typename R::Less_or_equal_lexicographically_d le;
00181   return le(p1,p2); }
00182 
00183 template <class R, class ForwardIterator>
00184 bool contained_in_linear_hull(
00185   ForwardIterator first, ForwardIterator last, const Vector_d<R>& x)
00186 /*{\Mfunc determines whether $x$ is contained in the linear hull
00187 of the vectors in |A = tuple [first,last)|. 
00188 \precond value type of |ForwardIterator| is |Vector_d<R>|.}*/
00189 { typename R::Contained_in_linear_hull_d contained; 
00190   return contained(first,last,x); }
00191 
00192 template <class ForwardIterator>
00193 int linear_rank(
00194   ForwardIterator first, ForwardIterator last)
00195 /*{\Mfunc computes the linear rank of the vectors in 
00196 |A = tuple [first,last)|. 
00197 \precond value type of |ForwardIterator| is |Vector_d<R>|.}*/
00198 { typedef typename std::iterator_traits<ForwardIterator>::
00199     value_type value_type;
00200   typedef typename value_type::R R;
00201   typename R::Linear_rank_d rank; 
00202   return rank(first,last); 
00203 }
00204 
00205 template <class ForwardIterator>
00206 bool linearly_independent(
00207   ForwardIterator first, ForwardIterator last)
00208 /*{\Mfunc decides whether the vectors in $A$ are linearly independent.
00209 \precond value type of |ForwardIterator| is |Vector_d<R>|.}*/
00210 { TUPLE_DIM_CHECK(first,last,linearly_independent);
00211   typedef typename std::iterator_traits<ForwardIterator>::
00212     value_type value_type;
00213   typedef typename value_type::R R;
00214   typename R::Linearly_independent_d independent; 
00215   return independent(first,last);
00216 }
00217 
00218 
00219 CGAL_END_NAMESPACE
00220 #endif // CGAL_PREDICATES_D_H
00221 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines