BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Iso_rectangle_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/Iso_rectangle_2.h $
00019 // $Id: Iso_rectangle_2.h 42932 2008-04-17 10:13:31Z spion $
00020 //
00021 //
00022 // Author(s)     : Andreas Fabri
00023 
00024 #ifndef CGAL_ISO_RECTANGLE_2_H
00025 #define CGAL_ISO_RECTANGLE_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 Iso_rectangle_2 : public R_::Kernel_base::Iso_rectangle_2
00037 {
00038   typedef typename R_::RT                    RT;
00039   typedef typename R_::FT                    FT;
00040   typedef typename R_::Point_2               Point_2;
00041   typedef typename R_::Aff_transformation_2  Aff_transformation_2;
00042 
00043   typedef Iso_rectangle_2                    Self;
00044   BOOST_STATIC_ASSERT((boost::is_same<Self, typename R_::Iso_rectangle_2>::value));
00045 
00046 public:
00047 
00048   typedef Dimension_tag<2>  Ambient_dimension;
00049   typedef Dimension_tag<2>  Feature_dimension;
00050 
00051   typedef typename R_::Kernel_base::Iso_rectangle_2  Rep;
00052 
00053   const Rep& rep() const
00054   {
00055     return *this;
00056   }
00057 
00058   Rep& rep()
00059   {
00060     return *this;
00061   }
00062 
00063   typedef  R_   R;
00064 
00065   Iso_rectangle_2() {}
00066 
00067   Iso_rectangle_2(const Rep& r)
00068     : Rep(r) {}
00069 
00070   Iso_rectangle_2(const Point_2 &p, const Point_2 &q, int)
00071     : Rep(typename R::Construct_iso_rectangle_2()(Return_base_tag(), p, q, 0)) {}
00072 
00073   Iso_rectangle_2(const Point_2 &p, const Point_2 &q)
00074     : Rep(typename R::Construct_iso_rectangle_2()(Return_base_tag(), p, q)) {}
00075 
00076   Iso_rectangle_2(const Point_2 &left, const Point_2 &right,
00077                   const Point_2 &bottom, const Point_2 &top)
00078     : Rep(typename R::Construct_iso_rectangle_2()(Return_base_tag(), left, right, bottom, top)) {}
00079 
00080   Iso_rectangle_2(const RT& min_hx, const RT& min_hy,
00081                   const RT& max_hx, const RT& max_hy)
00082     : Rep(typename R::Construct_iso_rectangle_2()(Return_base_tag(), min_hx, min_hy, max_hx, max_hy)) {}
00083 
00084   Iso_rectangle_2(const RT& min_hx, const RT& min_hy,
00085                   const RT& max_hx, const RT& max_hy, const RT& hw)
00086     : Rep(typename R::Construct_iso_rectangle_2()(Return_base_tag(), min_hx, min_hy, max_hx, max_hy, hw)) {}
00087 
00088 
00089   typename Qualified_result_of<typename R::Construct_min_vertex_2, Iso_rectangle_2 >::type
00090   min BOOST_PREVENT_MACRO_SUBSTITUTION () const
00091   {
00092     return R().construct_min_vertex_2_object()(*this);
00093   }
00094 
00095   typename Qualified_result_of<typename R::Construct_max_vertex_2, Iso_rectangle_2 >::type
00096   max BOOST_PREVENT_MACRO_SUBSTITUTION () const
00097   {
00098     return R().construct_max_vertex_2_object()(*this);
00099   }
00100 
00101   bool
00102   operator==(const Iso_rectangle_2 &i) const
00103   {
00104     return R().equal_2_object()(*this, i);
00105   }
00106 
00107   bool
00108   operator!=(const Iso_rectangle_2 &i) const
00109   {
00110     return ! (*this == i);
00111   }
00112 
00113 
00114   typename Qualified_result_of<typename R::Construct_vertex_2, Iso_rectangle_2 >::type
00115   vertex(int i) const
00116   {
00117     return R().construct_vertex_2_object()(*this,i);
00118   }
00119 
00120   typename Qualified_result_of<typename R::Construct_vertex_2, Iso_rectangle_2 >::type
00121   operator[](int i) const
00122   {
00123     return R().construct_vertex_2_object()(*this,i);
00124   }
00125 
00126   typename Qualified_result_of<typename R::Compute_xmin_2, Iso_rectangle_2 >::type
00127   xmin() const
00128   {
00129     return R().compute_xmin_2_object()(*this);
00130   }
00131 
00132   typename Qualified_result_of<typename R::Compute_xmax_2, Iso_rectangle_2 >::type
00133   xmax() const
00134   {
00135     return R().compute_xmax_2_object()(*this);
00136   }
00137 
00138   typename Qualified_result_of<typename R::Compute_ymin_2, Iso_rectangle_2 >::type
00139   ymin() const
00140   {
00141     return R().compute_ymin_2_object()(*this);
00142   }
00143 
00144   typename Qualified_result_of<typename R::Compute_ymax_2, Iso_rectangle_2 >::type
00145   ymax() const
00146   {
00147     return R().compute_ymax_2_object()(*this);
00148   }
00149 
00150   typename Qualified_result_of<typename R::Compute_xmin_2, Iso_rectangle_2 >::type
00151   min_coord(int i) const
00152   {
00153     CGAL_kernel_precondition( i == 0 || i == 1 );
00154     if (i == 0)
00155       return xmin();
00156     else
00157       return ymin();
00158   }
00159 
00160   typename Qualified_result_of<typename R::Compute_xmin_2, Iso_rectangle_2 >::type
00161   max_coord(int i) const
00162   {
00163     CGAL_kernel_precondition( i == 0 || i == 1 );
00164     if (i == 0)
00165       return xmax();
00166     else
00167       return ymax();
00168   }
00169 
00170   FT
00171   area() const
00172   {
00173     return R().compute_area_2_object()(*this);
00174   }
00175 
00176 
00177   bool
00178   has_on_boundary(const Point_2 &p) const
00179   {
00180     return R().has_on_boundary_2_object()(*this,p);
00181   }
00182 
00183 
00184   bool
00185   has_on_bounded_side(const Point_2 &p) const
00186   {
00187     return R().has_on_bounded_side_2_object()(*this,p);
00188   }
00189 
00190 
00191   bool
00192   has_on_unbounded_side(const Point_2 &p) const
00193   {
00194     return R().has_on_unbounded_side_2_object()(*this,p);
00195   }
00196 
00197   Bounded_side
00198   bounded_side(const Point_2 &p) const
00199   {
00200     return R().bounded_side_2_object()(*this,p);
00201   }
00202 
00203 
00204   bool
00205   is_degenerate() const
00206   {
00207     return R().is_degenerate_2_object()(*this);
00208   }
00209 
00210   Bbox_2
00211   bbox() const
00212   {
00213     return R().construct_bbox_2_object()(*this);
00214   }
00215 
00216   Iso_rectangle_2 transform(const Aff_transformation_2 &t) const
00217   {
00218     // FIXME : We need a precondition like this!!!
00219     // CGAL_kernel_precondition(t.is_axis_preserving());
00220     return Iso_rectangle_2(t.transform(min  BOOST_PREVENT_MACRO_SUBSTITUTION ()), 
00221                            t.transform(max  BOOST_PREVENT_MACRO_SUBSTITUTION ()));
00222   }
00223 };
00224 
00225 
00226 template < class R >
00227 std::ostream &
00228 operator<<(std::ostream &os, const Iso_rectangle_2<R> &r)
00229 {
00230   switch(os.iword(IO::mode)) {
00231   case IO::ASCII :
00232     return os << (r.min)() << ' ' << (r.max)();
00233   case IO::BINARY :
00234     return os << (r.min)() << (r.max)();
00235   default:
00236     return os << "Iso_rectangle_2(" << (r.min)() << ", " << (r.max)() << ")";
00237   }
00238 }
00239 
00240 template < class R >
00241 std::istream &
00242 operator>>(std::istream &is, Iso_rectangle_2<R> &r)
00243 {
00244   typename R::Point_2 p, q;
00245 
00246   is >> p >> q;
00247 
00248   if (is)
00249     r = Iso_rectangle_2<R>(p, q);
00250   return is;
00251 }
00252 
00253 CGAL_END_NAMESPACE
00254 
00255 #endif // CGAL_ISO_RECTANGLE_2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines