Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
include/CGAL/Bbox_2.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: Bbox_2.h,v 1.6 2008/12/06 08:43:26 mtcampbe Exp $
24 
25 #ifndef CGAL_OPT_BBOX_2_H
26 #define CGAL_OPT_BBOX_2_H
27 
28 #include <CGAL/basic.h>
29 #include <cmath>
30 
32 
33 class Bbox_2
34 {
35 public:
36  Bbox_2() {
37  _min[0] = _min[1] = HUGE_VAL;
38  _max[0] = _max[1] = -HUGE_VAL;
39  }
40  Bbox_2(double x_min, double y_min, double x_max, double y_max)
41  { _min[0]=x_min; _min[1]=y_min; _max[0]=x_max; _max[1]=y_max; }
42 
43  // Bbox_2(const Bbox_2 &);
44  // Bbox_2 &operator=(const Bbox_2 &b);
45  // bool operator==(const Bbox_2 &b) const;
46  // bool operator!=(const Bbox_2 &b) const;
47 
48  int dimension() const { return 2; }
49  double xmin() const { return _min[0]; }
50  double ymin() const { return _min[1]; }
51  double xmax() const { return _max[0]; }
52  double ymax() const { return _max[1]; }
53 
54 
55  double min(int i) const {
56  CGAL_kernel_precondition( (i == 0 ) || ( i == 1 ) );
57  if(i == 0) {
58  return xmin();
59  }
60  return ymin();
61  }
62 
63  double max(int i) const {
64  CGAL_kernel_precondition( (i == 0 ) || ( i == 1 ) );
65  if(i == 0) {
66  return xmax();
67  }
68  return ymax();
69  }
70 
71  Bbox_2 operator+(const Bbox_2& b) const {
72  Bbox_2 box=*this; box+=b; return box;
73  }
74 
75  Bbox_2& operator+=(const Bbox_2& b) {
76  _min[0] = std::min(_min[0], b._min[0]);
77  _min[1] = std::min(_min[1], b._min[1]);
78 
79  _max[0] = std::max(_max[0], b._max[0]);
80  _max[1] = std::max(_max[1], b._max[1]);
81 
82  return *this;
83  }
84 private:
85  double _min[2],_max[2];
86 };
87 
88 #ifndef NO_OSTREAM_INSERT_BBOX_2
89 inline
90 std::ostream&
91 operator<<(std::ostream &os, const Bbox_2 &b)
92 {
93  switch(os.iword(IO::mode)) {
94  case IO::ASCII :
95  os << b.xmin() << ' ' << b.ymin() << ' '
96  << b.xmax() << ' ' << b.ymax();
97  break;
98  case IO::BINARY :
99  write(os, b.xmin());
100  write(os, b.ymin());
101  write(os, b.xmax());
102  write(os, b.ymax());
103  break;
104  default:
105  os << "Bbox_2(" << b.xmin() << ", " << b.ymin() << ", "
106  << b.xmax() << ", " << b.ymax() << ")";
107  break;
108  }
109  return os;
110 }
111 #endif // NO_OSTREAM_INSERT_BBOX_2
112 
113 
114 
115 #ifndef NO_ISTREAM_EXTRACT_BBOX_2
116 inline
117 std::istream&
118 operator>>(std::istream &is, Bbox_2 &b)
119 {
120  double xmin, ymin, xmax, ymax;
121 
122  switch(is.iword(IO::mode)) {
123  case IO::ASCII :
124  is >> xmin >> ymin >> xmax >> ymax;
125  break;
126  case IO::BINARY :
127  read(is, xmin);
128  read(is, ymin);
129  read(is, xmax);
130  read(is, ymax);
131  break;
132  }
133  b = Bbox_2(xmin, ymin, xmax, ymax);
134  return is;
135 }
136 #endif // NO_ISTREAM_EXTRACT_BBOX_2
137 
138 inline bool do_overlap(const Bbox_2& bb1, const Bbox_2& bb2)
139 {
140  // check for emptiness ??
141  if (bb1.xmax() < bb2.xmin() || bb2.xmax() < bb1.xmin())
142  return false;
143  if (bb1.ymax() < bb2.ymin() || bb2.ymax() < bb1.ymin())
144  return false;
145  return true;
146 }
147 
149 
150 #include <CGAL/cgalopt.h>
151 
153 using CGAL::Bbox_2;
154 
155 inline bool do_overlap_eps(const Bbox_2& bb1, const Bbox_2& bb2,
156  const double eps) {
157  // check for emptiness ??
158  if (bb1.xmax()+eps < bb2.xmin() || bb2.xmax()+eps < bb1.xmin())
159  return false;
160  if (bb1.ymax()+eps < bb2.ymin() || bb2.ymax()+eps < bb1.ymin())
161  return false;
162  return true;
163 }
164 
165 inline bool do_overlap_strict(const Bbox_2& bb1, const Bbox_2& bb2)
166 {
167  if (bb1.xmax() <= bb2.xmin() || bb2.xmax() <= bb1.xmin())
168  return false;
169  if (bb1.ymax() <= bb2.ymin() || bb2.ymax() <= bb1.ymin())
170  return false;
171  return true;
172 }
173 
174 template <class InIter>
175 Bbox_2 get_Bbox_2(InIter first, InIter last) {
176  Bbox_2 box;
177 
178  while (first != last) {
179  box += first->bbox();
180  ++first;
181  }
182  return box;
183 }
184 
186 
187 #endif // CGAL_OPT_BBOX_2_H
188 
189 
190 
191 
192 
193 
double ymin() const
Bbox_2(double x_min, double y_min, double x_max, double y_max)
bool do_overlap_strict(const Bbox_2 &bb1, const Bbox_2 &bb2)
double xmax() const
Bbox_2 & operator+=(const Bbox_2 &b)
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
KD_tree::Box box
Definition: Overlay_0d.C:47
double xmin() const
Bbox_2 operator+(const Bbox_2 &b) const
int dimension() const
Definition: io.h:64
void write(std::ostream &os, const T &t, const io_Read_write &)
Definition: io.h:96
double min(int i) const
Bbox_2 get_Bbox_2(InIter first, InIter last)
double max(int i) const
blockLoc i
Definition: read.cpp:79
double _max[2]
static int mode
Definition: io.h:63
Definition: io.h:64
double ymax() const
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
bool do_overlap(const Bbox_2 &bb1, const Bbox_2 &bb2)
void read(std::istream &is, T &t, const io_Read_write &)
Definition: io.h:132
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
std::istream & operator>>(std::istream &is, CGAL::Aff_transformation_2< R > &t)
#define CGAL_OPT_END_NAMESPACE
Definition: cgalopt.h:33
bool do_overlap_eps(const Bbox_2 &bb1, const Bbox_2 &bb2, const double eps)
std::ostream & operator<<(std::ostream &os, const COM_exception &ex)
Print out a given exception.
double _min[2]
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
#define CGAL_kernel_precondition(EX)
#define CGAL_OPT_BEGIN_NAMESPACE
Definition: cgalopt.h:32