BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Bbox_2.h
Go to the documentation of this file.
00001 // Copyright (c) 1999,2004  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/Bbox_2.h $
00019 // $Id: Bbox_2.h 49057 2009-04-30 14:03:52Z spion $
00020 //
00021 // Author(s)     : Andreas Fabri
00022 
00023 #ifndef CGAL_BBOX_2_H
00024 #define CGAL_BBOX_2_H
00025 
00026 #include <CGAL/basic.h>
00027 #include <CGAL/kernel_assertions.h>
00028 #include <CGAL/IO/io.h>
00029 #include <CGAL/Dimension.h>
00030 #include <CGAL/array.h>
00031 
00032 CGAL_BEGIN_NAMESPACE
00033 
00034 template < typename T >
00035 struct Simple_cartesian;
00036 
00037 class Bbox_2
00038 {
00039   typedef cpp0x::array<double, 4>            BBox_rep_2;
00040 
00041   BBox_rep_2 rep;
00042 
00043 public:
00044 
00045   typedef Dimension_tag<2>  Ambient_dimension;
00046   typedef Dimension_tag<2>  Feature_dimension;
00047 
00048   typedef Simple_cartesian<double>  R;
00049 
00050              Bbox_2() {}
00051 
00052              Bbox_2(double x_min, double y_min,
00053                     double x_max, double y_max)
00054                  : rep(CGAL::make_array(x_min, y_min, x_max, y_max)) {}
00055 
00056   inline bool       operator==(const Bbox_2 &b) const;
00057   inline bool       operator!=(const Bbox_2 &b) const;
00058 
00059   inline int        dimension() const;
00060   inline double     xmin() const;
00061   inline double     ymin() const;
00062   inline double     xmax() const;
00063   inline double     ymax() const;
00064 
00065   inline double     max BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const;
00066   inline double     min BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const;
00067 
00068   inline Bbox_2     operator+(const Bbox_2 &b) const;
00069 
00070 };
00071 
00072 inline
00073 double
00074 Bbox_2::xmin() const
00075 { return rep[0]; }
00076 
00077 inline
00078 double
00079 Bbox_2::ymin() const
00080 { return rep[1]; }
00081 
00082 inline
00083 double
00084 Bbox_2::xmax() const
00085 { return rep[2]; }
00086 
00087 inline
00088 double
00089 Bbox_2::ymax() const
00090 { return rep[3]; }
00091 
00092 inline
00093 bool
00094 Bbox_2::operator==(const Bbox_2 &b) const
00095 {
00096   return    xmin() == b.xmin() && xmax() == b.xmax()
00097          && ymin() == b.ymin() && ymax() == b.ymax();
00098 }
00099 
00100 inline
00101 bool
00102 Bbox_2::operator!=(const Bbox_2 &b) const
00103 {
00104   return ! (b == *this);
00105 }
00106 
00107 inline
00108 int
00109 Bbox_2::dimension() const
00110 { return 2; }
00111 
00112 inline
00113 double
00114 Bbox_2::min BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const
00115 {
00116   CGAL_kernel_precondition( (i == 0 ) || ( i == 1 ) );
00117   if(i == 0) { return xmin(); }
00118   return ymin();
00119 }
00120 
00121 inline
00122 double
00123 Bbox_2::max BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const
00124 {
00125   CGAL_kernel_precondition( (i == 0 ) || ( i == 1 ) );
00126   if(i == 0) { return xmax(); }
00127   return ymax();
00128 }
00129 
00130 inline
00131 Bbox_2
00132 Bbox_2::operator+(const Bbox_2 &b) const
00133 {
00134   return Bbox_2((std::min)(xmin(), b.xmin()),
00135                 (std::min)(ymin(), b.ymin()),
00136                 (std::max)(xmax(), b.xmax()),
00137                 (std::max)(ymax(), b.ymax()));
00138 }
00139 
00140 inline
00141 bool
00142 do_overlap(const Bbox_2 &bb1, const Bbox_2 &bb2)
00143 {
00144     // check for emptiness ??
00145     if (bb1.xmax() < bb2.xmin() || bb2.xmax() < bb1.xmin())
00146         return false;
00147     if (bb1.ymax() < bb2.ymin() || bb2.ymax() < bb1.ymin())
00148         return false;
00149     return true;
00150 }
00151 
00152 inline
00153 std::ostream&
00154 operator<<(std::ostream &os, const Bbox_2 &b)
00155 {
00156     switch(os.iword(IO::mode)) {
00157     case IO::ASCII :
00158         os << b.xmin() << ' ' << b.ymin() << ' '
00159            << b.xmax() << ' ' << b.ymax();
00160         break;
00161     case IO::BINARY :
00162         write(os, b.xmin());
00163         write(os, b.ymin());
00164         write(os, b.xmax());
00165         write(os, b.ymax());
00166         break;
00167     default:
00168         os << "Bbox_2(" << b.xmin() << ", " << b.ymin() << ", "
00169                         << b.xmax() << ", " << b.ymax() << ")";
00170         break;
00171     }
00172     return os;
00173 }
00174 
00175 inline
00176 std::istream&
00177 operator>>(std::istream &is, Bbox_2 &b)
00178 {
00179     double xmin, ymin, xmax, ymax;
00180 
00181     switch(is.iword(IO::mode)) {
00182     case IO::ASCII :
00183         is >> xmin >> ymin >> xmax >> ymax;
00184         break;
00185     case IO::BINARY :
00186         read(is, xmin);
00187         read(is, ymin);
00188         read(is, xmax);
00189         read(is, ymax);
00190         break;
00191     }
00192     if (is)
00193       b = Bbox_2(xmin, ymin, xmax, ymax);
00194     return is;
00195 }
00196 
00197 CGAL_END_NAMESPACE
00198 
00199 #endif // CGAL_BBOX_2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines