Skip to content

Commit

Permalink
Prefer using getValue
Browse files Browse the repository at this point in the history
In preparation for changing subscript operators, change python bindings
where appropriate which get the pointers.

Signed-off-by: Kimball Thurston <[email protected]>
  • Loading branch information
kdt3rd committed Nov 3, 2024
1 parent 2ac0e8f commit 6c05a14
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
26 changes: 24 additions & 2 deletions src/python/PyImath/PyImathFixedArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <boost/any.hpp>
#include <iostream>
#include "PyImathUtil.h"
#include "ImathVec.h"

//
// Note: when PyImath from the v2 release of OpenEXR depended on Iex,
Expand Down Expand Up @@ -292,7 +293,7 @@ class FixedArray
_unmaskedLength(other._unmaskedLength)
{
}

const FixedArray &
operator = (const FixedArray &other)
{
Expand Down Expand Up @@ -357,7 +358,7 @@ class FixedArray
start = i; end = i+1; step = 1; slicelength = 1;
} else {
PyErr_SetString(PyExc_TypeError, "Object is not a slice");
boost::python::throw_error_already_set();
boost::python::throw_error_already_set();
}
}

Expand Down Expand Up @@ -832,6 +833,27 @@ struct IndexAccessDefault {
static Data & apply(Container &c, size_t i) { return c[i]; }
};

template <class Data>
struct IndexAccessDefault<IMATH_INTERNAL_NAMESPACE::Vec2<Data>, Data> {
using Container = IMATH_INTERNAL_NAMESPACE::Vec2<Data>;
typedef Data & result_type;
static Data & apply(Container &c, size_t i) { return *(c.getValue () + i); }
};

template <class Data>
struct IndexAccessDefault<IMATH_INTERNAL_NAMESPACE::Vec3<Data>, Data> {
using Container = IMATH_INTERNAL_NAMESPACE::Vec3<Data>;
typedef Data & result_type;
static Data & apply(Container &c, size_t i) { return *(c.getValue () + i); }
};

template <class Data>
struct IndexAccessDefault<IMATH_INTERNAL_NAMESPACE::Vec4<Data>, Data> {
using Container = IMATH_INTERNAL_NAMESPACE::Vec4<Data>;
typedef Data & result_type;
static Data & apply(Container &c, size_t i) { return *(c.getValue () + i); }
};

template <class Container, class Data, int Length, class IndexAccess = IndexAccessDefault<Container,Data> >
struct StaticFixedArray
{
Expand Down
2 changes: 1 addition & 1 deletion src/python/PyImath/PyImathVec2Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ template <class T,int index>
static FixedArray<T>
Vec2Array_get(FixedArray<IMATH_NAMESPACE::Vec2<T> > &va)
{
return FixedArray<T>(&(va.unchecked_index(0)[index]),
return FixedArray<T>(va.unchecked_index(0).getValue () + index,
va.len(), 2*va.stride(), va.handle(), va.writable());
}

Expand Down
2 changes: 1 addition & 1 deletion src/python/PyImathNumpy/imathnumpymodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ arrayToNumpy_vector(T &va)

int type = NumpyTypeFromType<PodType>::typeEnum;
npy_intp dims[2]{ va.len(), BaseType::dimensions()};
PodType *data = &va[0][0];
PodType *data = va[0].getValue ();
PyObject *a = PyArray_SimpleNewFromData(2, dims, type, data);

if (!a)
Expand Down

0 comments on commit 6c05a14

Please sign in to comment.