SheafSystem  0.0.0.0
chart_point_1d.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_1d.h"
22 #include "SheafSystem/assert_contract.h"
23 
24 using namespace fiber_bundle; // Workaround for bug in MS C++.
25 
26 // ===========================================================
27 // CHART_POINT_1D 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 {
89  // Preconditions:
90 
91  // Body:
92 
93  _chart_id = xchart_id;
94  _local_coords[0] = xu;
95 
96  // Postconditions:
97 
98  ensure(invariant());
99  ensure(chart_id() == xchart_id);
100  ensure(isunordered_or_equals(u(),xu));
101 
102  // Exit:
103 
104  return;
105 }
106 
108 chart_point_1d(const scoped_index& xchart_id, coord_type xu)
109 {
110  // Preconditions:
111 
112  // Body:
113 
114  _chart_id = xchart_id.hub_pod();
115  _local_coords[0] = xu;
116 
117  // Postconditions:
118 
119  ensure(invariant());
120  ensure(chart_id() == xchart_id.hub_pod());
121  ensure(isunordered_or_equals(u(), xu));
122 
123  // Exit:
124 
125  return;
126 }
127 
130  const coord_type* xlocal_coords,
131  size_type xlocal_coords_ub)
132 {
133  // Preconditions:
134 
135  require(xlocal_coords != 0);
136  require(xlocal_coords_ub >= db());
137 
138  // Body:
139 
140  _chart_id = xchart_id;
141  put_local_coords(xlocal_coords, xlocal_coords_ub);
142 
143  // Postconditions:
144 
145  ensure(invariant());
146  ensure(chart_id() == xchart_id);
147  ensure_for_all(i, 0, db(), isunordered_or_equals(local_coord(i), xlocal_coords[i]));
148 
149  // Exit:
150 
151  return;
152 }
153 
155 chart_point_1d(const scoped_index& xchart_id,
156  const coord_type* xlocal_coords,
157  size_type xlocal_coords_ub)
158 {
159  // Preconditions:
160 
161  require(xlocal_coords != 0);
162  require(xlocal_coords_ub >= db());
163 
164  // Body:
165 
166  _chart_id = xchart_id.hub_pod();
167  put_local_coords(xlocal_coords, xlocal_coords_ub);
168 
169  // Postconditions:
170 
171  ensure(invariant());
172  ensure(chart_id() == xchart_id.hub_pod());
173  ensure_for_all(i, 0, db(), isunordered_or_equals(local_coord(i), xlocal_coords[i]));
174 
175  // Exit:
176 
177  return;
178 }
179 
180 int
182 db() const
183 {
184  int result;
185 
186  // Preconditions:
187 
188 
189  // Body:
190 
191  result = 1;
192 
193  // Postconditions:
194 
195  ensure(result == 1);
196 
197  // Exit:
198 
199  return result;
200 }
201 
204 local_coord(int xi) const
205 {
206  coord_type result;
207 
208  // Preconditions:
209 
210  require((0 <= xi) && (xi < db()));
211 
212  // Body:
213 
214  result = _local_coords[xi];
215 
216  // Postconditions:
217 
220 
221  // Exit:
222 
223  return result;
224 }
225 
226 void
229 {
230  // Preconditions:
231 
232  require((0 <= xi) && (xi < db()));
233 
234  // Body:
235 
236  _local_coords[xi] = xvalue;
237 
238  // Postconditions:
239 
242 
243  ensure(isunordered_or_equals(local_coord(xi), xvalue));
244 
245  // Exit:
246 
247  return;
248 }
249 
253 {
254  coord_type* result;
255 
256  // Preconditions:
257 
258 
259  // Body:
260 
261  result = _local_coords;
262 
263  // Postconditions:
264 
265  ensure(result != 0);
266 
267  // Exit:
268 
269  return result;
270 }
271 
275 {
276  const coord_type* result;
277 
278  // Preconditions:
279 
280 
281  // Body:
282 
283  result = _local_coords;
284 
285  // Postconditions:
286 
287  ensure(result != 0);
288 
289  // Exit:
290 
291  return result;
292 }
293 
296 u() const
297 {
298  // Preconditions:
299 
300  // Body:
301 
302  const coord_type& result = _local_coords[0];
303 
304  // Postconditions:
305 
308 
309  ensure(isunordered_or_equals(result, local_coord(0)));
310 
311  // Exit:
312 
313  return result;
314 }
315 
318 u()
319 {
320  // Preconditions:
321 
322  // Body:
323 
324  coord_type& result = _local_coords[0];
325 
326  // Postconditions:
327 
330 
331  ensure(isunordered_or_equals(result, local_coord(0)));
332 
333  // Exit:
334 
335  return result;
336 }
337 
338 void
340 put(pod_index_type xchart_id, coord_type xu)
341 {
342  // Preconditions:
343 
344  // Body:
345 
346  _chart_id = xchart_id;
347  _local_coords[0] = xu;
348 
349  // Postconditions:
350 
351  ensure(invariant());
352  ensure(chart_id() == xchart_id);
353  ensure(isunordered_or_equals(u(), xu));
354 
355  // Exit:
356 
357  return;
358 }
359 
360 void
362 put(const scoped_index& xchart_id, coord_type xu)
363 {
364  // Preconditions:
365 
366  // Body:
367 
368  put(xchart_id.hub_pod(), xu);
369 
370  // Postconditions:
371 
372  ensure(invariant());
373  ensure(chart_id() == xchart_id.hub_pod());
374  ensure(isunordered_or_equals(u(), xu));
375 
376  // Exit:
377 
378  return;
379 }
380 
381 // PROTECTED MEMBER FUNCTIONS
382 
383 // PRIVATE MEMBER FUNCTIONS
384 
385 
386 // ===========================================================
387 // CHART_POINT FACET
388 // ===========================================================
389 
390 // PUBLIC MEMBER FUNCTIONS
391 
392 // PROTECTED MEMBER FUNCTIONS
393 
394 // PRIVATE MEMBER FUNCTIONS
395 
396 
397 // ===========================================================
398 // ANY FACET
399 // ===========================================================
400 
401 // PUBLIC MEMBER FUNCTIONS
402 
405 clone() const
406 {
407  chart_point_1d* result;
408 
409  // Preconditions:
410 
411  // Body:
412 
413  result = new chart_point_1d();
414 
415  // Postconditions:
416 
417  ensure(result->is_same_type(this));
418 
419  // Exit:
420 
421  return result;
422 }
423 
424 bool
426 invariant() const
427 {
428  bool result = true;
429 
430  // Preconditions:
431 
432  // Body:
433 
434  if(invariant_check())
435  {
436  // Prevent recursive calls to invariant
437 
438  disable_invariant_check();
439 
440  invariance(chart_point::invariant());
441  invariance(db() == 1);
442 
443  // Finished, turn invariant checking back on.
444 
445  enable_invariant_check();
446  }
447 
448  // Postconditions:
449 
450  // Exit
451 
452  return result;
453 }
454 
455 bool
457 is_ancestor_of(const any* other) const
458 {
459  // Preconditions:
460 
461  require(other != 0);
462 
463  // Body:
464 
465  // True if other conforms to this
466 
467  bool result = dynamic_cast<const chart_point_1d*>(other) != 0;
468 
469  // Postconditions:
470 
471  // Exit:
472 
473  return result;
474 }
475 
478 operator=(const chart_point_1d& xother)
479 {
480  // Preconditions:
481 
482  // Body:
483 
484  _chart_id = xother._chart_id;
485  _local_coords[0] = xother._local_coords[0];
486 
487  // Postconditions:
488 
489  ensure(invariant());
490  ensure(unexecutable(*this == xother));
491 
492  // Exit
493 
494  return *this;
495 }
496 
497 // PROTECTED MEMBER FUNCTIONS
498 
499 // PRIVATE MEMBER FUNCTIONS
500 
501 
502 // =============================================================================
503 // NON-MEMBER FUNCTIONS
504 // =============================================================================
505 
506 size_t
507 fiber_bundle::
508 deep_size(const chart_point_1d& xvalue, bool xinclude_shallow)
509 {
510  size_t result;
511 
512  // Preconditions:
513 
514  // Body:
515 
518 
519  result = 0;
520 
521  // Postconditions:
522 
523  ensure(result == 0);
524  //ensure(result >= 0);
525 
526  // Exit
527 
528  return result;
529 }
530 
chart_point_1d & 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
void put(pod_index_type xchart_id, coord_type xu)
Sets chart_id() == xchart_id, u() == xu.
coord_type & u()
The 0-th (and only) local coordinate of this; mutable version.
virtual chart_point_1d * clone() const
Virtual constructor, makes a new instance of the same type as this.
pod_index_type _chart_id
The id of the chart this point is in.
Definition: chart_point.h:148
virtual int db() const
The dimension of this chart.
virtual coord_type local_coord(int xi) const
The xi-th local coordinate of this point.
virtual bool invariant() const
Class invariant.
Abstract base class with useful features for all objects.
Definition: any.h:39
coord_type * local_coords()
The array of local coordinates.
virtual void put_local_coord(int xi, coord_type xvalue)
Sets the xi-th local coordinate of this point to xvalue.
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
virtual ~chart_point_1d()
Destructor.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
coord_type _local_coords[1]
The local coordinates of this point.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
chart_point_1d()
Default constructor.
A point in a 1D chart space.
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
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