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