SheafSystem  0.0.0.0
d_bin_coordinates.impl.h
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
20 
21 #ifndef D_BIN_COORDINATES_IMPL_H
22 #define D_BIN_COORDINATES_IMPL_H
23 
24 #ifndef SHEAF_DLL_SPEC_H
25 #include "SheafSystem/sheaf_dll_spec.h"
26 #endif
27 
28 #ifndef ASSERT_CONTRACT_H
29 #include "SheafSystem/assert_contract.h"
30 #endif
31 
32 #ifndef D_BIN_COORDINATES_H
33 #include "SheafSystem/d_bin_coordinates.h"
34 #endif
35 
36 #ifndef STD_BITSET_H
37 #include "SheafSystem/std_bitset.h"
38 #endif
39 
40 #ifndef STD_LIMITS_H
41 #include "SheafSystem/std_limits.h"
42 #endif
43 
44 namespace geometry
45 {
46 
47 // ============================================================================
48 // D_BIN_COORDINATES FACET
49 // ============================================================================
50 
51 template <int DC, int DB>
54 {
55  for(int i=0; i<DC; ++i)
56  {
57  _int_value[i] = 0;
58  }
59 
60  // Postconditions:
61 
62  ensure(invariant());
63 }
64 
65 template <int DC, int DB>
68 {
69  // Preconditions:
70 
71  require(precondition_of(operator=(xother)));
72 
73  // Body:
74 
75  *this = xother;
76 
77  // Postconditions:
78 
79  ensure(postcondition_of(operator=(xother)));
80 }
81 
82 template <int DC, int DB>
85 {
86  // Preconditions:
87 
88  require(precondition_of(operator=(xcoord)));
89 
90  // Body:
91 
92  *this = xcoord;
93 
94  // Postconditions:
95 
96  ensure(postcondition_of(operator=(xcoord)));
97 }
98 
99 template <int DC, int DB>
102 {}
103 
104 template <int DC, int DB>
105 bool
107 invariant() const
108 {
109  bool result = true;
110 
111  // The main reason for this existence
112  // of this class is to maintain the
113  // following invariance:
114 
115  invariance_for_all(i, 0, DC, int_value()[i] < ub());
116 
117  return result;
118 }
119 
120 template <int DC, int DB>
124 {
125  for(int i=0; i<DC; ++i)
126  {
127  _int_value[i] = xother._int_value[i];
128  }
129 
130  // Postconditions:
131 
132  ensure(invariant());
133 
134  return *this;
135 }
136 
137 template <int DC, int DB>
140 operator=(const value_type* xcoord)
141 {
142  // Preconditions:
143 
144  require_for_all(i, 0, DC, 0.0 <= xcoord[i]);
145  require_for_all(i, 0, DC, floor(xcoord[i]) < ub());
146 
147  // Body:
148 
149  for(int i=0; i<DC; ++i)
150  {
151  _int_value[i] = static_cast<int_type>(xcoord[i]);
152  }
153 
154  // Postcondition:
155 
156  ensure(invariant());
157 
158  return *this;
159 }
160 
161 template <int DC, int DB>
162 bool
165 {
166  bool result = true;
167  for(int i=0; i<DC; ++i)
168  {
169  result = result && (_int_value[i] == xother._int_value[i]);
170  }
171 
172  return result;
173 }
174 
175 template <int DC, int DB>
176 bool
178 operator==(int_type xother) const
179 {
180  bool result = true;
181  for(int i=0; i<DC; ++i)
182  {
183  result = result && (_int_value[i] == xother);
184  }
185 
186  return result;
187 }
188 
189 template <int DC, int DB>
190 bool
193 {
194  bool result = true;
195  for(int i=0; i<DC; ++i)
196  {
197  result = result && (_int_value[i] < xother._int_value[i]);
198  }
199 
200  return result;
201 }
202 
203 template <int DC, int DB>
204 bool
207 {
208  bool result = true;
209  for(int i=0; i<DC; ++i)
210  {
211  result = result && (_int_value[i] <= xother._int_value[i]);
212  }
213 
214  return result;
215 }
216 
217 template <int DC, int DB>
220 operator>>=(int xbits)
221 {
222  // Preconditions:
223 
224  require(xbits < bits());
225 
226  // Body:
227 
228  for(int i=0; i<DC; ++i)
229  {
230  _int_value[i] >>= xbits;
231  }
232 
233  // Postconditions:
234 
235  ensure(invariant());
236 
237  // Exit:
238 
239  return *this;
240 }
241 
242 template <int DC, int DB>
246 {
247  // Preconditions:
248 
249  // Body:
250 
251  for(int i=0; i<DC; ++i)
252  {
253  _int_value[i] -= xother._int_value[i];
254  }
255 
256  // Postconditions:
257 
258  ensure(invariant());
259 
260  // Exit:
261 
262  return *this;
263 }
264 
265 template <int DC, int DB>
266 size_type
268 branch(size_type xbit) const
269 {
270  size_type result = 0;
271 
272  // Preconditions:
273 
274  // Implemented below for specialized values of DC=1, 2, 3 & 4.
275 
276  not_implemented();
277 
278  // Postconditions:
279 
280  // Exit:
281 
282  return result;
283 }
284 
285 template <int DC, int DB>
286 void
289 {
290  // Preconditions:
291 
292  // Body:
293 
294  // Implemented below for specialized values of DC=1, 2, 3 & 4.
295 
296  not_implemented();
297 
298  // Postconditions:
299 
300  // Exit:
301 
302  return;
303 }
304 
305 template <int DC, int DB>
308 ub()
309 {
310  // Comparison and intersection logic in class octree_path
311  // requires positions to have leftmost bit = 0.
312 
313  static const int_type result =
314  static_cast<int_type>(1) << (std::numeric_limits<int_type>::digits - 1);
315 
316  return result;
317 }
318 
319 template <int DC, int DB>
323 {
324  static const size_type result = std::numeric_limits<int_type>::digits;
325  return result;
326 }
327 
328 template <int DC, int DB>
329 size_type
332 {
333  return bits() - 1;
334 }
335 
337 template <int DC, int DB>
338 size_type
341 {
342  return 0;
343 }
344 
345 template <int DC, int DB>
346 size_type
349 {
350  return 1<<DC;
351 }
352 
353 template <int DC, int DB>
354 size_type
356 dc()
357 {
358  return DC;
359 }
360 
361 template <int DC, int DB>
364 int_value() const
365 {
366  return _int_value;
367 }
368 
369 template <int DC, int DB>
373 {
374  // Preconditions:
375 
376  require(xi < DC);
377 
378  // Body:
379 
380  return _int_value[xi];
381 }
382 
383 template <int DC, int DB>
387 {
388  // Preconditions:
389 
390  require(xi < DC);
391 
392  // Body:
393 
394  return _int_value[xi];
395 }
396 
397 template <int DC, int DB>
399 d_bin_coordinates(int_type xint_value)
400 {
401  // Preconditions:
402 
403  require(xint_value < ub());
404 
405  // Body:
406 
407  for(int i=0; i<DC; ++i)
408  {
409  _int_value[i] = xint_value;
410  }
411 
412  // Postconditions:
413 
414  ensure(invariant());
415 }
416 
417 } // namespace geometry
418 
419 // ===========================================================
420 // NON-MEMBER FUNCTIONS
421 // ===========================================================
422 
423 #ifndef DOXYGEN_SHOULD_SKIP_THIS
424 template <int DC, int DB>
425 std::ostream& geometry::operator<<(std::ostream& xos, const geometry::d_bin_coordinates<DC, DB>& xcoords)
426 {
427  for(int i=0; i<xcoords.dc(); ++i)
428  {
429  xos << " "
430  << std::bitset<std::numeric_limits<typename d_bin_coordinates<DC, DB>::int_type>
431  ::digits>(xcoords.int_value()[i]);
432  }
433  return xos;
434 }
435 #endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
436 
437 #endif // ifndef D_BIN_COORDINATES_IMPL_H
const int_type * int_value() const
The value of this as an int_type.
unsigned long long int_type
The type used for integer coordinates.
static size_type dc()
The dimension of the tree this is a coordinate for.
bool operator==(const d_bin_coordinates< DC, DB > &xother) const
True if and only if this has the same value as xother.
void put_branch(size_type xbit, size_type xbranch)
Set the branch index at bit position xbit to xbranch.
bool invariant() const
Class invariant.
const int_type & operator[](size_type xi) const
The xi-th coordinate of this.
static size_type leftmost_bit_id()
The index of the leftmost bit.
d_bin_coordinates()
Default constructor.
Fixed point relative coordinates for a tree domain.
static int_type ub()
The upper bound for components.
size_type branch(size_type xbit) const
The branch index at bit position xbit.
static size_type bits()
The number of bits in a tree coordinate.
d_bin_coordinates< DC, DB > & operator>>=(int xbits)
Right shift and assignment of this by xbits.
d_bin_coordinates & operator=(const d_bin_coordinates< DC, DB > &xother)
Assignment from d_bin_coordinates.
bool operator<=(const d_bin_coordinates< DC, DB > &xother) const
True if and only if the value of this is less than or equal to the value of xother.
sheaf::size_type size_type
An unsigned integral type used to represent sizes and capacities.
static size_type rightmost_bit_id()
The index of the rightmost bit.
SHEAF_DLL_SPEC void floor(const sec_at0 &x0, sec_at0 &xresult, bool xauto_access)
Compute floor of x0 (floor(x0)) (pre-allocated version).
Definition: sec_at0.cc:1351
bool operator<(const d_bin_coordinates< DC, DB > &xother) const
True if and only if the value of this is less than the value of xother.
d_bin_coordinates & operator-=(const d_bin_coordinates< DC, DB > &xother)
Substraction and assignemnt.
static size_type degree()
The degree of the tree this is a coordinate for.
Namespace for geometry component of sheaf system.
Definition: field_vd.h:54
section_evaluator::value_type value_type
The type used for floating point coordinates.