diff --git a/src/Imath/ImathBox.h b/src/Imath/ImathBox.h index 0ab65b74..6d736465 100644 --- a/src/Imath/ImathBox.h +++ b/src/Imath/ImathBox.h @@ -150,6 +150,9 @@ typedef Box Box2i; /// 2D box of base type `int64_t`. typedef Box Box2i64; +/// 2D box of base type `half`. +typedef Box Box2h; + /// 2D box of base type `float`. typedef Box Box2f; @@ -165,6 +168,9 @@ typedef Box Box3i; /// 3D box of base type `int64_t`. typedef Box Box3i64; +/// 3D box of base type `half`. +typedef Box Box3h; + /// 3D box of base type `float`. typedef Box Box3f; @@ -515,48 +521,36 @@ template IMATH_HOSTDEVICE inline void Box>::extendBy (const Vec2& point) IMATH_NOEXCEPT { - if (point[0] < min[0]) min[0] = point[0]; - - if (point[0] > max[0]) max[0] = point[0]; - - if (point[1] < min[1]) min[1] = point[1]; - - if (point[1] > max[1]) max[1] = point[1]; + min.x = std::min (min.x, point.x); + max.x = std::max (max.x, point.x); + min.y = std::min (min.y, point.y); + max.y = std::max (max.y, point.y); } template IMATH_HOSTDEVICE inline void Box>::extendBy (const Box>& box) IMATH_NOEXCEPT { - if (box.min[0] < min[0]) min[0] = box.min[0]; - - if (box.max[0] > max[0]) max[0] = box.max[0]; - - if (box.min[1] < min[1]) min[1] = box.min[1]; - - if (box.max[1] > max[1]) max[1] = box.max[1]; + min.x = std::min (min.x, box.min.x); + max.x = std::max (max.x, box.max.x); + min.y = std::min (min.y, box.min.y); + max.y = std::max (max.y, box.max.y); } template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool Box>::intersects (const Vec2& point) const IMATH_NOEXCEPT { - if (point[0] < min[0] || point[0] > max[0] || point[1] < min[1] || - point[1] > max[1]) - return false; - - return true; + return (point.x >= min.x) && (point.x <= max.x) && + (point.y >= min.y) && (point.y <= max.y); } template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool Box>::intersects (const Box>& box) const IMATH_NOEXCEPT { - if (box.max[0] < min[0] || box.min[0] > max[0] || box.max[1] < min[1] || - box.min[1] > max[1]) - return false; - - return true; + return (box.min.x <= max.x) && (box.max.x >= min.x) && + (box.min.y <= max.y) && (box.max.y >= min.y); } template @@ -579,19 +573,17 @@ template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool Box>::isEmpty () const IMATH_NOEXCEPT { - if (max[0] < min[0] || max[1] < min[1]) return true; - - return false; + return (max.x < min.x || max.y < min.y); } template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool Box>::isInfinite () const IMATH_NOEXCEPT { - if (min[0] != std::numeric_limits::lowest () || - max[0] != std::numeric_limits::max () || - min[1] != std::numeric_limits::lowest () || - max[1] != std::numeric_limits::max ()) + if (min.x != std::numeric_limits::lowest () || + max.x != std::numeric_limits::max () || + min.y != std::numeric_limits::lowest () || + max.y != std::numeric_limits::max ()) return false; return true; @@ -601,7 +593,7 @@ template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool Box>::hasVolume () const IMATH_NOEXCEPT { - if (max[0] <= min[0] || max[1] <= min[1]) return false; + if (max.x <= min.x || max.y <= min.y) return false; return true; } @@ -610,12 +602,9 @@ template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline unsigned int Box>::majorAxis () const IMATH_NOEXCEPT { - unsigned int major = 0; - Vec2 s = size (); - - if (s[1] > s[major]) major = 1; + Vec2 s = size (); - return major; + return (s.x >= s.y) ? 0 : 1; } /// @@ -769,56 +758,42 @@ template IMATH_HOSTDEVICE inline void Box>::extendBy (const Vec3& point) IMATH_NOEXCEPT { - if (point[0] < min[0]) min[0] = point[0]; - - if (point[0] > max[0]) max[0] = point[0]; - - if (point[1] < min[1]) min[1] = point[1]; - - if (point[1] > max[1]) max[1] = point[1]; - - if (point[2] < min[2]) min[2] = point[2]; - - if (point[2] > max[2]) max[2] = point[2]; + min.x = std::min (min.x, point.x); + min.y = std::min (min.y, point.y); + min.z = std::min (min.z, point.z); + max.x = std::max (max.x, point.x); + max.y = std::max (max.y, point.y); + max.z = std::max (max.z, point.z); } template IMATH_HOSTDEVICE inline void Box>::extendBy (const Box>& box) IMATH_NOEXCEPT { - if (box.min[0] < min[0]) min[0] = box.min[0]; - - if (box.max[0] > max[0]) max[0] = box.max[0]; - - if (box.min[1] < min[1]) min[1] = box.min[1]; - - if (box.max[1] > max[1]) max[1] = box.max[1]; - - if (box.min[2] < min[2]) min[2] = box.min[2]; - - if (box.max[2] > max[2]) max[2] = box.max[2]; + min.x = std::min (min.x, box.min.x); + min.y = std::min (min.y, box.min.y); + min.z = std::min (min.z, box.min.z); + max.x = std::max (max.x, box.max.x); + max.y = std::max (max.y, box.max.y); + max.z = std::max (max.z, box.max.z); } template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool Box>::intersects (const Vec3& point) const IMATH_NOEXCEPT { - if (point[0] < min[0] || point[0] > max[0] || point[1] < min[1] || - point[1] > max[1] || point[2] < min[2] || point[2] > max[2]) - return false; - - return true; + return (point.x >= min.x) && (point.x <= max.x) && + (point.y >= min.y) && (point.y <= max.y) && + (point.z >= min.z) && (point.z <= max.z); } template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool Box>::intersects (const Box>& box) const IMATH_NOEXCEPT { - if (box.max[0] < min[0] || box.min[0] > max[0] || box.max[1] < min[1] || - box.min[1] > max[1] || box.max[2] < min[2] || box.min[2] > max[2]) - return false; - - return true; + return (box.min.x <= max.x) && (box.max.x >= min.x) && + (box.min.y <= max.y) && (box.max.y >= min.y) && + (box.min.z <= max.z) && (box.max.z >= min.z); } template @@ -841,21 +816,19 @@ template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool Box>::isEmpty () const IMATH_NOEXCEPT { - if (max[0] < min[0] || max[1] < min[1] || max[2] < min[2]) return true; - - return false; + return (max.x < min.x || max.y < min.y || max.z < min.z); } template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool Box>::isInfinite () const IMATH_NOEXCEPT { - if (min[0] != std::numeric_limits::lowest () || - max[0] != std::numeric_limits::max () || - min[1] != std::numeric_limits::lowest () || - max[1] != std::numeric_limits::max () || - min[2] != std::numeric_limits::lowest () || - max[2] != std::numeric_limits::max ()) + if (min.x != std::numeric_limits::lowest () || + max.x != std::numeric_limits::max () || + min.y != std::numeric_limits::lowest () || + max.y != std::numeric_limits::max () || + min.z != std::numeric_limits::lowest () || + max.z != std::numeric_limits::max ()) return false; return true; @@ -865,7 +838,7 @@ template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool Box>::hasVolume () const IMATH_NOEXCEPT { - if (max[0] <= min[0] || max[1] <= min[1] || max[2] <= min[2]) return false; + if (max.x <= min.x || max.y <= min.y || max.z <= min.z) return false; return true; } @@ -874,14 +847,11 @@ template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline unsigned int Box>::majorAxis () const IMATH_NOEXCEPT { - unsigned int major = 0; - Vec3 s = size (); - - if (s[1] > s[major]) major = 1; + Vec3 s = size (); - if (s[2] > s[major]) major = 2; - - return major; + if (s.x >= s.y) + return (s.x >= s.z) ? 0 : 2; + return (s.y >= s.z) ? 1 : 2; } IMATH_INTERNAL_NAMESPACE_HEADER_EXIT diff --git a/src/Imath/ImathEuler.h b/src/Imath/ImathEuler.h index 17543bb6..848d5042 100644 --- a/src/Imath/ImathEuler.h +++ b/src/Imath/ImathEuler.h @@ -877,18 +877,16 @@ IMATH_HOSTDEVICE Quat if (_initialRepeated) { a[i] = cj * (cs + sc); - a[j] = sj * (cc + ss) * - parity, // NOSONAR - suppress SonarCloud bug report. - a[k] = sj * (cs - sc); - q.r = cj * (cc - ss); + a[j] = sj * (cc + ss) * parity; + a[k] = sj * (cs - sc); + q.r = cj * (cc - ss); } else { - a[i] = cj * sc - sj * cs, - a[j] = (cj * ss + sj * cc) * - parity, // NOSONAR - suppress SonarCloud bug report. - a[k] = cj * cs - sj * sc; - q.r = cj * cc + sj * ss; + a[i] = cj * sc - sj * cs; + a[j] = (cj * ss + sj * cc) * parity; + a[k] = cj * cs - sj * sc; + q.r = cj * cc + sj * ss; } q.v = a; @@ -984,9 +982,9 @@ Euler::simpleXYZRotation (Vec3& xyzRot, const Vec3& targetXyzRot) IMATH_NOEXCEPT { Vec3 d = xyzRot - targetXyzRot; - xyzRot[0] = targetXyzRot[0] + angleMod (d[0]); - xyzRot[1] = targetXyzRot[1] + angleMod (d[1]); - xyzRot[2] = targetXyzRot[2] + angleMod (d[2]); + xyzRot.x = targetXyzRot.x + angleMod (d.x); + xyzRot.y = targetXyzRot.y + angleMod (d.y); + xyzRot.z = targetXyzRot.z + angleMod (d.z); } template diff --git a/src/Imath/ImathFrame.h b/src/Imath/ImathFrame.h index 05e7bd70..2ea7b0f3 100644 --- a/src/Imath/ImathFrame.h +++ b/src/Imath/ImathFrame.h @@ -89,10 +89,11 @@ Matrix44 constexpr firstFrame ( n.normalize (); if (n.length () == 0.0f) { - int i = fabs (t[0]) < fabs (t[1]) ? 0 : 1; - if (fabs (t[2]) < fabs (t[i])) i = 2; - Vec3 v (0.0, 0.0, 0.0); + + int i = fabs (t.x) < fabs (t.y) ? 0 : 1; + if (fabs (t.z) < fabs (t[i])) i = 2; + v[i] = 1.0; n = t.cross (v); n.normalize (); @@ -102,18 +103,21 @@ Matrix44 constexpr firstFrame ( Matrix44 M; - M[0][0] = t[0]; - M[0][1] = t[1]; - M[0][2] = t[2]; - M[0][3] = 0.0, M[1][0] = n[0]; - M[1][1] = n[1]; - M[1][2] = n[2]; - M[1][3] = 0.0, M[2][0] = b[0]; - M[2][1] = b[1]; - M[2][2] = b[2]; - M[2][3] = 0.0, M[3][0] = pi[0]; - M[3][1] = pi[1]; - M[3][2] = pi[2]; + M[0][0] = t.x; + M[0][1] = t.y; + M[0][2] = t.z; + M[0][3] = 0.0; + M[1][0] = n.x; + M[1][1] = n.y; + M[1][2] = n.z; + M[1][3] = 0.0; + M[2][0] = b.x; + M[2][1] = b.y; + M[2][2] = b.z; + M[2][3] = 0.0; + M[3][0] = pi.x; + M[3][1] = pi.y; + M[3][2] = pi.z; M[3][3] = 1.0; return M; diff --git a/src/Imath/ImathMatrixAlgo.cpp b/src/Imath/ImathMatrixAlgo.cpp index 0603fa77..ca8f46de 100644 --- a/src/Imath/ImathMatrixAlgo.cpp +++ b/src/Imath/ImathMatrixAlgo.cpp @@ -834,10 +834,10 @@ twoSidedJacobiSVD ( // The off-diagonal entries are (effectively) 0, so whatever's left on the // diagonal are the singular values: - S[0] = A[0][0]; - S[1] = A[1][1]; - S[2] = A[2][2]; - S[3] = A[3][3]; + S.x = A[0][0]; + S.y = A[1][1]; + S.z = A[2][2]; + S.w = A[3][3]; // Nothing thus far has guaranteed that the singular values are positive, // so let's go back through and flip them if not (since by contract we are @@ -901,14 +901,14 @@ twoSidedJacobiSVD ( { for (int i = 0; i < 4; ++i) U[i][3] = -U[i][3]; - S[3] = -S[3]; + S.w = -S.w; } if (V.determinant () < 0) { for (int i = 0; i < 4; ++i) V[i][3] = -V[i][3]; - S[3] = -S[3]; + S.w = -S.w; } } } diff --git a/src/Imath/ImathMatrixAlgo.h b/src/Imath/ImathMatrixAlgo.h index a5cf40c1..291aabac 100644 --- a/src/Imath/ImathMatrixAlgo.h +++ b/src/Imath/ImathMatrixAlgo.h @@ -1247,8 +1247,8 @@ extractAndRemoveScalingAndShear ( T maxVal = 0; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) - if (IMATH_INTERNAL_NAMESPACE::abs (row[i][j]) > maxVal) - maxVal = IMATH_INTERNAL_NAMESPACE::abs (row[i][j]); + if (IMATH_INTERNAL_NAMESPACE::abs (mat[i][j]) > maxVal) + maxVal = IMATH_INTERNAL_NAMESPACE::abs (mat[i][j]); // // We normalize the 2x2 matrix here. @@ -1299,11 +1299,11 @@ extractAndRemoveScalingAndShear ( // Check for a coordinate system flip. If the determinant // is -1, then flip the rotation matrix and adjust the scale(Y) // and shear(XY) factors to compensate. - if (row[0][0] * row[1][1] - row[0][1] * row[1][0] < 0) + if (row[0].x * row[1].y - row[0].y * row[1].x < 0) { - row[1][0] *= -1; - row[1][1] *= -1; - scl[1] *= -1; + row[1].x *= -1; + row[1].y *= -1; + scl.y *= -1; shr *= -1; } @@ -1311,8 +1311,8 @@ extractAndRemoveScalingAndShear ( // The upper 2x2 matrix in mat is now a rotation matrix. for (int i = 0; i < 2; i++) { - mat[i][0] = row[i][0]; - mat[i][1] = row[i][1]; + mat[i][0] = row[i].x; + mat[i][1] = row[i].y; } scl *= maxVal; diff --git a/src/Imath/ImathPlatform.h b/src/Imath/ImathPlatform.h index 437b95e7..9ea79247 100644 --- a/src/Imath/ImathPlatform.h +++ b/src/Imath/ImathPlatform.h @@ -25,7 +25,9 @@ IMATH_INTERNAL_NAMESPACE_HEADER_ENTER // // Helpful macros for checking which C++ standard we are compiling with. // -# if (__cplusplus >= 202002L) +# if (__cplusplus >= 202302L) +# define IMATH_CPLUSPLUS_VERSION 23 +# elif (__cplusplus >= 202002L) # define IMATH_CPLUSPLUS_VERSION 20 # elif (__cplusplus >= 201703L) # define IMATH_CPLUSPLUS_VERSION 17 diff --git a/src/Imath/ImathVec.h b/src/Imath/ImathVec.h index 236ce8de..d286aba6 100644 --- a/src/Imath/ImathVec.h +++ b/src/Imath/ImathVec.h @@ -10,11 +10,18 @@ #ifndef INCLUDED_IMATHVEC_H #define INCLUDED_IMATHVEC_H +#ifdef __has_include +# if __has_include() +# include +# endif +#endif + #include "ImathExport.h" #include "ImathNamespace.h" #include "ImathTypeTraits.h" #include "ImathMath.h" +#include "half.h" #include #include @@ -55,7 +62,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 /// Element access by index. /// - /// NB: This method of access uses dynamic array accesses which + /// NB: This method of access may use dynamic array accesses which /// can prevent compiler optimizations and force temporaries to be /// stored to the stack and other missed vectorization /// opportunities. Use of direct access to x, y when @@ -64,7 +71,7 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec2 /// Element access by index. /// - /// NB: This method of access uses dynamic array accesses which + /// NB: This method of access may use dynamic array accesses which /// can prevent compiler optimizations and force temporaries to be /// stored to the stack and other missed vectorization /// opportunities. Use of direct access to x, y when @@ -800,6 +807,32 @@ template class IMATH_EXPORT_TEMPLATE_TYPE Vec4 /// @} #endif + /// @{ + /// @name Compatibility with Sb + + /// Set the value + template IMATH_HOSTDEVICE void setValue (S a, S b, S c, S d) IMATH_NOEXCEPT; + + /// Set the value + template + IMATH_HOSTDEVICE void setValue (const Vec4& v) IMATH_NOEXCEPT; + + /// Return the value in `a` and `b` + template + IMATH_HOSTDEVICE void getValue (S& a, S& b, S& c, S& d) const IMATH_NOEXCEPT; + + /// Return the value in `v` + template + IMATH_HOSTDEVICE void getValue (Vec4& v) const IMATH_NOEXCEPT; + + /// Return a raw pointer to the array of values + IMATH_HOSTDEVICE T* getValue () IMATH_NOEXCEPT; + + /// Return a raw pointer to the array of values + IMATH_HOSTDEVICE const T* getValue () const IMATH_NOEXCEPT; + + /// @} + /// @{ /// @name Arithmetic and Comparison @@ -997,6 +1030,9 @@ operator* (T a, const Vec4& v) IMATH_NOEXCEPT; // Typedefs for convenience //------------------------- +/// Vec2 of half +typedef Vec2 V2h; + /// Vec2 of short typedef Vec2 V2s; @@ -1012,6 +1048,9 @@ typedef Vec2 V2f; /// Vec2 of double typedef Vec2 V2d; +/// Vec3 of half +typedef Vec3 V3h; + /// Vec3 of short typedef Vec3 V3s; @@ -1027,6 +1066,9 @@ typedef Vec3 V3f; /// Vec3 of double typedef Vec3 V3d; +/// Vec4 of half +typedef Vec4 V4h; + /// Vec4 of short typedef Vec4 V4s; @@ -1229,7 +1271,18 @@ template constexpr IMATH_HOSTDEVICE inline const T& Vec2::operator[] (int i) const IMATH_NOEXCEPT { +#ifdef __cpp_if_consteval + if consteval + { + return (i == 0) ? x : y; + } + else + { + return reinterpret_cast (this)[i]; + } +#else return reinterpret_cast (this)[i]; +#endif } template IMATH_HOSTDEVICE inline Vec2::Vec2 () IMATH_NOEXCEPT @@ -1340,8 +1393,9 @@ template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool Vec2::equalWithAbsError (const Vec2& v, T e) const IMATH_NOEXCEPT { - for (int i = 0; i < 2; i++) - if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], v[i], e)) + if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError (x, v.x, e)) + return false; + if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError (y, v.y, e)) return false; return true; @@ -1351,9 +1405,10 @@ template IMATH_HOSTDEVICE IMATH_CONSTEXPR14 inline bool Vec2::equalWithRelError (const Vec2& v, T e) const IMATH_NOEXCEPT { - for (int i = 0; i < 2; i++) - if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], v[i], e)) - return false; + if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError (x, v.x, e)) + return false; + if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError (y, v.y, e)) + return false; return true; } @@ -1630,10 +1685,21 @@ Vec3::operator[] (int i) IMATH_NOEXCEPT } template -IMATH_HOSTDEVICE constexpr inline const T& +constexpr IMATH_HOSTDEVICE inline const T& Vec3::operator[] (int i) const IMATH_NOEXCEPT { +#ifdef __cpp_if_consteval + if consteval + { + return (i == 0) ? x : ((i == 1) ? y : z); + } + else + { + return reinterpret_cast (this)[i]; + } +#else return reinterpret_cast (this)[i]; +#endif } template IMATH_HOSTDEVICE inline Vec3::Vec3 () IMATH_NOEXCEPT @@ -2106,7 +2172,18 @@ template IMATH_HOSTDEVICE constexpr inline const T& Vec4::operator[] (int i) const IMATH_NOEXCEPT { +#ifdef __cpp_if_consteval + if consteval + { + return (i == 0) ? x : ((i == 1) ? y : ((i == 2) ? z : w)); + } + else + { + return reinterpret_cast (this)[i]; + } +#else return reinterpret_cast (this)[i]; +#endif } template IMATH_HOSTDEVICE inline Vec4::Vec4 () IMATH_NOEXCEPT @@ -2166,6 +2243,64 @@ IMATH_HOSTDEVICE constexpr inline Vec4::Vec4 (const Vec3& v) w (T (1)) {} +template +template +IMATH_HOSTDEVICE inline void +Vec4::setValue (S a, S b, S c, S d) IMATH_NOEXCEPT +{ + x = T (a); + y = T (b); + z = T (c); + w = T (d); +} + +template +template +IMATH_HOSTDEVICE inline void +Vec4::setValue (const Vec4& v) IMATH_NOEXCEPT +{ + x = T (v.x); + y = T (v.y); + z = T (v.z); + w = T (v.w); +} + +template +template +IMATH_HOSTDEVICE inline void +Vec4::getValue (S& a, S& b, S& c, S& d) const IMATH_NOEXCEPT +{ + a = S (x); + b = S (y); + c = S (z); + d = S (w); +} + +template +template +IMATH_HOSTDEVICE inline void +Vec4::getValue (Vec4& v) const IMATH_NOEXCEPT +{ + v.x = S (x); + v.y = S (y); + v.z = S (z); + v.w = S (w); +} + +template +IMATH_HOSTDEVICE inline T* +Vec4::getValue () IMATH_NOEXCEPT +{ + return reinterpret_cast (this); +} + +template +IMATH_HOSTDEVICE inline const T* +Vec4::getValue () const IMATH_NOEXCEPT +{ + return reinterpret_cast (this); +} + template template IMATH_HOSTDEVICE constexpr inline bool diff --git a/src/python/PyImath/PyImathFixedArray.h b/src/python/PyImath/PyImathFixedArray.h index 64283980..ad69f3fa 100644 --- a/src/python/PyImath/PyImathFixedArray.h +++ b/src/python/PyImath/PyImathFixedArray.h @@ -15,6 +15,7 @@ #include #include #include "PyImathUtil.h" +#include "ImathVec.h" // // Note: when PyImath from the v2 release of OpenEXR depended on Iex, @@ -292,7 +293,7 @@ class FixedArray _unmaskedLength(other._unmaskedLength) { } - + const FixedArray & operator = (const FixedArray &other) { @@ -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(); } } @@ -832,6 +833,27 @@ struct IndexAccessDefault { static Data & apply(Container &c, size_t i) { return c[i]; } }; +template +struct IndexAccessDefault, Data> { + using Container = IMATH_INTERNAL_NAMESPACE::Vec2; + typedef Data & result_type; + static Data & apply(Container &c, size_t i) { return *(c.getValue () + i); } +}; + +template +struct IndexAccessDefault, Data> { + using Container = IMATH_INTERNAL_NAMESPACE::Vec3; + typedef Data & result_type; + static Data & apply(Container &c, size_t i) { return *(c.getValue () + i); } +}; + +template +struct IndexAccessDefault, Data> { + using Container = IMATH_INTERNAL_NAMESPACE::Vec4; + typedef Data & result_type; + static Data & apply(Container &c, size_t i) { return *(c.getValue () + i); } +}; + template > struct StaticFixedArray { diff --git a/src/python/PyImath/PyImathVec2Impl.h b/src/python/PyImath/PyImathVec2Impl.h index 36effb28..4823f711 100644 --- a/src/python/PyImath/PyImathVec2Impl.h +++ b/src/python/PyImath/PyImathVec2Impl.h @@ -1093,7 +1093,7 @@ template static FixedArray Vec2Array_get(FixedArray > &va) { - return FixedArray(&(va.unchecked_index(0)[index]), + return FixedArray(va.unchecked_index(0).getValue () + index, va.len(), 2*va.stride(), va.handle(), va.writable()); } diff --git a/src/python/PyImathNumpy/imathnumpymodule.cpp b/src/python/PyImathNumpy/imathnumpymodule.cpp index 7cca301f..cc82ce55 100644 --- a/src/python/PyImathNumpy/imathnumpymodule.cpp +++ b/src/python/PyImathNumpy/imathnumpymodule.cpp @@ -93,7 +93,7 @@ arrayToNumpy_vector(T &va) int type = NumpyTypeFromType::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)