-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.cpp
198 lines (177 loc) · 7.61 KB
/
module.cpp
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
// SPDX-License-Identifier: GPL-3.0-or-later
/****************************************************************************
* *
* Copyright (c) 2024 André Caldas <andre.em.caldas@gmail.com> *
* *
* This file is part of ParaCADis. *
* *
* ParaCADis 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.1 of the License, *
* or (at your option) any later version. *
* *
* ParaCADis 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 ParaCADis. If not, see <https://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#ifndef GeometricPrimitives_PY_module_h
#define GeometricPrimitives_PY_module_h
#include <nanobind/nanobind.h>
#include <nanobind/operators.h>
#include "module.h"
#include <base/geometric_primitives/CoordinateSystem.h>
#include <base/geometric_primitives/circles.h>
#include <base/geometric_primitives/deferenceables.h>
#include <base/geometric_primitives/lines.h>
#include <base/geometric_primitives/types.h>
namespace nb = nanobind;
using namespace nb::literals;
void init_geometric_primitives(nb::module_& parent_module,
nb::module_& naming_scheme)
{
auto m = parent_module.def_submodule("geometric_primitives");
m.doc() = "Basic geometric objects used in ParaCADis.";
auto exporter_base = naming_scheme.attr("ExporterBase");
/*
* Real number.
*/
nb::class_<Real>(
m, "Real",
"Real number used in ParaCADis."
" In the future it will be an algebraic structure (field)"
" at least with square root.")
.def(nb::init_implicit<double>(),
"Creates a real number from a double."
" (attention: do not use double for calculations).")
.def(nb::self + nb::self)
.def(nb::self - nb::self)
.def(nb::self * nb::self)
.def(nb::self / nb::self)
.def("__repr__",
[](const Real&){ return "<REAL... (put info here)>"; });
/*
* Vector.
*/
nb::class_<Vector>(
m, "Vector",
"A vector.")
.def(nb::init<>(), "Zero vector")
.def(nb::init<Real, Real, Real>(), "x"_a, "y"_a, "z"_a)
.def(nb::self + nb::self)
.def(nb::self - nb::self)
.def("__repr__",
[](const Vector&){ return "<VECTOR... (put info here)>"; });
/*
* DeferenceableVector.
*/
nb::class_<DeferenceableVector>(
m, "DeferenceableVector", exporter_base,
"A vector that can be handled as a geometric object."
" It can be put inside containers and it exports its parameters.")
.def(nb::init<>(), "Zero vector")
.def(nb::init<Real, Real, Real>(), "x"_a, "y"_a, "z"_a)
.def(nb::init<const Vector&>())
.def("__repr__",
[](const Vector&){ return "<DEFERENCEABLEVECTOR... (put info here)>"; });
/*
* Point.
*/
nb::class_<Point>(
m, "Point",
"A point.")
.def(nb::init<>(), "Origin")
.def(nb::init<Real, Real, Real>(), "x"_a, "y"_a, "z"_a)
.def("__repr__",
[](const Point&){ return "<POINT... (put info here)>"; });
/*
* DeferenceablePoint.
*/
nb::class_<DeferenceablePoint>(
m, "DeferenceablePoint", exporter_base,
"A point that can be handled as a geometric object."
" It can be put inside containers and it exports its parameters.")
.def(nb::init<>(), "Origin")
.def(nb::init<Real, Real, Real>(), "x"_a, "y"_a, "z"_a)
.def(nb::init<const Point&>())
.def("__repr__",
[](const Point&){ return "<DEFERENCEABLEPOINT... (put info here)>"; });
/*
* Line2Points.
*/
nb::class_<Line2Points>(
m, "Line2Points", exporter_base,
"An oriented straight line, half-line or segment specified by two points.")
.def(nb::init<Point, Point, bool, bool>(),
"start"_a, "end"_a,
"is_bounded_start"_a = true,
"is_bounded_end"_a = true,
"The line is determined by the points 'start' and 'end',"
" those points are also boundaries when 'is_bounded_start'"
" or 'is_bounded_end' are set to True.")
.def("__repr__",
[](const Point&){ return "<LINE2POINTS... (put info here)>"; });
/*
* LinePointDirection.
*/
nb::class_<LinePointDirection>(
m, "LinePointDirection", exporter_base,
"An oriented straight line, half-line or segment specified by"
" a starting point and a vector.")
.def(nb::init<Point, Vector, bool, bool>(),
"start"_a, "direction"_a,
"is_bounded_start"_a = true,
"is_bounded_end"_a = true,
"The line is determined by the points 'start' and 'start + direction',"
" those points are also boundaries when 'is_bounded_start'"
" or 'is_bounded_end' are set to True.")
.def("__repr__",
[](const Point&){ return "<LINEPOINTDIRECTION... (put info here)>"; });
/*
* CirclePointRadiusNormal.
*/
nb::class_<CirclePointRadiusNormal>(
m, "CirclePointRadiusNormal", exporter_base,
"An oriented circle specified by a center point,"
" the radius and a normal vector."
" The circle orientation is determined by the right-hand rule"
" applied to the normal vector"
" (a right-hand holding the normal vector is such that the fingers"
" point to the circle orientation).")
.def(nb::init<Point, Real, Vector>(),
"center"_a, "radius"_a, "normal"_a,
"Creates the circle cetered at 'center', with radius 'radius'"
" and orientation given the the 'normal' vector.")
.def("__repr__",
[](const Point&){ return "<CIRCLEPOINTRADIUSNORMAL... (put info here)>"; });
/*
* Circle3Points.
*/
nb::class_<Circle3Points>(
m, "Circle3Points", exporter_base,
"An oriented circle specified by three points.")
.def(nb::init<Point, Point, Point>(),
"a"_a, "b"_a, "c"_a,
"The circle passes by the given points."
" The orientation is determined by the sequence 'a->b->c'.")
.def("__repr__",
[](const Point&){ return "<CIRCLE3POINTS... (put info here)>"; });
/*
* DeferenceableCoordinateSystem.
*/
nb::class_<DeferenceableCoordinateSystem>(
m, "DeferenceableCoordinateSystem", exporter_base,
"A coordinate system that exports its parameters.")
.def(nb::init<>(), "Identity coordinate system.")
.def(nb::init<const Point&>(), "A translated coordinate system.")
.def(nb::init<const Point&, const Vector&, const Vector&, const Vector&>(),
"Translated coordinate system with axis."
" The axis need to be orthonormal.")
.def("__repr__",
[](const Point&){ return "<DEF_COORDINATESYSTEM... (put info here)>"; });
}
#endif