Skip to content

Commit f65b01c

Browse files
authored
Complete pybind11 wrappings for V2, V3, V4, and add pyBindImathTest (AcademySoftwareFoundation#472)
This does three things: 1. Completes the vector class wrapping, so all previous functionality is supported, including interoperability between vector classes (i.e. V2i + V2f), and interoperability between vectors and tuples and lists (i.e. V2i(1,2) + [1,2]). 2. Adds src/pybind11/PyBindImathTest/pyBindImathTest, which is a duplicate of the original test script for the Boost-based bindings, with the not-yet-implemented features commented out for now. 3. Adds wrappings for miscellaneous functions in PyImathFun.cpp, which are needed by the vector tests. The vector class tests pass, so the pybind11 functionality is now consistent with existing Boost-based bindings. All new wrappings should un-comment out the appropriate tests and validate that they pass. Signed-off-by: Cary Phillips <cary@ilm.com>
1 parent 2859857 commit f65b01c

9 files changed

Lines changed: 11326 additions & 101 deletions

File tree

.github/workflows/ci_steps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123

124124
- name: Upload install_manifest.txt
125125
# Upload the manifest to make it possible to download for inspection and debugging
126-
uses: actions/upload-artifact@v4
126+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
127127
with:
128128
name: ${{ env.INSTALL_MANIFEST }}
129129
path: _build/${{ env.INSTALL_MANIFEST }}

src/pybind11/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ set(PYBINDIMATH_LIB_SUFFIX "-${IMATH_VERSION_API}" CACHE STRING "String added to
1515
set(PYBINDIMATH_LIB_PYTHONVER_ROOT "_Python" CACHE STRING "String added as a root to the identifier of the python version in the libraries")
1616

1717
add_subdirectory(PyBindImath)
18+
if(BUILD_TESTING)
19+
enable_testing()
20+
add_subdirectory( PyBindImathTest )
21+
endif()
22+

src/pybind11/PyBindImath/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ find_package(pybind11 REQUIRED)
99
#
1010

1111
set(PYBINDIMATH_SOURCES
12+
PyBindImathFun.cpp
1213
PyBindImathBox.cpp
1314
PyBindImathVec.cpp
1415
PyBindImathPlane.cpp
@@ -120,4 +121,5 @@ if(IMATH_BUILD_APPLE_FRAMEWORKS)
120121
MACOSX_FRAMEWORK_IDENTIFIER github.com/AcademySoftwareFoundation/Imath.PyBind
121122
MACOSX_FRAMEWORK_BUNDLE_VERSION PYBINDIMATH_LIB_SUFFIX
122123
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${Imath_VERSION})
123-
endif()
124+
endif()
125+

src/pybind11/PyBindImath/PyBindImath.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace PyBindImath {
1919

20+
PYBINDIMATH_EXPORT void register_imath_fun(pybind11::module& m);
21+
2022
PYBINDIMATH_EXPORT void register_imath_vec(pybind11::module& m);
2123
PYBINDIMATH_EXPORT void register_imath_box(pybind11::module& m);
2224
PYBINDIMATH_EXPORT void register_imath_plane(pybind11::module& m);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
// Copyright Contributors to the OpenEXR Project.
4+
//
5+
6+
#include "PyBindImath.h"
7+
#include <ImathFun.h>
8+
9+
namespace py = pybind11;
10+
11+
namespace PyBindImath {
12+
13+
template <class T>
14+
void
15+
register_imath_funT(py::module& m)
16+
{
17+
m.def("cmp", IMATH_NAMESPACE::cmp<T>);
18+
m.def("cmpt", IMATH_NAMESPACE::cmpt<T>);
19+
m.def("iszero", IMATH_NAMESPACE::iszero<T>);
20+
m.def("equal", IMATH_NAMESPACE::equal<T, T, T>);
21+
22+
}
23+
24+
void
25+
register_imath_fun(py::module& m)
26+
{
27+
register_imath_funT<int>(m);
28+
register_imath_funT<float>(m);
29+
register_imath_funT<double>(m);
30+
}
31+
32+
33+
} // namespace PyBindImath

0 commit comments

Comments
 (0)