SheafSystem  0.0.0.0
chart_point_2d.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_2d.h"
22 #include "SheafSystem/assert_contract.h"
23 
24 using namespace fiber_bundle; // Workaround for bug in MS C++.
25 
26 
27 // ===========================================================
28 // CHART_POINT_2D FACET
29 // ===========================================================
30 
31 // PUBLIC MEMBER FUNCTIONS
32 
35 {
36  // Preconditions:
37 
38  // Body:
39 
40  _chart_id = invalid_pod_index();
41 
42  // Postconditions:
43 
44  ensure(invariant());
45  ensure(!is_valid());
46 
47  // Exit:
48 
49  return;
50 }
51 
54 {
55  // Preconditions:
56 
57  // Body:
58 
59  *this = xother;
60 
61  // Postconditions:
62 
63  ensure(invariant());
64  ensure(*this == xother);
65 
66  // Exit:
67 
68  return;
69 }
70 
73 {
74  // Preconditions:
75 
76  // Body:
77 
78  // Nothing to do.
79 
80  // Postconditions:
81 
82  // Exit:
83 
84  return;
85 }
86 
89 {
90  // Preconditions:
91 
92  // Body:
93 
94  _chart_id = xchart_id;
95  _local_coords[0] = xu;
96  _local_coords[1] = xv;
97 
98  // Postconditions:
99 
100  ensure(invariant());
101  ensure(chart_id() == xchart_id);
102  ensure(isunordered_or_equals(u(), xu));
103  ensure(isunordered_or_equals(v(), xv));
104 
105  // Exit:
106 
107  return;
108 }
109 
111 chart_point_2d(const scoped_index& xchart_id, coord_type xu, coord_type xv)
112 {
113  // Preconditions:
114 
115  // Body:
116 
117  _chart_id = xchart_id.hub_pod();
118  _local_coords[0] = xu;
119  _local_coords[1] = xv;
120 
121  // Postconditions:
122 
123  ensure(invariant());
124  ensure(chart_id() == xchart_id.hub_pod());
125  ensure(isunordered_or_equals(u(), xu));
126  ensure(isunordered_or_equals(v(), xv));
127 
128  // Exit:
129 
130  return;
131 }
132 
135  const coord_type* xlocal_coords,
136  size_type xlocal_coords_ub)
137 {
138  // Preconditions:
139 
140  require(xlocal_coords != 0);
141  require(xlocal_coords_ub >= db());
142 
143  // Body:
144 
145  _chart_id = xchart_id;
146  put_local_coords(xlocal_coords, xlocal_coords_ub);
147 
148  // Postconditions:
149 
150  ensure(invariant());
151  ensure(chart_id() == xchart_id);
152  ensure_for_all(i, 0, db(), isunordered_or_equals(local_coord(i), xlocal_coords[i]));
153 
154  // Exit:
155 
156  return;
157 }
158 
160 chart_point_2d(const scoped_index& xchart_id,
161  const coord_type* xlocal_coords,
162  size_type xlocal_coords_ub)
163 {
164  // Preconditions:
165 
166  require(xlocal_coords != 0);
167  require(xlocal_coords_ub >= db());
168 
169  // Body:
170 
171  _chart_id = xchart_id.hub_pod();
172  put_local_coords(xlocal_coords, xlocal_coords_ub);
173 
174  // Postconditions:
175 
176  ensure(invariant());
177  ensure(chart_id() == xchart_id.hub_pod());
178  ensure_for_all(i, 0, db(), isunordered_or_equals(local_coord(i), xlocal_coords[i]));
179 
180  // Exit:
181 
182  return;
183 }
184 
185 int
187 db() const
188 {
189  int result;
190 
191  // Preconditions:
192 
193 
194  // Body:
195 
196  result = 2;
197 
198  // Postconditions:
199 
200  ensure(result == 2);
201 
202  // Exit:
203 
204  return result;
205 }
206 
209 local_coord(int xi) const
210 {
211  coord_type result;
212 
213  // Preconditions:
214 
215  require((0 <= xi) && (xi < db()));
216 
217  // Body:
218 
219  result = _local_coords[xi];
220 
221  // Postconditions:
222 
225 
226  // Exit:
227 
228  return result;
229 }
230 
231 void
234 {
235  // Preconditions:
236 
237  require((0 <= xi) && (xi < db()));
238 
239  // Body:
240 
241  _local_coords[xi] = xvalue;
242 
243  // Postconditions:
244 
247 
248  ensure(isunordered_or_equals(local_coord(xi), xvalue));
249 
250  // Exit:
251 
252  return;
253 }
254 
258 {
259  coord_type* result;
260 
261  // Preconditions:
262 
263  // Body:
264 
265  result = _local_coords;
266 
267  // Postconditions:
268 
269  ensure(result != 0);
270 
271  // Exit:
272 
273  return result;
274 }
275 
279 {
280  const coord_type* result;
281 
282  // Preconditions:
283 
284  // Body:
285 
286  result = _local_coords;
287 
288  // Postconditions:
289 
290  ensure(result != 0);
291 
292  // Exit:
293 
294  return result;
295 }
296 
299 u() const
300 {
301  // Preconditions:
302 
303  // Body:
304 
305  const coord_type& result = _local_coords[0];
306 
307  // Postconditions:
308 
311 
312  ensure(isunordered_or_equals(result, local_coord(0)));
313 
314  // Exit:
315 
316  return result;
317 }
318 
321 v() const
322 {
323  // Preconditions:
324 
325  // Body:
326 
327  const coord_type& result = _local_coords[1];
328 
329  // Postconditions:
330 
333 
334  // The following seems reasonable,
335  // but fails if result is NAN because NAN
336  // doesn't == anything, not even itself.
337 
338  ensure(isunordered_or_equals(result, local_coord(1)));
339 
340  // Exit:
341 
342  return result;
343 }
344 
345 void
347 put(pod_index_type xchart_id, coord_type xu, coord_type xv)
348 {
349  // Preconditions:
350 
351  // Body:
352 
353  _chart_id = xchart_id;
354  _local_coords[0] = xu;
355  _local_coords[1] = xv;
356 
357  // Postconditions:
358 
359  ensure(invariant());
360  ensure(chart_id() == xchart_id);
361  ensure(isunordered_or_equals(u(), xu));
362  ensure(isunordered_or_equals(v(), xv));
363 
364  // Exit:
365 
366  return;
367 }
368 
369 void
371 put(const scoped_index& xchart_id, coord_type xu, coord_type xv)
372 {
373  // Preconditions:
374 
375  // Body:
376 
377  put(xchart_id.hub_pod(), xu, xv);
378 
379  // Postconditions:
380 
381  ensure(invariant());
382  ensure(chart_id() == xchart_id.hub_pod());
383  ensure(isunordered_or_equals(u(), xu));
384  ensure(isunordered_or_equals(v(), xv));
385 
386  // Exit:
387 
388  return;
389 }
390 
391 // PROTECTED MEMBER FUNCTIONS
392 
393 // PRIVATE MEMBER FUNCTIONS
394 
395 
396 // ===========================================================
397 // CHART_POINT FACET
398 // ===========================================================
399 
400 // PUBLIC MEMBER FUNCTIONS
401 
402 // PROTECTED MEMBER FUNCTIONS
403 
404 // PRIVATE MEMBER FUNCTIONS
405 
406 
407 // ===========================================================
408 // ANY FACET
409 // ===========================================================
410 
411 // PUBLIC MEMBER FUNCTIONS
412 
415 clone() const
416 {
417  chart_point_2d* result;
418 
419  // Preconditions:
420 
421 
422  // Body:
423 
424  result = new chart_point_2d();
425 
426  // Postconditions:
427 
428  ensure(result->is_same_type(this));
429 
430  // Exit:
431 
432  return result;
433 }
434 
435 bool
437 invariant() const
438 {
439  bool result = true;
440 
441  // Preconditions:
442 
443  // Body:
444 
445  if(invariant_check())
446  {
447  // Prevent recursive calls to invariant
448 
449  disable_invariant_check();
450 
451  invariance(chart_point::invariant());
452  invariance(db() == 2);
453 
454  // Finished, turn invariant checking back on.
455 
456  enable_invariant_check();
457  }
458 
459  // Postconditions:
460 
461  // Exit
462 
463  return result;
464 }
465 
466 bool
468 is_ancestor_of(const any* other) const
469 {
470 
471  // Preconditions:
472 
473  require(other != 0);
474 
475  // Body:
476 
477  // True if other conforms to this
478 
479  bool result = dynamic_cast<const chart_point_2d*>(other) != 0;
480 
481  // Postconditions:
482 
483  // Exit:
484 
485  return result;
486 }
487 
490 operator=(const chart_point_2d& xother)
491 {
492 
493  // Preconditions:
494 
495  // Body:
496 
497  _chart_id = xother._chart_id;
498  _local_coords[0] = xother._local_coords[0];
499  _local_coords[1] = xother._local_coords[1];
500 
501  // Postconditions:
502 
503  ensure(invariant());
504  ensure(unexecutable(*this == xother));
505 
506  // Exit
507 
508  return *this;
509 }
510 
511 // PROTECTED MEMBER FUNCTIONS
512 
513 // PRIVATE MEMBER FUNCTIONS
514 
515 
516 // =============================================================================
517 // NON-MEMBER FUNCTIONS
518 // =============================================================================
519 
520 size_t
521 fiber_bundle::
522 deep_size(const chart_point_2d& xvalue, bool xinclude_shallow)
523 {
524  size_t result;
525 
526  // Preconditions:
527 
528  // Body:
529 
532 
533  result = 0;
534 
535  // Postconditions:
536 
537  ensure(result == 0);
538  //ensure(result >= 0);
539 
540  // Exit
541 
542  return result;
543 }
chart_point_2d & 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
const coord_type & u() const
The 0-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
void put(pod_index_type xchart, coord_type xu, coord_type xv)
Sets chart_id() == xchart_id, u() == xu, v() == xv.
chart_point_2d()
Default constructor.
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
coord_type _local_coords[2]
The local coordinates of this point.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
Definition: sheaf.h:52
virtual ~chart_point_2d()
Destructor.
A point in a 2D chart space.
virtual bool invariant() const
Class invariant.
const coord_type & v() const
The 1-th local coordinate of this.
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.
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.
virtual coord_type local_coord(int xi) const
The xi-th local coordinate of this point.
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
virtual chart_point_2d * clone() const
Virtual constructor, makes a new instance of the same type as this.
SHEAF_DLL_SPEC bool isunordered_or_equals(float x1, float x2)
True if isunordered(x1, x2) or x1 == x2.
Definition: sheaf.cc:102