File: nfacetspec.h

package info (click to toggle)
regina-normal 4.93-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 28,576 kB
  • sloc: cpp: 86,815; ansic: 13,030; xml: 9,089; perl: 951; sh: 380; python: 273; makefile: 103
file content (398 lines) | stat: -rw-r--r-- 13,414 bytes parent folder | download
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398

/**************************************************************************
 *                                                                        *
 *  Regina - A Normal Surface Theory Calculator                           *
 *  Computational Engine                                                  *
 *                                                                        *
 *  Copyright (c) 1999-2011, Ben Burton                                   *
 *  For further details contact Ben Burton (bab@debian.org).              *
 *                                                                        *
 *  This program is free software; you can redistribute it and/or         *
 *  modify it under the terms of the GNU General Public License as        *
 *  published by the Free Software Foundation; either version 2 of the    *
 *  License, or (at your option) any later version.                       *
 *                                                                        *
 *  This program is distributed in the hope that it will be useful, but   *
 *  WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 *  General Public License for more details.                              *
 *                                                                        *
 *  You should have received a copy of the GNU General Public             *
 *  License along with this program; if not, write to the Free            *
 *  Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,       *
 *  MA 02110-1301, USA.                                                   *
 *                                                                        *
 **************************************************************************/

/* end stub */

/*! \file triangulation/nfacetspec.h
 *  \brief Allows lightweight representation of individual facets of
 *  simplices.
 */

#ifndef __NFACETSPEC_H
#ifndef __DOXYGEN
#define __NFACETSPEC_H
#endif

#include "regina-core.h"

namespace regina {

/**
 * \weakgroup triangulation
 * @{
 */

/**
 * A lightweight class used to refer to a particular facet of a
 * particular simplex in a triangulation.  Only the simplex index
 * and the facet number are stored.
 *
 * The template parameter gives the dimension of the triangulation
 * (so for dimension three, this class describes a face of a tetrahedron,
 * and for dimension four it describes a facet of a pentachoron).
 *
 * Facilities are provided for iterating through simplex facets.
 * With this in mind, it is also possible to represent the overall
 * boundary, a past-the-end value and a before-the-start value.
 *
 * When iterating through the simplex facets, the facets will be
 * ordered first by simplex index and then by facet number.  The
 * overall boundary appears after all other simplex facets.
 *
 * If there are \a n simplices, the simplices will be numbered from 0
 * to <i>n</i>-1 inclusive.  The boundary will be represented as
 * simplex \a n, facet 0.  The past-the-end value will be represented
 * as simplex \a n, facet 1, and the before-the-start value will be
 * represented as simplex -1, facet \a dim.
 *
 * \ifacespython The generic template NFacetSpec is not available to
 * Python users, although the special 3-dimensional case NTetFace is.
 * All Python notes in this class refer to the special case
 * NTetFace only.
 */
template <int dim>
struct NFacetSpec {
    int simp;
        /**< The simplex referred to.  Simplex numbering begins
         *   at 0. */
    int facet;
        /**< The facet of the simplex referred to.  The facet number
         *   is between 0 and \a dim inclusive. */

    /**
     * Creates a new specifier with no initialisation.  This
     * specifier must be initialised before it is used.
     */
    NFacetSpec();
    /**
     * Creates a new specifier referring to the given facet of the given
     * simplex.
     *
     * @param newSimp the given simplex; see the class notes for
     * allowable values of this parameter.
     * @param newFacet the given facet; this should be between 0 and
     * \a dim inclusive.
     */
    NFacetSpec(int newSimp, int newFacet);
    /**
     * Creates a new specifier referring to the same simplex facet as
     * the given specifier.
     *
     * @param cloneMe the specifier to clone.
     */
    NFacetSpec(const NFacetSpec<dim>& cloneMe);

    /**
     * Determines if this specifier represents the overall boundary.
     *
     * @param nSimplices the number of simplices under consideration.
     * Note that the boundary is represented in this specifier as
     * simplex \a nSimplices, facet 0.
     * @return \c true if and only if this specifier represents the
     * overall boundary.
     */
    bool isBoundary(unsigned nSimplices) const;
    /**
     * Determines if this specifier represents a before-the-start value.
     *
     * @return \c true if and only if this specifier is before-the-start.
     */
    bool isBeforeStart() const;
    /**
     * Determines if this specifier represents a past-the-end value.
     * You can optionally declare the overall boundary to be
     * past-the-end as well as the already predefined past-the-end value.
     *
     * @param nSimplices the number of simplices under consideration.
     * Note that past-the-end is represented in this specifier as
     * simplex \a nSimplices, facet 1.
     * @param boundaryAlso \c true if the overall boundary should be
     * considered past-the-end in addition to the predefined past-the-end
     * value.
     * @return \c true if and only if this specifier is past-the-end.
     */
    bool isPastEnd(unsigned nSimplices, bool boundaryAlso) const;

    /**
     * Sets this specifier to the first facet of the first simplex.
     */
    void setFirst();
    /**
     * Sets this specifier to the overall boundary.
     *
     * @param nSimplices the number of simplices under consideration.
     * Note that the boundary is represented in this specifier as
     * simplex \a nSimplices, facet 0.
     */
    void setBoundary(unsigned nSimplices);
    /**
     * Sets this specifier to before-the-start.
     */
    void setBeforeStart();
    /**
     * Sets this specifier to past-the-end.
     *
     * @param nSimplices the number of simplices under consideration.
     * Note that past-the-end is represented in this specifier as
     * simplex \a nSimplices, facet 1.
     */
    void setPastEnd(unsigned nSimplices);

    /**
     * Sets this specifier to the value of the given specifier.
     *
     * @param other the given specifier.
     * @return a reference to this specifier.
     */
    NFacetSpec& operator = (const NFacetSpec<dim>& other);
    /**
     * Increments this specifier.  It will be changed to point to the
     * next simplex facet.
     *
     * Faces are ordered first by simplex index and then by facet
     * number.  The overall boundary appears after all other facets.
     *
     * \pre This specifier is not past-the-end.
     *
     * \ifacespython Not present, although the preincrement operator is
     * present in python as the member function inc().
     *
     * @return A copy of this specifier after it has been incremented.
     */
    NFacetSpec operator ++ ();
    /**
     * Increments this specifier.  It will be changed to point to the
     * next simplex facet.
     *
     * Faces are ordered first by simplex index and then by facet
     * number.  The overall boundary appears after all other facets.
     *
     * \pre This specifier is not past-the-end.
     *
     * \ifacespython This routine is named inc() since python does not
     * support the increment operator.
     *
     * @return A copy of this specifier before it was incremented.
     */
    NFacetSpec operator ++ (int);
    /**
     * Decrements this specifier.  It will be changed to point to the
     * previous simplex facet.
     *
     * Faces are ordered first by simplex index and then by facet
     * number.  The overall boundary appears after all other facets.
     *
     * \pre This specifier is not before-the-start.
     *
     * \ifacespython Not present, although the predecrement operator is
     * present in python as the member function dec().
     *
     * @return A copy of this specifier after it has been decremented.
     */
    NFacetSpec operator -- ();
    /**
     * Decrements this specifier.  It will be changed to point to the
     * previous simplex facet.
     *
     * Faces are ordered first by simplex index and then by facet
     * number.  The overall boundary appears after all other facets.
     *
     * \pre This specifier is not before-the-start.
     *
     * \ifacespython This routine is named dec() since python does not
     * support the decrement operator.
     *
     * @return A copy of this specifier before it was decremented.
     */
    NFacetSpec operator -- (int);

    /**
     * Determines if this and the given specifier are identical.
     *
     * @param other the specifier to compare with this.
     * @return \c true if and only if this and the given specifier are
     * equal.
     */
    bool operator == (const NFacetSpec<dim>& other) const;
    /**
     * Determines if this is less than the given specifier.
     *
     * @param other the specifier to compare with this.
     * @return \c true if and only if this is less than the given
     * specifier.
     */
    bool operator < (const NFacetSpec<dim>& other) const;
    /**
     * Determines if this is less than or equal to the given specifier.
     *
     * @param other the specifier to compare with this.
     * @return \c true if and only if this is less than or equal to
     * the given specifier.
     */
    bool operator <= (const NFacetSpec<dim>& other) const;
};

/**
 * A lightweight class used to refer to a particular face of a
 * particular tetrahedron in a 3-manifold triangulation.  This is a
 * convenience typedef for the template instance NFacetSpec<3>.
 *
 * \ifacespython The specific class NTetFace is available through Python,
 * even though the generic template NFacetSpec is not.  Both the old field
 * names (\a tet and \a face) and the new field names (\a simp and \a facet)
 * are provided, though the old names are deprecated and will be removed
 * in a future version of Regina.
 *
 * \deprecated For the 3-dimensional class NTetFace, the old field names
 * \a tet and \a face are deprecated.  Please use the new (generic) names
 * \a simp and \a facet instead.  The old names are no longer supported
 * in C++, but will continue to be supported in Python until Regina 5.0.
 */
typedef NFacetSpec<3> NTetFace;

/*@}*/

// Inline functions for NFacetSpec

template <int dim>
inline NFacetSpec<dim>::NFacetSpec() {
}

template <int dim>
inline NFacetSpec<dim>::NFacetSpec(int newSimp, int newFacet) :
        simp(newSimp), facet(newFacet) {
}

template <int dim>
inline NFacetSpec<dim>::NFacetSpec(const NFacetSpec& cloneMe) :
        simp(cloneMe.simp), facet(cloneMe.facet) {
}

template <int dim>
inline bool NFacetSpec<dim>::isBoundary(unsigned nSimplices) const {
    return (simp == static_cast<int>(nSimplices) && facet == 0);
}

template <int dim>
inline bool NFacetSpec<dim>::isBeforeStart() const {
    return (simp < 0);
}

template <int dim>
inline bool NFacetSpec<dim>::isPastEnd(unsigned nSimplices, bool boundaryAlso)
        const {
    return (simp == static_cast<int>(nSimplices) &&
        (boundaryAlso || facet > 0));
}

template <int dim>
inline void NFacetSpec<dim>::setFirst() {
    simp = facet = 0;
}

template <int dim>
inline void NFacetSpec<dim>::setBoundary(unsigned nSimplices) {
    simp = nSimplices;
    facet = 0;
}

template <int dim>
inline void NFacetSpec<dim>::setBeforeStart() {
    simp = -1;
    facet = dim;
}

template <int dim>
inline void NFacetSpec<dim>::setPastEnd(unsigned nSimplices) {
    simp = nSimplices;
    facet = 1;
}

template <int dim>
inline NFacetSpec<dim>& NFacetSpec<dim>::operator = (
        const NFacetSpec<dim>& other) {
    simp = other.simp;
    facet = other.facet;
    return *this;
}

template <int dim>
inline NFacetSpec<dim> NFacetSpec<dim>::operator ++ () {
    if (++facet > dim) {
        facet = 0;
        ++simp;
    }
    return *this;
}

template <int dim>
inline NFacetSpec<dim> NFacetSpec<dim>::operator ++ (int) {
    NFacetSpec<dim> ans(*this);
    if (++facet > dim) {
        facet = 0;
        ++simp;
    }
    return ans;
}

template <int dim>
inline NFacetSpec<dim> NFacetSpec<dim>::operator -- () {
    if (--facet < 0) {
        facet = dim;
        --simp;
    }
    return *this;
}

template <int dim>
inline NFacetSpec<dim> NFacetSpec<dim>::operator -- (int) {
    NFacetSpec<dim> ans(*this);
    if (--facet < 0) {
        facet = dim;
        --simp;
    }
    return ans;
}

template <int dim>
inline bool NFacetSpec<dim>::operator == (const NFacetSpec<dim>& other) const {
    return (simp == other.simp && facet == other.facet);
}

template <int dim>
inline bool NFacetSpec<dim>::operator < (const NFacetSpec<dim>& other) const {
    return (simp < other.simp || (simp == other.simp && facet < other.facet));
}

template <int dim>
inline bool NFacetSpec<dim>::operator <= (const NFacetSpec<dim>& other) const {
    return (simp < other.simp || (simp == other.simp && facet <= other.facet));
}

} // namespace regina

#endif