File: face-bindings.h

package info (click to toggle)
regina-normal 7.4.1-1.1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 154,244 kB
  • sloc: cpp: 295,026; xml: 9,992; sh: 1,344; python: 1,225; perl: 616; ansic: 138; makefile: 26
file content (202 lines) | stat: -rw-r--r-- 10,430 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

/**************************************************************************
 *                                                                        *
 *  Regina - A Normal Surface Theory Calculator                           *
 *  Python Interface                                                      *
 *                                                                        *
 *  Copyright (c) 1999-2025, 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.                       *
 *                                                                        *
 *  As an exception, when this program is distributed through (i) the     *
 *  App Store by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or     *
 *  (iii) Google Play by Google Inc., then that store may impose any      *
 *  digital rights management, device limits and/or redistribution        *
 *  restrictions that are required by its terms of service.               *
 *                                                                        *
 *  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, see <https://www.gnu.org/licenses/>. *
 *                                                                        *
 **************************************************************************/

#include <pybind11/pybind11.h>
#include "triangulation/generic.h"
#include "../helpers.h"
#include "../generic/facehelper.h"
#include "../docstrings/triangulation/alias/facenumber.h"
#include "../docstrings/triangulation/generic/face.h"
#include "../docstrings/triangulation/generic/faceembedding.h"
#include "../docstrings/triangulation/detail/face.h"
#include "../docstrings/triangulation/detail/facenumbering.h"

using regina::Face;
using regina::FaceEmbedding;

template <int dim, int subdim>
void addFace(pybind11::module_& m, pybind11::module_& internal,
        const char* name, const char* embName) {
    RDOC_SCOPE_BEGIN(FaceEmbedding)
    RDOC_SCOPE_BASE_2(detail::FaceEmbeddingBase, alias::FaceNumber)

    auto e = pybind11::class_<FaceEmbedding<dim, subdim>>(m, embName,
            rdoc_scope)
        .def(pybind11::init<regina::Simplex<dim>*, regina::Perm<dim + 1>>(),
            rdoc::__init)
        .def(pybind11::init<const FaceEmbedding<dim, subdim>&>(), rdoc::__copy)
        .def("simplex", &FaceEmbedding<dim, subdim>::simplex,
            pybind11::return_value_policy::reference, rbase::simplex)
        .def("face", &FaceEmbedding<dim, subdim>::face, rbase::face)
        .def("vertices", &FaceEmbedding<dim, subdim>::vertices, rbase::vertices)
    ;
    if constexpr (subdim == 0)
        e.def("vertex", &FaceEmbedding<dim, subdim>::vertex, rbase2::vertex);
    else if constexpr (subdim == 1)
        e.def("edge", &FaceEmbedding<dim, subdim>::edge, rbase2::edge);
    else if constexpr (subdim == 2)
        e.def("triangle", &FaceEmbedding<dim, subdim>::triangle,
            rbase2::triangle);
    else if constexpr (subdim == 3)
        e.def("tetrahedron", &FaceEmbedding<dim, subdim>::tetrahedron,
            rbase2::tetrahedron);
    else if constexpr (subdim == 4)
        e.def("pentachoron", &FaceEmbedding<dim, subdim>::pentachoron,
            rbase2::pentachoron);
    regina::python::add_output(e);
    regina::python::add_eq_operators(e, rbase::__eq);

    // We use the global scope here because all of Face's members are
    // inherited, and so Face's own docstring namespace does not exist.
    RDOC_SCOPE_SWITCH_MAIN
    RDOC_SCOPE_BASE_2(detail::FaceBase, detail::FaceNumberingAPI)

    auto c = pybind11::class_<regina::Face<dim, subdim>>(m, name, rdoc::Face)
        .def("isValid", &Face<dim, subdim>::isValid, rbase::isValid)
        // Only standard dimensions offer hasBadLink().
        .def("hasBadIdentification", &Face<dim, subdim>::hasBadIdentification,
            rbase::hasBadIdentification)
        .def("isLinkOrientable", &Face<dim, subdim>::isLinkOrientable,
            rbase::isLinkOrientable)
        .def("degree", &Face<dim, subdim>::degree, rbase::degree)
        .def("embedding", &Face<dim, subdim>::embedding, rbase::embedding)
        .def("embeddings", &Face<dim, subdim>::embeddings, rbase::embeddings)
        .def("__iter__", [](const Face<dim, subdim>& f) {
            // By default, make_iterator uses reference_internal.
            return pybind11::make_iterator<pybind11::return_value_policy::copy>(
                f.begin(), f.end());
        }, pybind11::keep_alive<0, 1>(), // iterator keeps Face alive
            rbase::__iter__)
        .def("front", &Face<dim, subdim>::front, rbase::front)
        .def("back", &Face<dim, subdim>::back, rbase::back)
        .def("index", &Face<dim, subdim>::index, rbase::index)
        .def("triangulation", &Face<dim, subdim>::triangulation,
            rbase::triangulation)
        .def("component", &Face<dim, subdim>::component,
            pybind11::return_value_policy::reference, rbase::component)
        .def("boundaryComponent", &Face<dim, subdim>::boundaryComponent,
            pybind11::return_value_policy::reference, rbase::boundaryComponent)
        .def("isBoundary", &Face<dim, subdim>::isBoundary, rbase::isBoundary)
        .def_static("ordering", &Face<dim, subdim>::ordering, rbase2::ordering)
        .def_static("containsVertex", &Face<dim, subdim>::containsVertex,
            rbase2::containsVertex)
        .def_readonly_static("nFaces", &Face<dim, subdim>::nFaces)
        .def_readonly_static("lexNumbering", &Face<dim, subdim>::lexNumbering)
        .def_readonly_static("oppositeDim", &Face<dim, subdim>::oppositeDim)
        .def_readonly_static("dimension", &Face<dim, subdim>::dimension)
        .def_readonly_static("subdimension", &Face<dim, subdim>::subdimension)
    ;
    if constexpr (subdim == 1) {
        c.def_static("faceNumber",
            pybind11::overload_cast<regina::Perm<dim+1>>(
                &Face<dim, subdim>::faceNumber),
            rbase2::faceNumber);
        c.def_static("faceNumber",
            pybind11::overload_cast<int, int>(&Face<dim, subdim>::faceNumber),
            rbase2::faceNumber);
    } else {
        c.def_static("faceNumber", &Face<dim, subdim>::faceNumber,
            rbase2::faceNumber);
    }
    if constexpr (subdim > 0) {
        c.def("face", &regina::python::face<Face<dim, subdim>, subdim, int>,
            pybind11::arg("lowerdim"), pybind11::arg("face"),
            rbase::face);
        c.def("faceMapping",
            &regina::python::faceMapping<Face<dim, subdim>, subdim, dim + 1>,
            pybind11::arg("lowerdim"), pybind11::arg("face"),
            rbase::faceMapping);
    }
    if constexpr (subdim > 4) {
        c.def("pentachoron", &Face<dim, subdim>::pentachoron,
            pybind11::return_value_policy::reference, rbase::pentachoron);
        c.def("pentachoronMapping", &Face<dim, subdim>::pentachoronMapping,
            rbase::pentachoronMapping);
    }
    if constexpr (subdim > 3) {
        c.def("tetrahedron", &Face<dim, subdim>::tetrahedron,
            pybind11::return_value_policy::reference, rbase::tetrahedron);
        c.def("tetrahedronMapping", &Face<dim, subdim>::tetrahedronMapping,
            rbase::tetrahedronMapping);
    }
    if constexpr (subdim > 2) {
        c.def("triangle", &Face<dim, subdim>::triangle,
            pybind11::return_value_policy::reference, rbase::triangle);
        c.def("triangleMapping", &Face<dim, subdim>::triangleMapping,
            rbase::triangleMapping);
    }
    if constexpr (subdim > 1) {
        c.def("edge", &Face<dim, subdim>::edge,
            pybind11::return_value_policy::reference, rbase::edge);
        c.def("edgeMapping", &Face<dim, subdim>::edgeMapping,
            rbase::edgeMapping);
    }
    if constexpr (subdim > 0) {
        c.def("vertex", &Face<dim, subdim>::vertex,
            pybind11::return_value_policy::reference, rbase::vertex);
        c.def("vertexMapping", &Face<dim, subdim>::vertexMapping,
            rbase::vertexMapping);
    }
    if constexpr (subdim == 1) {
        c.def("isLoop", &Face<dim, subdim>::isLoop, rbase::isLoop);
    }
    if constexpr (subdim == 2) {
        c.def("triangleType", &Face<dim, subdim>::triangleType,
            rbase::triangleType);
        c.def("triangleSubtype", &Face<dim, subdim>::triangleSubtype,
            rbase::triangleSubtype);
        c.def("formsMobiusBand", &Face<dim, subdim>::formsMobiusBand,
            rbase::formsMobiusBand);
        c.def("formsCone", &Face<dim, subdim>::formsCone, rbase::formsCone);
    }
    if constexpr (dim - subdim == 1) {
        c.def("join", &Face<dim, subdim>::join, rbase::join);
        c.def("lock", &Face<dim, subdim>::lock, rbase::lock);
        c.def("unlock", &Face<dim, subdim>::unlock, rbase::unlock);
        c.def("isLocked", &Face<dim, subdim>::isLocked, rbase::isLocked);
        c.def("inMaximalForest", &Face<dim, subdim>::inMaximalForest,
            rbase::inMaximalForest);
    }
    regina::python::add_output(c);
    regina::python::add_eq_operators(c);

    RDOC_SCOPE_END

    regina::python::addListView<
        decltype(std::declval<Face<dim, subdim>>().embeddings())>(internal,
        (std::string(name) + "_embeddings").c_str());
    // The name we give to the next ListView class is not in the typical form
    // Triangulation<dim>_faces<subdim>; however, this is an internal class,
    // and the name we do use is easy to build from what we already know.
    regina::python::addListView<
        decltype(regina::Triangulation<dim>().template faces<subdim>())>(
        internal, (std::string(name) + "_faces").c_str());
}