aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/bboxset.hh
blob: 4883cc6e92cc6772909e98c0effca33704fe92be (plain)
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
/***************************************************************************
                          bboxset.hh  -  Sets of 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/bboxset.hh,v 1.4 2001/03/22 18:42:05 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 BBOXSET_HH
#define BBOXSET_HH

#include <assert.h>

#include <iostream>
#include <set>

#include "bbox.hh"
#include "defs.hh"
#include "vect.hh"

using namespace std;



// Forward definition
template<class T, int D> class bboxset;

template<class T,int D>
bboxset<T,D> operator- (const bbox<T,D>& b1, const bbox<T,D>& b2);
template<class T,int D>
bboxset<T,D> operator- (const bbox<T,D>& b, const bboxset<T,D>& s);

// Output
template<class T,int D>
ostream& operator<< (ostream& os, const bboxset<T,D>& s);



// Bounding box class
template<class T, int D>
class bboxset {
  
  // Types
  typedef bbox<T,D> box;
  typedef set<box> bset;
  
  // Fields
  bset bs;
  // Invariant:
  // All bboxes have the same stride.
  // No bbox is empty.
  // The bboxes don't overlap.
  
public:
  
  // Constructors
  bboxset ();
  bboxset (const box& b);
  bboxset (const bboxset& s);
  bboxset (const bset& bs);
  
  // Invariant
  bool invariant () const;
  
  // Normalisation
  void normalize ();
  
  // Accessors
  bool empty () const { return bs.empty(); }
  T size () const;
  
  // Add (bboxes that don't overlap)
  bboxset& operator+= (const box& b);
  bboxset& operator+= (const bboxset& s);
  bboxset operator+ (const box& b) const;
  bboxset operator+ (const bboxset& s) const;
  
  // Union
  bboxset& operator|= (const box& b);
  bboxset& operator|= (const bboxset& s);
  bboxset operator| (const box& b) const;
  bboxset operator| (const bboxset& s) const;
  
  // Intersection
  bboxset operator& (const box& b) const;
  bboxset operator& (const bboxset& s) const;
  bboxset& operator&= (const box& b);
  bboxset& operator&= (const bboxset& s);
  
  // Difference
  // friend bboxset operator- <T,D>(const box& b1, const box& b2);
  bboxset operator- (const box& b) const;
  bboxset& operator-= (const box& b);
  bboxset& operator-= (const bboxset& s);
  bboxset operator- (const bboxset& s) const;
  // friend bboxset operator- <T,D>(const box& b, const bboxset& s);
  
  // Iterators
  typedef typename bset::const_iterator const_iterator;
  typedef typename bset::iterator       iterator;
  
  iterator begin () const { return bs.begin(); }
  iterator end () const   { return bs.end(); }
  
  // Output
  friend ostream& operator<< <>(ostream& os, const bboxset& s);
};



#if defined(TMPL_IMPLICIT)
#  include "bboxset.cc"
#endif

#endif // BBOXSET_HH