summaryrefslogtreecommitdiff
path: root/src/kboxco2.cc
blob: 9d0ad8306b21fd53d71355f991f4a8a879471379 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include <kboxco2.h>

K_BOXCO2 :: K_BOXCO2()
{
  unsigned long i;
  
  for (i = 0; i < 2; i++)
  {
    low[i]       = 0;
    high[i]      = 0;
    low_open[i]  = 1;
    high_open[i] = 1;
  }
}

K_BOXCO2 :: K_BOXCO2(const bigrational& l_s, const bigrational& h_s,
                     const bigrational& l_t, const bigrational& h_t,
                     const int l_open_s, const int h_open_s,
                     const int l_open_t, const int h_open_t)
{
  low[0]       = l_s;
  high[0]      = h_s;
  low[1]       = l_t;
  high[1]      = h_t;
  low_open[0]  = l_open_s;
  high_open[0] = h_open_s;
  low_open[1]  = l_open_t;
  high_open[1] = h_open_t;
}

K_BOXCO2 :: K_BOXCO2(const bigrational* const l, const bigrational* const h,
                     const int* const l_open, const int* const h_open)
{
  unsigned long i;
  
  for (i = 0; i < 2; i++)
  {
    low[i]       = l[i];
    high[i]      = h[i];
    low_open[i]  = l_open[i];
    high_open[i] = h_open[i];
  }
}

K_BOXCO2 :: K_BOXCO2(const K_BOXCO2& b)
{
  unsigned long i;
  
  for (i = 0; i < 2; i++)
  {
    low[i]       = b.low[i];
    high[i]      = b.high[i];
    low_open[i]  = b.low_open[i];
    high_open[i] = b.high_open[i];
  }
}

K_BOXCO2& K_BOXCO2 :: operator =(const K_BOXCO2& b)
{
  if (this != &b)
  {
    unsigned long i;
    
    for (i = 0; i < 2; i++)
    {
      low[i]       = b.low[i];
      high[i]      = b.high[i];
      low_open[i]  = b.low_open[i];
      high_open[i] = b.high_open[i];
    }
  }
  
  return *this;
}

K_BOXCO2 :: ~K_BOXCO2()
{ }

ostream& K_BOXCO2 :: output(ostream& o) const
{
  if (low_open[0])
    o << "( ";
  else  //  if (low_open[0] == 0)
    o << "[ ";
  
  o << low[0] << ", " << high[0];
  
  if (high_open[0])
    o << " )";
  else  //  if (high_open[0] == 0)
    o << " ]";
  
  o << " x ";
  
  if (low_open[1])
    o << "( ";
  else  //  if (low_open[1] == 0)
    o << "[ ";
  
  o << low[1] << ", " << high[1];
  
  if (high_open[1])
    o << " )";
  else  //  if (high_open[1] == 0)
    o << " ]";
  
  return o;
}

ostream& operator <<(ostream& o, const K_BOXCO2& b)
{
  return b.output(o);
}

bigrational K_BOXCO2 :: get_low_s() const
{
  return low[0];
}

bigrational K_BOXCO2 :: get_high_s() const
{
  return high[0];
}

bigrational K_BOXCO2 :: get_low_t() const
{
  return low[1];
}

bigrational K_BOXCO2 :: get_high_t() const
{
  return high[1];
}

int K_BOXCO2 :: is_low_s_open() const
{
  return low_open[0];
}

int K_BOXCO2 :: is_high_s_open() const
{
  return high_open[0];
}

int K_BOXCO2 :: is_low_t_open() const
{
  return low_open[1];
}

int K_BOXCO2 :: is_high_t_open() const
{
  return high_open[1];
}

K_BOXCO2 K_BOXCO2 :: merge(const K_BOXCO2& b) const
{
  unsigned long i;
  K_BOXCO2      c;
  
  for (i = 0; i < 2; i++)
  {
    if (low[i] < b.low[i])
    {
      c.low[i]      = low[i];
      c.low_open[i] = low_open[i];
    }
    else if (low[i] > b.low[i])
    {
      c.low[i]      = b.low[i];
      c.low_open[i] = b.low_open[i];
    }
    else  //  if (low[i] == b.low[i])
    {
      c.low[i]      = low[i];
      c.low_open[i] = low_open[i] * b.low_open[i];
    }
    
    if (high[i] > b.high[i])
    {
      c.high[i]      = high[i];
      c.high_open[i] = high_open[i];
    }
    else if (high[i] < b.high[i])
    {
      c.high[i]      = b.high[i];
      c.high_open[i] = b.high_open[i];
    }
    else  //  if (high[i] == b.high[i])
    {
      c.high[i]      = high[i];
      c.high_open[i] = high_open[i] * b.high_open[i];
    }
  }
  
  return c;
}

int K_BOXCO2 :: overlap(const K_BOXCO2& b) const
{
  unsigned long i;
  int           o;
  
  for (o = 1, i = 0; o && i < 2; i++)
    if (low[i] > b.high[i]
        ||
        high[i] < b.low[i]
        ||
        low[i] == b.high[i] && (low_open[i] || b.high_open[i])
        ||
        high[i] == b.low[i] && (high_open[i] || b.low_open[i]))
      o = 0;
  
  return o;
}

int K_BOXCO2 :: contains(const K_BOXCO2& b) const
{
  unsigned long i;
  int           c;
  
  for (i = 0, c = 1; c && i < 2; i++)
    if (low[i] > b.low[i]
        ||
        high[i] < b.high[i]
        ||
        low[i] == b.low[i] && low_open[i] && !b.low_open[i]
        ||
        high[i] == b.high[i] && high_open[i] && !b.high_open[i])
      c = 0;
  
  return c;
}