BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Triangle_2.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/Kernel_23/include/CGAL/Triangle_2.h $
00019 // $Id: Triangle_2.h 45156 2008-08-26 13:40:26Z spion $
00020 //
00021 //
00022 // Author(s)     : Andreas Fabri
00023 
00024 #ifndef CGAL_TRIANGLE_2_H
00025 #define CGAL_TRIANGLE_2_H
00026 
00027 #include <boost/static_assert.hpp>
00028 #include <boost/type_traits.hpp>
00029 #include <CGAL/Kernel/Return_base_tag.h>
00030 #include <CGAL/Bbox_2.h>
00031 #include <CGAL/Dimension.h>
00032 
00033 CGAL_BEGIN_NAMESPACE
00034 
00035 template <class R_>
00036 class Triangle_2 : public R_::Kernel_base::Triangle_2
00037 {
00038   typedef typename R_::Point_2          Point_2;
00039   typedef typename R_::Aff_transformation_2 Aff_transformation_2;
00040   typedef typename R_::Kernel_base::Triangle_2  RTriangle_2;
00041 
00042   typedef Triangle_2                            Self;
00043   BOOST_STATIC_ASSERT((boost::is_same<Self, typename R_::Triangle_2>::value));
00044 
00045 public:
00046 
00047   typedef Dimension_tag<2>  Ambient_dimension;
00048   typedef Dimension_tag<2>  Feature_dimension;
00049 
00050   typedef RTriangle_2 Rep;
00051 
00052   const Rep& rep() const
00053   {
00054     return *this;
00055   }
00056 
00057   Rep& rep()
00058   {
00059     return *this;
00060   }
00061 
00062   typedef  R_                          R;
00063   typedef typename R::FT               FT;
00064 
00065   Triangle_2() {}
00066 
00067   Triangle_2(const RTriangle_2& t)
00068       : RTriangle_2(t) {}
00069 
00070   Triangle_2(const Point_2 &p, const Point_2 &q, const Point_2 &r)
00071       : RTriangle_2(typename R::Construct_triangle_2()(Return_base_tag(), p,q,r)) {}
00072 
00073   FT
00074   area() const
00075   {
00076     return R().compute_area_2_object()(vertex(0), vertex(1), vertex(2));
00077   }
00078 
00079   typename R::Orientation
00080   orientation() const
00081   {
00082     return R().orientation_2_object()(vertex(0), vertex(1), vertex(2));
00083   }
00084 
00085   typename R::Bounded_side
00086   bounded_side(const Point_2 &p) const
00087   {
00088     return R().bounded_side_2_object()(*this,p);
00089   }
00090 
00091   typename R::Oriented_side
00092   oriented_side(const Point_2 &p) const
00093   {
00094     return R().oriented_side_2_object()(*this,p);
00095   }
00096 
00097   typename R::Boolean
00098   operator==(const Triangle_2 &t) const
00099   {
00100     return R().equal_2_object()(*this,t);
00101   }
00102 
00103   typename R::Boolean
00104   operator!=(const Triangle_2 &t) const
00105   {
00106     return !(*this == t);
00107   }
00108 
00109   typename Qualified_result_of<typename R::Construct_vertex_2, Triangle_2, int>::type
00110   vertex(int i) const
00111   {
00112     return R().construct_vertex_2_object()(*this,i);
00113   }
00114 
00115   typename Qualified_result_of<typename R::Construct_vertex_2, Triangle_2, int>::type
00116   operator[](int i) const
00117   {
00118     return vertex(i);
00119   }
00120 
00121   typename R::Boolean
00122   has_on_bounded_side(const Point_2 &p) const
00123   {
00124     return bounded_side(p) == ON_BOUNDED_SIDE;
00125   }
00126 
00127   typename R::Boolean
00128   has_on_unbounded_side(const Point_2 &p) const
00129   {
00130     return bounded_side(p) == ON_UNBOUNDED_SIDE;
00131   }
00132 
00133   typename R::Boolean
00134   has_on_boundary(const Point_2 &p) const
00135   {
00136     return bounded_side(p) == ON_BOUNDARY;
00137   }
00138 
00139   typename R::Boolean
00140   has_on_negative_side(const Point_2 &p) const
00141   {
00142     return oriented_side(p) == ON_NEGATIVE_SIDE;
00143   }
00144 
00145   typename R::Boolean
00146   has_on_positive_side(const Point_2 &p) const
00147   {
00148     return oriented_side(p) == ON_POSITIVE_SIDE;
00149   }
00150 
00151   typename R::Boolean
00152   is_degenerate() const
00153   {
00154     return R().collinear_2_object()(vertex(0), vertex(1), vertex(2));
00155   }
00156 
00157   Bbox_2
00158   bbox() const
00159   {
00160     return R().construct_bbox_2_object()(*this);
00161   }
00162 
00163   Triangle_2
00164   opposite() const
00165   {
00166     return R().construct_opposite_triangle_2_object()(*this);
00167   }
00168 
00169   Triangle_2
00170   transform(const Aff_transformation_2 &t) const
00171   {
00172     return Triangle_2(t.transform(vertex(0)),
00173                       t.transform(vertex(1)),
00174                       t.transform(vertex(2)));
00175   }
00176 
00177 };
00178 
00179 
00180 template < class R >
00181 std::ostream &
00182 operator<<(std::ostream &os, const Triangle_2<R> &t)
00183 {
00184     switch(os.iword(IO::mode)) {
00185     case IO::ASCII :
00186         return os << t[0] << ' ' << t[1] << ' ' << t[2];
00187     case IO::BINARY :
00188         return os << t[0] << t[1]  << t[2];
00189     default:
00190         return os<< "Triangle_2(" << t[0] << ", "
00191                  << t[1] << ", " << t[2] <<")";
00192     }
00193 }
00194 
00195 template < class R >
00196 std::istream &
00197 operator>>(std::istream &is, Triangle_2<R> &t)
00198 {
00199     typename R::Point_2 p, q, r;
00200 
00201     is >> p >> q >> r;
00202 
00203     if (is)
00204         t = Triangle_2<R>(p, q, r);
00205     return is;
00206 }
00207 
00208 CGAL_END_NAMESPACE
00209 
00210 #endif // CGAL_TRIANGLE_2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines