SheafSystem  0.0.0.0
chart_point_3d.cc
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 #include "SheafSystem/chart_point_3d.h"
22 #include "SheafSystem/assert_contract.h"
23 
24 using namespace fiber_bundle; // Workaround for bug in MS C++.
25 
26 // ===========================================================
27 // CHART_POINT_3D FACET
28 // ===========================================================
29 
30 // PUBLIC MEMBER FUNCTIONS
31 
34 {
35  // Preconditions:
36 
37  // Body:
38 
39  _chart_id = invalid_pod_index();
40 
41  // Postconditions:
42 
43  ensure(invariant());
44  ensure(!is_valid());
45 
46  // Exit:
47 
48  return;
49 }
50 
53 {
54  // Preconditions:
55 
56  // Body:
57 
58  *this = xother;
59 
60  // Postconditions:
61 
62  ensure(invariant());
63  ensure(*this == xother);
64 
65  // Exit:
66 
67  return;
68 }
69 
72 {
73  // Preconditions:
74 
75  // Body:
76 
77  // Nothing to do.
78 
79  // Postconditions:
80 
81  // Exit:
82 
83  return;
84 }
85 
88  coord_type xu,
89  coord_type xv,
90  coord_type xw)
91 {
92  // Preconditions:
93 
94  // Body:
95 
96  _chart_id = xchart_id;
97  _local_coords[0] = xu;
98  _local_coords[1] = xv;
99  _local_coords[2] = xw;
100 
101  // Postconditions:
102 
103  ensure(invariant());
104  ensure(chart_id() == xchart_id);
105  ensure(isunordered_or_equals(u(), xu));
106  ensure(isunordered_or_equals(v(), xv));
107  ensure(isunordered_or_equals(w(), xw));
108 
109  // Exit:
110 
111  return;
112 }
113 
115 chart_point_3d(const scoped_index& xchart_id,
116  coord_type xu,
117  coord_type xv,
118  coord_type xw)
119 {
120  // Preconditions:
121 
122  // Body:
123 
124  _chart_id = xchart_id.hub_pod();
125  _local_coords[0] = xu;
126  _local_coords[1] = xv;
127  _local_coords[2] = xw;
128 
129  // Postconditions:
130 
131  ensure(invariant());
132  ensure(chart_id() == xchart_id.hub_pod());
133  ensure(isunordered_or_equals(u(), xu));
134  ensure(isunordered_or_equals(v(), xv));
135  ensure(isunordered_or_equals(w(), xw));
136 
137  // Exit:
138 
139  return;
140 }
141 
144  const coord_type* xlocal_coords,
145  size_type xlocal_coords_ub)
146 {
147 
148  // Preconditions:
149 
150  require(xlocal_coords != 0);
151  require(xlocal_coords_ub >= db());
152 
153  // Body:
154 
155  _chart_id = xchart_id;
156  put_local_coords(xlocal_coords, xlocal_coords_ub);
157 
158  // Postconditions:
159 
160  ensure(invariant());
161  ensure(chart_id() == xchart_id);
162  ensure_for_all(i, 0, db(), isunordered_or_equals(local_coord(i), xlocal_coords[i]));
163 
164  // Exit:
165 
166  return;
167 }
168 
170 chart_point_3d(const scoped_index& xchart_id,
171  const coord_type* xlocal_coords,
172  size_type xlocal_coords_ub)
173 {
174 
175  // Preconditions:
176 
177  require(xlocal_coords != 0);
178  require(xlocal_coords_ub >= db());
179 
180  // Body:
181 
182  _chart_id = xchart_id.hub_pod();
183  put_local_coords(xlocal_coords, xlocal_coords_ub);
184 
185  // Postconditions:
186 
187  ensure(invariant());
188  ensure(chart_id() == xchart_id.hub_pod());
189  ensure_for_all(i, 0, db(), isunordered_or_equals(local_coord(i), xlocal_coords[i]));
190 
191  // Exit:
192 
193  return;
194 }
195 
196 int
198 db() const
199 {
200  int result;
201 
202  // Preconditions:
203 
204  // Body:
205 
206  result = 3;
207 
208  // Postconditions:
209 
210  ensure(result == 3);
211 
212  // Exit:
213 
214  return result;
215 }
216 
219 local_coord(int xi) const
220 {
221  coord_type result;
222 
223  // Preconditions:
224 
225  require((0 <= xi) && (xi < db()));
226 
227  // Body:
228 
229  result = _local_coords[xi];
230 
231  // Postconditions:
232 
235 
236  // Exit:
237 
238  return result;
239 }
240 
241 void
244 {
245  // Preconditions:
246 
247  require((0 <= xi) && (xi < db()));
248 
249  // Body:
250 
251  _local_coords[xi] = xvalue;
252 
253  // Postconditions:
254 
257 
258  ensure(isunordered_or_equals(local_coord(xi), xvalue));
259 
260  // Exit:
261 
262  return;
263 }
264 
268 {
269  coord_type* result;
270 
271  // Preconditions:
272 
273  // Body:
274 
275  result = _local_coords;
276 
277  // Postconditions:
278 
279  ensure(result != 0);
280 
281  // Exit:
282 
283  return result;
284 }
285 
289 {
290  const coord_type* result;
291 
292  // Preconditions:
293 
294 
295  // Body:
296 
297  result = _local_coords;
298 
299  // Postconditions:
300 
301  ensure(result != 0);
302 
303  // Exit:
304 
305  return result;
306 }
307 
310 u() const
311 {
312 
313  // Preconditions:
314 
315  // Body:
316 
317  const coord_type& result = _local_coords[0];
318 
319  // Postconditions:
320 
323 
324  ensure(isunordered_or_equals(result, local_coord(0)));
325 
326  // Exit:
327 
328  return result;
329 }
330 
333 v() const
334 {
335  // Preconditions:
336 
337  // Body:
338 
339  const coord_type& result = _local_coords[1];
340 
341  // Postconditions:
342 
345 
346  ensure(isunordered_or_equals(result, local_coord(1)));
347 
348  // Exit:
349 
350  return result;
351 }
352 
355 w() const
356 {
357  // Preconditions:
358 
359  // Body:
360 
361  const coord_type& result = _local_coords[2];
362 
363  // Postconditions:
364 
367 
368  ensure(isunordered_or_equals(result, local_coord(2)));
369 
370  // Exit:
371 
372  return result;
373 }
374 
375 void
378 {
379  // Preconditions:
380 
381  // Body:
382 
383  _chart_id = xchart_id;
384  _local_coords[0] = xu;
385  _local_coords[1] = xv;
386  _local_coords[2] = xw;
387 
388  // Postconditions:
389 
390  ensure(invariant());
391  ensure(chart_id() == xchart_id);
392  ensure(isunordered_or_equals(u(), xu));
393  ensure(isunordered_or_equals(v(), xv));
394  ensure(isunordered_or_equals(w(), xw));
395 
396  // Exit:
397 
398  return;
399 }
400 
401 void
403 put(const scoped_index& xchart_id, coord_type xu, coord_type xv, coord_type xw)
404 {
405  // Preconditions:
406 
407  // Body:
408 
409  put(xchart_id.hub_pod(), xu, xv, xw);
410 
411  // Postconditions:
412 
413  ensure(invariant());
414  ensure(chart_id() == xchart_id.hub_pod());
415  ensure(isunordered_or_equals(u(), xu));
416  ensure(isunordered_or_equals(v(), xv));
417  ensure(isunordered_or_equals(w(), xw));
418 
419  // Exit:
420 
421  return;
422 }
423 
424 // PROTECTED MEMBER FUNCTIONS
425 
426 // PRIVATE MEMBER FUNCTIONS
427 
428 
429 // ===========================================================
430 // CHART_POINT FACET
431 // ===========================================================
432 
433 // PUBLIC MEMBER FUNCTIONS
434 
435 // PROTECTED MEMBER FUNCTIONS
436 
437 // PRIVATE MEMBER FUNCTIONS
438 
439 
440 // ===========================================================
441 // ANY FACET
442 // ===========================================================
443 
444 // PUBLIC MEMBER FUNCTIONS
445 
448 clone() const
449 {
450  chart_point_3d* result;
451 
452  // Preconditions:
453 
454  // Body:
455 
456  result = new chart_point_3d();
457 
458  // Postconditions:
459 
460  ensure(result->is_same_type(this));
461 
462  // Exit:
463 
464  return result;
465 }
466 
467 bool
469 invariant() const
470 {
471  bool result = true;
472 
473  // Preconditions:
474 
475  // Body:
476 
477  if(invariant_check())
478  {
479  // Prevent recursive calls to invariant
480 
481  disable_invariant_check();
482 
483  invariance(chart_point::invariant());
484  invariance(db() == 3);
485 
486  // Finished, turn invariant checking back on.
487 
488  enable_invariant_check();
489  }
490 
491  // Postconditions:
492 
493  // Exit
494 
495  return result;
496 }
497 
498 bool
500 is_ancestor_of(const any* other) const
501 {
502  // Preconditions:
503 
504  require(other != 0);
505 
506  // Body:
507 
508  // True if other conforms to this
509 
510  bool result = dynamic_cast<const chart_point_3d*>(other) != 0;
511 
512  // Postconditions:
513 
514  // Exit:
515 
516  return result;
517 }
518 
521 operator=(const chart_point_3d& xother)
522 {
523  // Preconditions:
524 
525  // Body:
526 
527  _chart_id = xother._chart_id;
528  _local_coords[0] = xother._local_coords[0];
529  _local_coords[1] = xother._local_coords[1];
530  _local_coords[2] = xother._local_coords[2];
531 
532  // Postconditions:
533 
534  ensure(invariant());
535  ensure(unexecutable(*this == xother));
536 
537  // Exit
538 
539  return *this;
540 }
541 
542 // PROTECTED MEMBER FUNCTIONS
543 
544 // PRIVATE MEMBER FUNCTIONS
545 
546 
547 // =============================================================================
548 // NON-MEMBER FUNCTIONS
549 // =============================================================================
550 
551 size_t
552 fiber_bundle::
553 deep_size(const chart_point_3d& xvalue, bool xinclude_shallow)
554 {
555  size_t result;
556 
557  // Preconditions:
558 
559  // Body:
560 
563 
564  result = 0;
565 
566  // Postconditions:
567 
568  ensure(result == 0);
569  //ensure(result >= 0);
570 
571  // Exit
572 
573  return result;
574 }
575 
576 
chart_point_3d & operator=(const chart_point &xother)
Assignment operator.
chart_point_coord_type coord_type
The type of local coordinate; the scalar type for the local coordinate vector space.
Definition: chart_point.h:65
virtual bool invariant() const
Class invariant.
virtual ~chart_point_3d()
Destructor.
A point in a 3D chart space.
const coord_type & w() const
The 2-th local coordinate of this.
const coord_type & v() const
The 1-th local coordinate of this.
virtual int db() const
The dimension of this chart.
pod_index_type _chart_id
The id of the chart this point is in.
Definition: chart_point.h:148
Abstract base class with useful features for all objects.
Definition: any.h:39
virtual bool invariant() const
Class invariant.
Definition: chart_point.cc:393
An index within the external ("client") scope of a given id space.
Definition: scoped_index.h:116
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual void put_local_coord(int xi, coord_type xvalue)
Sets the xi-th local coordinate of this point to xvalue.
const coord_type & u() const
The 0-th local coordinate of this.
coord_type * local_coords()
The array of local coordinates.
virtual coord_type local_coord(int xi) const
The xi-th local coordinate of this point.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
void put(pod_index_type xchart_id, coord_type xu, coord_type xv, coord_type xw)
Sets chart_id() == xchart_id, u() == xu, v() == xv, w() == xw.
chart_point_3d()
Default constructor.
virtual chart_point_3d * clone() const
Virtual constructor, makes a new instance of the same type as this.
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
Namespace for the fiber_bundles component of the sheaf system.
SHEAF_DLL_SPEC pod_index_type invalid_pod_index()
The invalid pod index value.
Definition: pod_types.cc:31
bool is_same_type(const any *other) const
True if other is the same type as this.
Definition: any.cc:79
coord_type _local_coords[3]
The local coordinates of this point.
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.
Definition: scoped_index.h:710
SHEAF_DLL_SPEC bool isunordered_or_equals(float x1, float x2)
True if isunordered(x1, x2) or x1 == x2.
Definition: sheaf.cc:102