// // SPDX-License-Identifier: BSD-3-Clause // Copyright Contributors to the OpenEXR Project. // // clang-format off #ifndef _PyImathBoxArrayImpl_h_ #define _PyImathBoxArrayImpl_h_ // // This .C file was turned into a header file so that instantiations // of the various Box* types can be spread across multiple files in // order to work around MSVC limitations. // #include #include #include #include #include #include #include #include "PyImath.h" #include "PyImathBox.h" #include "PyImathDecorators.h" #include "PyImathMathExc.h" #include "PyImathOperators.h" #include "PyImathVecOperators.h" namespace PyImath { using namespace boost::python; using namespace IMATH_NAMESPACE; template static FixedArray BoxArray_get(FixedArray > &va) { return index == 0 ? FixedArray(&(va.unchecked_index(0).min), va.len(),2*va.stride(),va.handle(),va.writable()) : FixedArray(&(va.unchecked_index(0).max), va.len(),2*va.stride(),va.handle(),va.writable()); } template static void setItemTuple(FixedArray > &va, Py_ssize_t index, const tuple &t) { if(t.attr("__len__")() == 2) { Box v; v.min = extract(t[0]); v.max = extract(t[1]); va[(size_t)va.canonical_index(index)] = v; } else throw std::invalid_argument ("tuple of length 2 expected"); } template class_ > > register_BoxArray() { using boost::mpl::true_; using boost::mpl::false_; class_ > > boxArray_class = FixedArray >::register_("Fixed length array of IMATH_NAMESPACE::Box"); boxArray_class .add_property("min",&BoxArray_get) .add_property("max",&BoxArray_get) .def("__setitem__", &setItemTuple) ; add_comparison_functions(boxArray_class); decoratecopy(boxArray_class); return boxArray_class; } } // namespace PyImath #endif // _PyImathBoxArrayImpl_h_