1
+ /* *
2
+ * This file contains the pybind11 reference implementation for the stugen tests,
3
+ * and was originally inspired by:
4
+ *
5
+ * https://github.com/sizmailov/pybind11-mypy-demo
6
+ *
7
+ * Copyright (c) 2016 The Pybind Development Team, All rights reserved.
8
+ *
9
+ * Redistribution and use in source and binary forms, with or without
10
+ * modification, are permitted provided that the following conditions are met:
11
+ *
12
+ * 1. Redistributions of source code must retain the above copyright notice, this
13
+ * list of conditions and the following disclaimer.
14
+ *
15
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
16
+ * this list of conditions and the following disclaimer in the documentation
17
+ * and/or other materials provided with the distribution.
18
+ *
19
+ * 3. Neither the name of the copyright holder nor the names of its contributors
20
+ * may be used to endorse or promote products derived from this software
21
+ * without specific prior written permission.
22
+ *
23
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+ *
34
+ * You are under no obligation whatsoever to provide any bug fixes, patches, or
35
+ * upgrades to the features, functionality or performance of the source code
36
+ * ("Enhancements") to anyone; however, if you choose to make your Enhancements
37
+ * available either publicly, or directly to the author of this software, without
38
+ * imposing a separate written license agreement for such Enhancements, then you
39
+ * hereby grant the following license: a non-exclusive, royalty-free perpetual
40
+ * license to install, use, modify, prepare derivative works, incorporate into
41
+ * other computer software, distribute, and sublicense such enhancements or
42
+ * derivative works thereof, in binary and source code form.
43
+ */
44
+
1
45
#include < cmath>
2
46
#include < pybind11/pybind11.h>
3
47
@@ -68,7 +112,7 @@ const Point Point::y_axis = Point(0, 1);
68
112
Point::LengthUnit Point::length_unit = Point::LengthUnit::mm;
69
113
Point::AngleUnit Point::angle_unit = Point::AngleUnit::radian;
70
114
71
- }
115
+ } // namespace: basics
72
116
73
117
void bind_basics (py::module & basics) {
74
118
@@ -80,7 +124,6 @@ void bind_basics(py::module& basics) {
80
124
basics.def (" midpoint" , &midpoint, py::arg (" left" ), py::arg (" right" ));
81
125
basics.def (" weighted_midpoint" , weighted_midpoint, py::arg (" left" ), py::arg (" right" ), py::arg (" alpha" )=0.5 );
82
126
83
-
84
127
// Classes
85
128
py::class_<Point> pyPoint (basics, " Point" );
86
129
py::enum_<Point::LengthUnit> pyLengthUnit (pyPoint, " LengthUnit" );
@@ -103,30 +146,25 @@ void bind_basics(py::module& basics) {
103
146
.def_property_static (" angle_unit" ,
104
147
[](py::object& /* cls*/ ){ return Point::angle_unit; },
105
148
[](py::object& /* cls*/ , Point::AngleUnit value){ Point::angle_unit = value; }
106
- )
107
- ;
149
+ );
108
150
109
151
pyPoint.attr (" origin" ) = Point::origin;
110
152
111
153
pyLengthUnit
112
154
.value (" mm" , Point::LengthUnit::mm)
113
155
.value (" pixel" , Point::LengthUnit::pixel)
114
- .value (" inch" , Point::LengthUnit::inch)
115
- ;
156
+ .value (" inch" , Point::LengthUnit::inch);
116
157
117
158
pyAngleUnit
118
159
.value (" radian" , Point::AngleUnit::radian)
119
- .value (" degree" , Point::AngleUnit::degree)
120
- ;
160
+ .value (" degree" , Point::AngleUnit::degree);
121
161
122
162
// Module-level attributes
123
163
basics.attr (" PI" ) = std::acos (-1 );
124
164
basics.attr (" __version__" ) = " 0.0.1" ;
125
165
}
126
166
127
167
PYBIND11_MODULE (pybind11_mypy_demo, m) {
128
-
129
168
auto basics = m.def_submodule (" basics" );
130
169
bind_basics (basics);
131
-
132
170
}
0 commit comments