1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/***************************************************************************
bbox.hh - Bounding boxes
-------------------
begin : Sun Jun 11 2000
copyright : (C) 2000 by Erik Schnetter
email : schnetter@astro.psu.edu
$Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/bbox.hh,v 1.3 2001/03/07 13:00:57 eschnett Exp $
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef BBOX_HH
#define BBOX_HH
#include <iostream>
#include "defs.hh"
#include "vect.hh"
// Forward definition
template<class T, int D> class bbox;
// Output
template<class T,int D>
ostream& operator<< (ostream& os, const bbox<T,D>& b);
// Bounding box class
template<class T, int D>
class bbox {
// Fields
vect<T,D> _lower, _upper, _stride; // bounds are inclusive
public:
// Constructors
bbox ();
bbox (const bbox& b);
bbox& operator= (const bbox& b);
bbox (const vect<T,D>& lower, const vect<T,D>& upper,
const vect<T,D>& stride);
// Accessors
const vect<T,D>& lower () const { return _lower; }
const vect<T,D>& upper () const { return _upper; }
const vect<T,D>& stride () const { return _stride; }
vect<T,D> shape () const { return _upper - _lower + _stride; }
bool empty() const {
return any(lower()>upper());
}
T size () const;
T num_points () const;
// Queries
bool contains (const vect<T,D>& x) const;
// Operators
bool operator== (const bbox& b) const;
bool operator!= (const bbox& b) const;
bool operator< (const bbox& b) const;
bool operator> (const bbox& b) const;
bool operator<= (const bbox& b) const;
bool operator>= (const bbox& b) const;
// Intersection
bbox operator& (const bbox& b) const;
// Containment
bool contained_in (const bbox& b) const;
// Alignment check
bool aligned_with (const bbox& b) const;
// Expand the bbox a little by multiples of the stride
bbox expand (const vect<T,D>& lo, const vect<T,D>& hi) const;
// Find the smallest b-compatible box around *this
bbox expanded_for (const bbox& b) const;
// Find the largest b-compatible box inside *this
bbox contracted_for (const bbox& b) const;
// Set operations
// Smallest bbox containing both boxes
bbox operator* (const bbox& b) const;
bbox& operator*= (const bbox& b);
// Largest bbox inside both boxes
bbox operator+ (const bbox& b) const;
bbox& operator+= (const bbox& b);
// Iterators
class iterator {
protected:
bbox box;
vect<T,D> pos;
public:
iterator (const bbox& box, const vect<T,D>& pos);
const vect<T,D>& operator* () const { return pos; }
bool operator!= (const iterator& i) const;
iterator& operator++ ();
};
iterator begin () const;
iterator end () const;
// Output
friend ostream& operator<< <>(ostream& os, const bbox& b);
};
#if defined(TMPL_IMPLICIT)
# include "bbox.cc"
#endif
#endif // BBOX_HH
|