From 808630ecf498437766eea45b8dc5e8f243d76337 Mon Sep 17 00:00:00 2001 From: Matt Kuruc Date: Wed, 18 Jan 2023 10:40:12 -0800 Subject: [PATCH] Replace boost hash usage with TfHash in pxr/base/gf --- pxr/base/gf/bbox3d.h | 8 +++--- pxr/base/gf/dualQuat.template.h | 8 ++---- pxr/base/gf/dualQuatd.h | 8 ++---- pxr/base/gf/dualQuatf.h | 8 ++---- pxr/base/gf/dualQuath.h | 8 ++---- pxr/base/gf/frustum.h | 19 +++++++-------- pxr/base/gf/interval.h | 15 +++--------- pxr/base/gf/matrix.template.h | 12 +++------ pxr/base/gf/matrix2d.h | 15 ++++++------ pxr/base/gf/matrix2f.h | 15 ++++++------ pxr/base/gf/matrix3d.h | 20 +++++++++------ pxr/base/gf/matrix3f.h | 20 +++++++++------ pxr/base/gf/matrix4d.h | 27 +++++++++++++++------ pxr/base/gf/matrix4f.h | 27 +++++++++++++++------ pxr/base/gf/multiInterval.cpp | 5 +--- pxr/base/gf/quat.template.h | 7 ++---- pxr/base/gf/quatd.h | 7 ++---- pxr/base/gf/quaternion.h | 8 ++---- pxr/base/gf/quatf.h | 7 ++---- pxr/base/gf/quath.h | 7 ++---- pxr/base/gf/range.template.h | 8 ++---- pxr/base/gf/range1d.h | 8 ++---- pxr/base/gf/range1f.h | 8 ++---- pxr/base/gf/range2d.h | 8 ++---- pxr/base/gf/range2f.h | 8 ++---- pxr/base/gf/range3d.h | 8 ++---- pxr/base/gf/range3f.h | 8 ++---- pxr/base/gf/rect2i.h | 8 ++---- pxr/base/gf/rotation.h | 8 ++---- pxr/base/gf/testenv/testGfBBox3d.py | 9 +++++++ pxr/base/gf/testenv/testGfDualQuaternion.py | 9 +++++++ pxr/base/gf/testenv/testGfFrustum.py | 14 ++++++++++- pxr/base/gf/testenv/testGfInterval.py | 6 +++++ pxr/base/gf/testenv/testGfMatrix.py | 15 ++++++++++++ pxr/base/gf/testenv/testGfQuaternion.py | 6 +++++ pxr/base/gf/testenv/testGfRange.py | 9 +++++++ pxr/base/gf/testenv/testGfRect2i.py | 9 +++++++ pxr/base/gf/testenv/testGfRotation.py | 5 ++++ pxr/base/gf/testenv/testGfVec.py | 7 ++++++ pxr/base/gf/vec.template.h | 7 ++---- pxr/base/gf/vec2d.h | 8 ++---- pxr/base/gf/vec2f.h | 8 ++---- pxr/base/gf/vec2h.h | 8 ++---- pxr/base/gf/vec2i.h | 8 ++---- pxr/base/gf/vec3d.h | 9 ++----- pxr/base/gf/vec3f.h | 9 ++----- pxr/base/gf/vec3h.h | 9 ++----- pxr/base/gf/vec3i.h | 9 ++----- pxr/base/gf/vec4d.h | 10 ++------ pxr/base/gf/vec4f.h | 10 ++------ pxr/base/gf/vec4h.h | 10 ++------ pxr/base/gf/vec4i.h | 10 ++------ pxr/base/gf/wrapBBox3d.cpp | 5 ++++ pxr/base/gf/wrapFrustum.cpp | 5 ++++ pxr/base/gf/wrapInterval.cpp | 1 + pxr/base/gf/wrapQuat.template.cpp | 6 ++++- pxr/base/gf/wrapQuatd.cpp | 6 ++++- pxr/base/gf/wrapQuaternion.cpp | 2 ++ pxr/base/gf/wrapQuatf.cpp | 6 ++++- pxr/base/gf/wrapQuath.cpp | 6 ++++- pxr/base/gf/wrapRect2i.cpp | 6 ++++- pxr/base/gf/wrapRotation.cpp | 8 +++++- 62 files changed, 293 insertions(+), 285 deletions(-) diff --git a/pxr/base/gf/bbox3d.h b/pxr/base/gf/bbox3d.h index 5ebe6d20a4..8e42acbde3 100644 --- a/pxr/base/gf/bbox3d.h +++ b/pxr/base/gf/bbox3d.h @@ -210,10 +210,10 @@ class GfBBox3d { /// Hash. friend inline size_t hash_value(const GfBBox3d &b) { - size_t h = 0; - boost::hash_combine(h, b._box); - boost::hash_combine(h, b._matrix); - return h; + return TfHash::Combine( + b._box, + b._matrix + ); } /// Component-wise equality test. The axis-aligned boxes and diff --git a/pxr/base/gf/dualQuat.template.h b/pxr/base/gf/dualQuat.template.h index 1bb0f39220..9e4976bc6f 100644 --- a/pxr/base/gf/dualQuat.template.h +++ b/pxr/base/gf/dualQuat.template.h @@ -40,8 +40,7 @@ {% endif %} #include "pxr/base/gf/quat{{ SUFFIX }}.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -175,10 +174,7 @@ class {{ DUALQUAT }} final /// Hash. friend inline size_t hash_value(const {{ DUALQUAT }} &dq) { - size_t h = 0; - boost::hash_combine(h, dq.GetReal()); - boost::hash_combine(h, dq.GetDual()); - return h; + return TfHash::Combine(dq.GetReal(), dq.GetDual()); } /// Component-wise dual quaternion equality test. The real and dual parts diff --git a/pxr/base/gf/dualQuatd.h b/pxr/base/gf/dualQuatd.h index 0d6a06d80d..274a57cdfb 100644 --- a/pxr/base/gf/dualQuatd.h +++ b/pxr/base/gf/dualQuatd.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/traits.h" #include "pxr/base/gf/quatd.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -173,10 +172,7 @@ class GfDualQuatd final /// Hash. friend inline size_t hash_value(const GfDualQuatd &dq) { - size_t h = 0; - boost::hash_combine(h, dq.GetReal()); - boost::hash_combine(h, dq.GetDual()); - return h; + return TfHash::Combine(dq.GetReal(), dq.GetDual()); } /// Component-wise dual quaternion equality test. The real and dual parts diff --git a/pxr/base/gf/dualQuatf.h b/pxr/base/gf/dualQuatf.h index cefa8412c4..d4002704ac 100644 --- a/pxr/base/gf/dualQuatf.h +++ b/pxr/base/gf/dualQuatf.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/traits.h" #include "pxr/base/gf/quatf.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -173,10 +172,7 @@ class GfDualQuatf final /// Hash. friend inline size_t hash_value(const GfDualQuatf &dq) { - size_t h = 0; - boost::hash_combine(h, dq.GetReal()); - boost::hash_combine(h, dq.GetDual()); - return h; + return TfHash::Combine(dq.GetReal(), dq.GetDual()); } /// Component-wise dual quaternion equality test. The real and dual parts diff --git a/pxr/base/gf/dualQuath.h b/pxr/base/gf/dualQuath.h index 53f3b09c7c..4ddfc4e5c7 100644 --- a/pxr/base/gf/dualQuath.h +++ b/pxr/base/gf/dualQuath.h @@ -38,8 +38,7 @@ #include "pxr/base/gf/half.h" #include "pxr/base/gf/quath.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -174,10 +173,7 @@ class GfDualQuath final /// Hash. friend inline size_t hash_value(const GfDualQuath &dq) { - size_t h = 0; - boost::hash_combine(h, dq.GetReal()); - boost::hash_combine(h, dq.GetDual()); - return h; + return TfHash::Combine(dq.GetReal(), dq.GetDual()); } /// Component-wise dual quaternion equality test. The real and dual parts diff --git a/pxr/base/gf/frustum.h b/pxr/base/gf/frustum.h index 551be1bb22..1aaada2308 100644 --- a/pxr/base/gf/frustum.h +++ b/pxr/base/gf/frustum.h @@ -38,8 +38,7 @@ #include "pxr/base/gf/vec2d.h" #include "pxr/base/gf/vec3d.h" #include "pxr/base/gf/api.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -190,14 +189,14 @@ class GfFrustum { } friend inline size_t hash_value(const GfFrustum &f) { - size_t h = 0; - boost::hash_combine(h, f._position); - boost::hash_combine(h, f._rotation); - boost::hash_combine(h, f._window); - boost::hash_combine(h, f._nearFar); - boost::hash_combine(h, f._viewDistance); - boost::hash_combine(h, f._projectionType); - return h; + return TfHash::Combine( + f._position, + f._rotation, + f._window, + f._nearFar, + f._viewDistance, + f._projectionType + ); } // Equality operator. true iff all parts match. diff --git a/pxr/base/gf/interval.h b/pxr/base/gf/interval.h index 5cbafdbf6d..bf1688b03d 100644 --- a/pxr/base/gf/interval.h +++ b/pxr/base/gf/interval.h @@ -29,9 +29,8 @@ #include "pxr/pxr.h" #include "pxr/base/gf/math.h" -#include "pxr/base/gf/api.h" - -#include +#include "pxr/base/gf/api.h" +#include "pxr/base/tf/hash.h" #include #include @@ -103,10 +102,7 @@ class GfInterval size_t Hash() const { return hash_value(*this); } friend inline size_t hash_value(GfInterval const &i) { - size_t h = 0; - boost::hash_combine(h, i._min); - boost::hash_combine(h, i._max); - return h; + return TfHash::Combine(i._min, i._max); } /// Minimum value @@ -391,10 +387,7 @@ class GfInterval return _Bound( value * rhs.value, closed & rhs.closed ); } friend inline size_t hash_value(const _Bound &b) { - size_t h = 0; - boost::hash_combine(h, b.value); - boost::hash_combine(h, b.closed); - return h; + return TfHash::Combine(b.value, b.closed); } }; diff --git a/pxr/base/gf/matrix.template.h b/pxr/base/gf/matrix.template.h index bd53b3c657..b01ffec463 100644 --- a/pxr/base/gf/matrix.template.h +++ b/pxr/base/gf/matrix.template.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/traits.h" {% block includes %} {% endblock %} - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -218,12 +217,9 @@ class {{ MAT }} /// Hash. friend inline size_t hash_value({{ MAT }} const &m) { - int nElems = {{ DIM }} * {{ DIM }}; - size_t h = 0; - const {{ SCL }} *p = m.GetArray(); - while (nElems--) - boost::hash_combine(h, *p++); - return h; + return TfHash::Combine( + {{ MATRIX("m._mtx[%(i)s][%(j)s]", sep=',\n ') }} + ); } /// Tests for element-wise matrix equality. All elements must match diff --git a/pxr/base/gf/matrix2d.h b/pxr/base/gf/matrix2d.h index a79c7f8d6e..a58de681b0 100644 --- a/pxr/base/gf/matrix2d.h +++ b/pxr/base/gf/matrix2d.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/matrixData.h" #include "pxr/base/gf/vec2d.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -224,12 +223,12 @@ class GfMatrix2d /// Hash. friend inline size_t hash_value(GfMatrix2d const &m) { - int nElems = 2 * 2; - size_t h = 0; - const double *p = m.GetArray(); - while (nElems--) - boost::hash_combine(h, *p++); - return h; + return TfHash::Combine( + m._mtx[0][0], + m._mtx[0][1], + m._mtx[1][0], + m._mtx[1][1] + ); } /// Tests for element-wise matrix equality. All elements must match diff --git a/pxr/base/gf/matrix2f.h b/pxr/base/gf/matrix2f.h index 8b4e3edf48..8bab33c4b2 100644 --- a/pxr/base/gf/matrix2f.h +++ b/pxr/base/gf/matrix2f.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/matrixData.h" #include "pxr/base/gf/vec2f.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -224,12 +223,12 @@ class GfMatrix2f /// Hash. friend inline size_t hash_value(GfMatrix2f const &m) { - int nElems = 2 * 2; - size_t h = 0; - const float *p = m.GetArray(); - while (nElems--) - boost::hash_combine(h, *p++); - return h; + return TfHash::Combine( + m._mtx[0][0], + m._mtx[0][1], + m._mtx[1][0], + m._mtx[1][1] + ); } /// Tests for element-wise matrix equality. All elements must match diff --git a/pxr/base/gf/matrix3d.h b/pxr/base/gf/matrix3d.h index 4244649432..e8e8d207b4 100644 --- a/pxr/base/gf/matrix3d.h +++ b/pxr/base/gf/matrix3d.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/matrixData.h" #include "pxr/base/gf/vec3d.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -263,12 +262,17 @@ class GfMatrix3d /// Hash. friend inline size_t hash_value(GfMatrix3d const &m) { - int nElems = 3 * 3; - size_t h = 0; - const double *p = m.GetArray(); - while (nElems--) - boost::hash_combine(h, *p++); - return h; + return TfHash::Combine( + m._mtx[0][0], + m._mtx[0][1], + m._mtx[0][2], + m._mtx[1][0], + m._mtx[1][1], + m._mtx[1][2], + m._mtx[2][0], + m._mtx[2][1], + m._mtx[2][2] + ); } /// Tests for element-wise matrix equality. All elements must match diff --git a/pxr/base/gf/matrix3f.h b/pxr/base/gf/matrix3f.h index 835646f554..29c69f4927 100644 --- a/pxr/base/gf/matrix3f.h +++ b/pxr/base/gf/matrix3f.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/matrixData.h" #include "pxr/base/gf/vec3f.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -263,12 +262,17 @@ class GfMatrix3f /// Hash. friend inline size_t hash_value(GfMatrix3f const &m) { - int nElems = 3 * 3; - size_t h = 0; - const float *p = m.GetArray(); - while (nElems--) - boost::hash_combine(h, *p++); - return h; + return TfHash::Combine( + m._mtx[0][0], + m._mtx[0][1], + m._mtx[0][2], + m._mtx[1][0], + m._mtx[1][1], + m._mtx[1][2], + m._mtx[2][0], + m._mtx[2][1], + m._mtx[2][2] + ); } /// Tests for element-wise matrix equality. All elements must match diff --git a/pxr/base/gf/matrix4d.h b/pxr/base/gf/matrix4d.h index 905084096f..9108e5b296 100644 --- a/pxr/base/gf/matrix4d.h +++ b/pxr/base/gf/matrix4d.h @@ -41,8 +41,7 @@ #include "pxr/base/gf/limits.h" #include "pxr/base/gf/math.h" #include "pxr/base/gf/vec3d.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -303,12 +302,24 @@ class GfMatrix4d /// Hash. friend inline size_t hash_value(GfMatrix4d const &m) { - int nElems = 4 * 4; - size_t h = 0; - const double *p = m.GetArray(); - while (nElems--) - boost::hash_combine(h, *p++); - return h; + return TfHash::Combine( + m._mtx[0][0], + m._mtx[0][1], + m._mtx[0][2], + m._mtx[0][3], + m._mtx[1][0], + m._mtx[1][1], + m._mtx[1][2], + m._mtx[1][3], + m._mtx[2][0], + m._mtx[2][1], + m._mtx[2][2], + m._mtx[2][3], + m._mtx[3][0], + m._mtx[3][1], + m._mtx[3][2], + m._mtx[3][3] + ); } /// Tests for element-wise matrix equality. All elements must match diff --git a/pxr/base/gf/matrix4f.h b/pxr/base/gf/matrix4f.h index 2c9610a539..9e2c65c3ae 100644 --- a/pxr/base/gf/matrix4f.h +++ b/pxr/base/gf/matrix4f.h @@ -41,8 +41,7 @@ #include "pxr/base/gf/limits.h" #include "pxr/base/gf/math.h" #include "pxr/base/gf/vec3f.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -303,12 +302,24 @@ class GfMatrix4f /// Hash. friend inline size_t hash_value(GfMatrix4f const &m) { - int nElems = 4 * 4; - size_t h = 0; - const float *p = m.GetArray(); - while (nElems--) - boost::hash_combine(h, *p++); - return h; + return TfHash::Combine( + m._mtx[0][0], + m._mtx[0][1], + m._mtx[0][2], + m._mtx[0][3], + m._mtx[1][0], + m._mtx[1][1], + m._mtx[1][2], + m._mtx[1][3], + m._mtx[2][0], + m._mtx[2][1], + m._mtx[2][2], + m._mtx[2][3], + m._mtx[3][0], + m._mtx[3][1], + m._mtx[3][2], + m._mtx[3][3] + ); } /// Tests for element-wise matrix equality. All elements must match diff --git a/pxr/base/gf/multiInterval.cpp b/pxr/base/gf/multiInterval.cpp index e02a7837e3..f6214e7caf 100644 --- a/pxr/base/gf/multiInterval.cpp +++ b/pxr/base/gf/multiInterval.cpp @@ -52,10 +52,7 @@ GfMultiInterval::GfMultiInterval(const std::vector &intervals) size_t GfMultiInterval::Hash() const { - size_t h = 0; - for (auto const &i: _set) - boost::hash_combine(h, i); - return h; + return TfHash()(_set); } GfInterval diff --git a/pxr/base/gf/quat.template.h b/pxr/base/gf/quat.template.h index e6847e9ac4..658e53697a 100644 --- a/pxr/base/gf/quat.template.h +++ b/pxr/base/gf/quat.template.h @@ -39,8 +39,7 @@ {% if SCL == 'GfHalf' -%} #include "pxr/base/gf/half.h" {% endif %} - -#include +#include "pxr/base/tf/hash.h" #include @@ -165,9 +164,7 @@ class {{ QUAT }} /// Hash. friend inline size_t hash_value(const {{ QUAT }} &q) { - size_t h = boost::hash()(q.GetReal()); - boost::hash_combine(h, q.GetImaginary()); - return h; + return TfHash::Combine(q.GetReal(), q.GetImaginary()); } /// Component-wise negation. diff --git a/pxr/base/gf/quatd.h b/pxr/base/gf/quatd.h index 1246df7afd..b28e0444fc 100644 --- a/pxr/base/gf/quatd.h +++ b/pxr/base/gf/quatd.h @@ -36,8 +36,7 @@ #include "pxr/base/gf/declare.h" #include "pxr/base/gf/vec3d.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -163,9 +162,7 @@ class GfQuatd /// Hash. friend inline size_t hash_value(const GfQuatd &q) { - size_t h = boost::hash()(q.GetReal()); - boost::hash_combine(h, q.GetImaginary()); - return h; + return TfHash::Combine(q.GetReal(), q.GetImaginary()); } /// Component-wise negation. diff --git a/pxr/base/gf/quaternion.h b/pxr/base/gf/quaternion.h index ac103739c0..01fa3a9d29 100644 --- a/pxr/base/gf/quaternion.h +++ b/pxr/base/gf/quaternion.h @@ -30,8 +30,7 @@ #include "pxr/pxr.h" #include "pxr/base/gf/api.h" #include "pxr/base/gf/vec3d.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -125,10 +124,7 @@ class GfQuaternion /// Hash. friend inline size_t hash_value(const GfQuaternion &q) { - size_t h = 0; - boost::hash_combine(h, q.GetReal()); - boost::hash_combine(h, q.GetImaginary()); - return h; + return TfHash::Combine(q.GetReal(), q.GetImaginary()); } /// Component-wise quaternion equality test. The real and imaginary parts diff --git a/pxr/base/gf/quatf.h b/pxr/base/gf/quatf.h index 45def9d446..1042be388a 100644 --- a/pxr/base/gf/quatf.h +++ b/pxr/base/gf/quatf.h @@ -36,8 +36,7 @@ #include "pxr/base/gf/declare.h" #include "pxr/base/gf/vec3f.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -163,9 +162,7 @@ class GfQuatf /// Hash. friend inline size_t hash_value(const GfQuatf &q) { - size_t h = boost::hash()(q.GetReal()); - boost::hash_combine(h, q.GetImaginary()); - return h; + return TfHash::Combine(q.GetReal(), q.GetImaginary()); } /// Component-wise negation. diff --git a/pxr/base/gf/quath.h b/pxr/base/gf/quath.h index 9767591dad..6addda91c9 100644 --- a/pxr/base/gf/quath.h +++ b/pxr/base/gf/quath.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/vec3h.h" #include "pxr/base/gf/traits.h" #include "pxr/base/gf/half.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -164,9 +163,7 @@ class GfQuath /// Hash. friend inline size_t hash_value(const GfQuath &q) { - size_t h = boost::hash()(q.GetReal()); - boost::hash_combine(h, q.GetImaginary()); - return h; + return TfHash::Combine(q.GetReal(), q.GetImaginary()); } /// Component-wise negation. diff --git a/pxr/base/gf/range.template.h b/pxr/base/gf/range.template.h index ec69bf3362..8f1adaef42 100644 --- a/pxr/base/gf/range.template.h +++ b/pxr/base/gf/range.template.h @@ -39,8 +39,7 @@ #include "pxr/base/gf/vec{{ DIM }}f.h" {% endif %} #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -324,10 +323,7 @@ class {{ RNG }} /// hash. friend inline size_t hash_value(const {{ RNG }} &r) { - size_t h = 0; - boost::hash_combine(h, r._min); - boost::hash_combine(h, r._max); - return h; + return TfHash::Combine(r._min, r._max); } /// The min and max points must match exactly for equality. diff --git a/pxr/base/gf/range1d.h b/pxr/base/gf/range1d.h index 614f9c5378..d80fddaca2 100644 --- a/pxr/base/gf/range1d.h +++ b/pxr/base/gf/range1d.h @@ -35,8 +35,7 @@ #include "pxr/base/gf/api.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -296,10 +295,7 @@ class GfRange1d /// hash. friend inline size_t hash_value(const GfRange1d &r) { - size_t h = 0; - boost::hash_combine(h, r._min); - boost::hash_combine(h, r._max); - return h; + return TfHash::Combine(r._min, r._max); } /// The min and max points must match exactly for equality. diff --git a/pxr/base/gf/range1f.h b/pxr/base/gf/range1f.h index 9fc245281b..007c405df3 100644 --- a/pxr/base/gf/range1f.h +++ b/pxr/base/gf/range1f.h @@ -35,8 +35,7 @@ #include "pxr/base/gf/api.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -296,10 +295,7 @@ class GfRange1f /// hash. friend inline size_t hash_value(const GfRange1f &r) { - size_t h = 0; - boost::hash_combine(h, r._min); - boost::hash_combine(h, r._max); - return h; + return TfHash::Combine(r._min, r._max); } /// The min and max points must match exactly for equality. diff --git a/pxr/base/gf/range2d.h b/pxr/base/gf/range2d.h index 2c71573d35..cd6f6899c9 100644 --- a/pxr/base/gf/range2d.h +++ b/pxr/base/gf/range2d.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/vec2d.h" #include "pxr/base/gf/vec2f.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -300,10 +299,7 @@ class GfRange2d /// hash. friend inline size_t hash_value(const GfRange2d &r) { - size_t h = 0; - boost::hash_combine(h, r._min); - boost::hash_combine(h, r._max); - return h; + return TfHash::Combine(r._min, r._max); } /// The min and max points must match exactly for equality. diff --git a/pxr/base/gf/range2f.h b/pxr/base/gf/range2f.h index b5d981c1d2..dc8326b0b7 100644 --- a/pxr/base/gf/range2f.h +++ b/pxr/base/gf/range2f.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/vec2d.h" #include "pxr/base/gf/vec2f.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -300,10 +299,7 @@ class GfRange2f /// hash. friend inline size_t hash_value(const GfRange2f &r) { - size_t h = 0; - boost::hash_combine(h, r._min); - boost::hash_combine(h, r._max); - return h; + return TfHash::Combine(r._min, r._max); } /// The min and max points must match exactly for equality. diff --git a/pxr/base/gf/range3d.h b/pxr/base/gf/range3d.h index 8d4cc3a7a8..9c0fa55d98 100644 --- a/pxr/base/gf/range3d.h +++ b/pxr/base/gf/range3d.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/vec3d.h" #include "pxr/base/gf/vec3f.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -302,10 +301,7 @@ class GfRange3d /// hash. friend inline size_t hash_value(const GfRange3d &r) { - size_t h = 0; - boost::hash_combine(h, r._min); - boost::hash_combine(h, r._max); - return h; + return TfHash::Combine(r._min, r._max); } /// The min and max points must match exactly for equality. diff --git a/pxr/base/gf/range3f.h b/pxr/base/gf/range3f.h index d29b227a29..6a206f610b 100644 --- a/pxr/base/gf/range3f.h +++ b/pxr/base/gf/range3f.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/vec3d.h" #include "pxr/base/gf/vec3f.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -302,10 +301,7 @@ class GfRange3f /// hash. friend inline size_t hash_value(const GfRange3f &r) { - size_t h = 0; - boost::hash_combine(h, r._min); - boost::hash_combine(h, r._max); - return h; + return TfHash::Combine(r._min, r._max); } /// The min and max points must match exactly for equality. diff --git a/pxr/base/gf/rect2i.h b/pxr/base/gf/rect2i.h index 592d687641..2bcfa5efeb 100644 --- a/pxr/base/gf/rect2i.h +++ b/pxr/base/gf/rect2i.h @@ -31,8 +31,7 @@ #include "pxr/base/gf/math.h" #include "pxr/base/gf/vec2i.h" #include "pxr/base/gf/api.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -267,10 +266,7 @@ class GfRect2i { } friend inline size_t hash_value(const GfRect2i &r) { - size_t h = 0; - boost::hash_combine(h, r._min); - boost::hash_combine(h, r._max); - return h; + return TfHash::Combine(r._min, r._max); } /// Returns true if \p r1 and \p r2 are equal. diff --git a/pxr/base/gf/rotation.h b/pxr/base/gf/rotation.h index b35d38062e..de9204b9c9 100644 --- a/pxr/base/gf/rotation.h +++ b/pxr/base/gf/rotation.h @@ -34,8 +34,7 @@ #include "pxr/base/gf/vec3d.h" #include "pxr/base/gf/vec3f.h" #include "pxr/base/gf/api.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -221,10 +220,7 @@ class GfRotation { /// Hash. friend inline size_t hash_value(const GfRotation &r) { - size_t h = 0; - boost::hash_combine(h, r._axis); - boost::hash_combine(h, r._angle); - return h; + return TfHash::Combine(r._axis, r._angle); } /// Component-wise rotation equality test. The axes and angles must match diff --git a/pxr/base/gf/testenv/testGfBBox3d.py b/pxr/base/gf/testenv/testGfBBox3d.py index 31a7dcd523..7a56d2fc76 100644 --- a/pxr/base/gf/testenv/testGfBBox3d.py +++ b/pxr/base/gf/testenv/testGfBBox3d.py @@ -170,6 +170,15 @@ def test_MethodsAndProperties(self): self.assertEqual(b4, eval(repr(b4))) + def test_Hash(self): + b = Gf.BBox3d( + Gf.Range3d((-1, -2, -3), (2, 3, 4)), + Gf.Matrix4d(1.0) + ) + + self.assertEqual(hash(b), hash(b)) + self.assertEqual(hash(b), hash(Gf.BBox3d(b))) + if __name__ == '__main__': unittest.main() diff --git a/pxr/base/gf/testenv/testGfDualQuaternion.py b/pxr/base/gf/testenv/testGfDualQuaternion.py index c6a543fdff..4b4f19827c 100644 --- a/pxr/base/gf/testenv/testGfDualQuaternion.py +++ b/pxr/base/gf/testenv/testGfDualQuaternion.py @@ -208,5 +208,14 @@ def test_Operators(self): Gf.IsClose(dq.Transform(vec3Type(0,1,0)), vec3Type(-0.4,-0.333333,-0.133333), closeVal) and Gf.IsClose(dq.Transform(vec3Type(0,0,1)), vec3Type(0.2,0.666667,-0.933333), closeVal)) + def test_Hash(self): + for DualQuatType, QuatType, Vec3Type, _ in testClasses: + dq = DualQuatType( + QuatType(1.0, Vec3Type(2.0, 3.0, 4.0)), + QuatType(2.0, Vec3Type(3.0, 4.0, 5.0)) + ) + self.assertEqual(hash(dq), hash(dq)) + self.assertEqual(hash(dq), hash(DualQuatType(dq))) + if __name__ == '__main__': unittest.main() diff --git a/pxr/base/gf/testenv/testGfFrustum.py b/pxr/base/gf/testenv/testGfFrustum.py index 311a40dfbb..2a49843908 100644 --- a/pxr/base/gf/testenv/testGfFrustum.py +++ b/pxr/base/gf/testenv/testGfFrustum.py @@ -408,7 +408,19 @@ def test_ConstructFromMatrix(self): self.assertTrue( Gf.IsClose(corners[i], (results[i] + results[i+4]) / 2.0, 0.0001)) - + + def test_Hash(self): + frustum = Gf.Frustum( + Gf.Vec3d(1.0, 2.0, 3.0), + Gf.Rotation(Gf.Vec3d(1.0, 0.0, 0.0), 90.0), + Gf.Range2d(Gf.Vec2d(-0.5, 0.5), Gf.Vec2d(-1.0, 1.0)), + Gf.Range1d(1.0, 1000.0), + Gf.Frustum.Perspective, + 10.0 + ) + + self.assertEqual(hash(frustum), hash(frustum)) + self.assertEqual(hash(frustum), hash(Gf.Frustum(frustum))) if __name__ == '__main__': unittest.main() diff --git a/pxr/base/gf/testenv/testGfInterval.py b/pxr/base/gf/testenv/testGfInterval.py index 2c0f1c3216..dedb4d7367 100644 --- a/pxr/base/gf/testenv/testGfInterval.py +++ b/pxr/base/gf/testenv/testGfInterval.py @@ -269,5 +269,11 @@ def runTest(self): self.assertTrue(len(str(Gf.Interval())), ("str")) + def test_Hash(self): + interval = Gf.Interval(-1.5, 2.0, True, False) + self.assertEqual(hash(interval), hash(interval)) + self.assertEqual(hash(interval), hash(Gf.Interval(interval))) + + if __name__ == '__main__': unittest.main() diff --git a/pxr/base/gf/testenv/testGfMatrix.py b/pxr/base/gf/testenv/testGfMatrix.py index 90d8efacbd..3d94941c32 100644 --- a/pxr/base/gf/testenv/testGfMatrix.py +++ b/pxr/base/gf/testenv/testGfMatrix.py @@ -816,5 +816,20 @@ def test_Exceptions(self): with self.assertRaises(excType): int(Gf.Matrix3f(3)) + def test_Hash(self): + MatrixTypes = [ + Gf.Matrix2d, + Gf.Matrix2f, + Gf.Matrix3d, + Gf.Matrix3f, + Gf.Matrix4d, + Gf.Matrix4f + ] + + for MatrixType in MatrixTypes: + m = MatrixType(*(i * 2.0 for i in range(1, 1 + MatrixType.dimension[0] * MatrixType.dimension[1]))) + self.assertEqual(hash(m), hash(m)) + self.assertEqual(hash(m), hash(MatrixType(m))) + if __name__ == '__main__': unittest.main() diff --git a/pxr/base/gf/testenv/testGfQuaternion.py b/pxr/base/gf/testenv/testGfQuaternion.py index 206e2ffed2..20f9cc0fc7 100644 --- a/pxr/base/gf/testenv/testGfQuaternion.py +++ b/pxr/base/gf/testenv/testGfQuaternion.py @@ -225,5 +225,11 @@ def test_Operators(self): self.assertTrue(Gf.IsClose(r1, vec3Type(0.0, 1.0, 0.0), closeVal) and Gf.IsClose(r1, r2, closeVal)) + def test_Hash(self): + for QuatType, Vec3Type, _ in testClasses: + q = QuatType(1.0, Vec3Type(2.0, 3.0, 4.0)) + self.assertEqual(hash(q), hash(q)) + self.assertEqual(hash(q), hash(QuatType(q))) + if __name__ == '__main__': unittest.main() diff --git a/pxr/base/gf/testenv/testGfRange.py b/pxr/base/gf/testenv/testGfRange.py index 8c49ac72c5..17748d9b77 100644 --- a/pxr/base/gf/testenv/testGfRange.py +++ b/pxr/base/gf/testenv/testGfRange.py @@ -328,5 +328,14 @@ def runTest(self): # Construct float from double type self.assertEqual(Rangef(r1d), r1f) + def test_Hash(self): + for RangeType, ValueType in self.Ranges: + r = RangeType( + makeValue(ValueType, [-1.0, -2.0, -3.0, -4.0]), + makeValue(ValueType, [4.0, 3.0, 2.0, 1.0]) + ) + self.assertEqual(hash(r), hash(r)) + self.assertEqual(hash(r), hash(RangeType(r))) + if __name__ == '__main__': unittest.main() diff --git a/pxr/base/gf/testenv/testGfRect2i.py b/pxr/base/gf/testenv/testGfRect2i.py index 3ac45fe954..18fd9cbbf8 100644 --- a/pxr/base/gf/testenv/testGfRect2i.py +++ b/pxr/base/gf/testenv/testGfRect2i.py @@ -112,5 +112,14 @@ def test_Properties(self): self.assertTrue(len(str(Gf.Rect2i()))) + def test_Hash(self): + r = Gf.Rect2i( + Gf.Vec2i(1, 2), + Gf.Vec2i(10, 20) + ) + + self.assertEqual(hash(r), hash(r)) + self.assertEqual(hash(r), hash(Gf.Rect2i(r))) + if __name__ == '__main__': unittest.main() diff --git a/pxr/base/gf/testenv/testGfRotation.py b/pxr/base/gf/testenv/testGfRotation.py index 5919ab1b71..4f5509783d 100644 --- a/pxr/base/gf/testenv/testGfRotation.py +++ b/pxr/base/gf/testenv/testGfRotation.py @@ -205,5 +205,10 @@ def test_RotateOntoProjected(self): self.assertTrue(Gf.IsClose(rot.angle, -1.91983, 0.00001)) self.assertEqual(rot.axis, axis.GetNormalized()) + def test_Hash(self): + rot = Gf.Rotation(Gf.Vec3d(1.0, 0.0, 0.0), 40.0) + self.assertEqual(hash(rot), hash(rot)) + self.assertEqual(hash(rot), hash(Gf.Rotation(rot))) + if __name__ == '__main__': unittest.main() diff --git a/pxr/base/gf/testenv/testGfVec.py b/pxr/base/gf/testenv/testGfVec.py index 9425c24c42..09d6630703 100644 --- a/pxr/base/gf/testenv/testGfVec.py +++ b/pxr/base/gf/testenv/testGfVec.py @@ -287,6 +287,12 @@ def OperatorsTest(self, Vec): # v[:2] = [None, None] + def HashTest(self, Vec): + v1 = Vec() + SetVec(v1, [12, 1, 2, -4]) + self.assertEqual(hash(v1), hash(v1)) + self.assertEqual(hash(v1), hash(Vec(v1))) + def MethodsTest(self, Vec): v1 = Vec() v2 = Vec() @@ -544,6 +550,7 @@ def test_Types(self): self.ConstructorsTest( Vec ) self.OperatorsTest( Vec ) self.MethodsTest( Vec ) + self.HashTest( Vec ) def test_TupleToVec(self): diff --git a/pxr/base/gf/vec.template.h b/pxr/base/gf/vec.template.h index 596bd68489..10361af854 100644 --- a/pxr/base/gf/vec.template.h +++ b/pxr/base/gf/vec.template.h @@ -42,8 +42,7 @@ #include "pxr/base/gf/half.h" {% endif %} {% endif %} - -#include +#include "pxr/base/tf/hash.h" #include {% if IS_FLOATING_POINT(SCL) -%} @@ -143,9 +142,7 @@ class {{ VEC }} /// Hash. friend inline size_t hash_value({{ VEC }} const &vec) { - size_t h = 0; - {{ LIST("boost::hash_combine(h, vec[%(i)s]);", sep='\n ') }} - return h; + return TfHash::Combine({{ LIST("vec[%(i)s]", sep=', ') }}); } /// Equality comparison. diff --git a/pxr/base/gf/vec2d.h b/pxr/base/gf/vec2d.h index 191a1fce2f..bb28425257 100644 --- a/pxr/base/gf/vec2d.h +++ b/pxr/base/gf/vec2d.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/limits.h" #include "pxr/base/gf/traits.h" #include "pxr/base/gf/math.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -143,10 +142,7 @@ class GfVec2d /// Hash. friend inline size_t hash_value(GfVec2d const &vec) { - size_t h = 0; - boost::hash_combine(h, vec[0]); - boost::hash_combine(h, vec[1]); - return h; + return TfHash::Combine(vec[0], vec[1]); } /// Equality comparison. diff --git a/pxr/base/gf/vec2f.h b/pxr/base/gf/vec2f.h index d22277be66..e3c46ebc1e 100644 --- a/pxr/base/gf/vec2f.h +++ b/pxr/base/gf/vec2f.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/limits.h" #include "pxr/base/gf/traits.h" #include "pxr/base/gf/math.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -143,10 +142,7 @@ class GfVec2f /// Hash. friend inline size_t hash_value(GfVec2f const &vec) { - size_t h = 0; - boost::hash_combine(h, vec[0]); - boost::hash_combine(h, vec[1]); - return h; + return TfHash::Combine(vec[0], vec[1]); } /// Equality comparison. diff --git a/pxr/base/gf/vec2h.h b/pxr/base/gf/vec2h.h index ff813f9164..fd284f5c9d 100644 --- a/pxr/base/gf/vec2h.h +++ b/pxr/base/gf/vec2h.h @@ -38,8 +38,7 @@ #include "pxr/base/gf/traits.h" #include "pxr/base/gf/math.h" #include "pxr/base/gf/half.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -144,10 +143,7 @@ class GfVec2h /// Hash. friend inline size_t hash_value(GfVec2h const &vec) { - size_t h = 0; - boost::hash_combine(h, vec[0]); - boost::hash_combine(h, vec[1]); - return h; + return TfHash::Combine(vec[0], vec[1]); } /// Equality comparison. diff --git a/pxr/base/gf/vec2i.h b/pxr/base/gf/vec2i.h index 1580f8bfab..8f4e22bf1d 100644 --- a/pxr/base/gf/vec2i.h +++ b/pxr/base/gf/vec2i.h @@ -36,8 +36,7 @@ #include "pxr/base/gf/api.h" #include "pxr/base/gf/limits.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -132,10 +131,7 @@ class GfVec2i /// Hash. friend inline size_t hash_value(GfVec2i const &vec) { - size_t h = 0; - boost::hash_combine(h, vec[0]); - boost::hash_combine(h, vec[1]); - return h; + return TfHash::Combine(vec[0], vec[1]); } /// Equality comparison. diff --git a/pxr/base/gf/vec3d.h b/pxr/base/gf/vec3d.h index e71266c210..ffcf0222b8 100644 --- a/pxr/base/gf/vec3d.h +++ b/pxr/base/gf/vec3d.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/limits.h" #include "pxr/base/gf/traits.h" #include "pxr/base/gf/math.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -150,11 +149,7 @@ class GfVec3d /// Hash. friend inline size_t hash_value(GfVec3d const &vec) { - size_t h = 0; - boost::hash_combine(h, vec[0]); - boost::hash_combine(h, vec[1]); - boost::hash_combine(h, vec[2]); - return h; + return TfHash::Combine(vec[0], vec[1], vec[2]); } /// Equality comparison. diff --git a/pxr/base/gf/vec3f.h b/pxr/base/gf/vec3f.h index 0a6ae625ec..c216ce8eba 100644 --- a/pxr/base/gf/vec3f.h +++ b/pxr/base/gf/vec3f.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/limits.h" #include "pxr/base/gf/traits.h" #include "pxr/base/gf/math.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -150,11 +149,7 @@ class GfVec3f /// Hash. friend inline size_t hash_value(GfVec3f const &vec) { - size_t h = 0; - boost::hash_combine(h, vec[0]); - boost::hash_combine(h, vec[1]); - boost::hash_combine(h, vec[2]); - return h; + return TfHash::Combine(vec[0], vec[1], vec[2]); } /// Equality comparison. diff --git a/pxr/base/gf/vec3h.h b/pxr/base/gf/vec3h.h index 279ff81029..1f690480db 100644 --- a/pxr/base/gf/vec3h.h +++ b/pxr/base/gf/vec3h.h @@ -38,8 +38,7 @@ #include "pxr/base/gf/traits.h" #include "pxr/base/gf/math.h" #include "pxr/base/gf/half.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -151,11 +150,7 @@ class GfVec3h /// Hash. friend inline size_t hash_value(GfVec3h const &vec) { - size_t h = 0; - boost::hash_combine(h, vec[0]); - boost::hash_combine(h, vec[1]); - boost::hash_combine(h, vec[2]); - return h; + return TfHash::Combine(vec[0], vec[1], vec[2]); } /// Equality comparison. diff --git a/pxr/base/gf/vec3i.h b/pxr/base/gf/vec3i.h index 9c0a455d53..1a1b5e50e0 100644 --- a/pxr/base/gf/vec3i.h +++ b/pxr/base/gf/vec3i.h @@ -36,8 +36,7 @@ #include "pxr/base/gf/api.h" #include "pxr/base/gf/limits.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -139,11 +138,7 @@ class GfVec3i /// Hash. friend inline size_t hash_value(GfVec3i const &vec) { - size_t h = 0; - boost::hash_combine(h, vec[0]); - boost::hash_combine(h, vec[1]); - boost::hash_combine(h, vec[2]); - return h; + return TfHash::Combine(vec[0], vec[1], vec[2]); } /// Equality comparison. diff --git a/pxr/base/gf/vec4d.h b/pxr/base/gf/vec4d.h index 1699ffc5fd..f307ceeff9 100644 --- a/pxr/base/gf/vec4d.h +++ b/pxr/base/gf/vec4d.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/limits.h" #include "pxr/base/gf/traits.h" #include "pxr/base/gf/math.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -157,12 +156,7 @@ class GfVec4d /// Hash. friend inline size_t hash_value(GfVec4d const &vec) { - size_t h = 0; - boost::hash_combine(h, vec[0]); - boost::hash_combine(h, vec[1]); - boost::hash_combine(h, vec[2]); - boost::hash_combine(h, vec[3]); - return h; + return TfHash::Combine(vec[0], vec[1], vec[2], vec[3]); } /// Equality comparison. diff --git a/pxr/base/gf/vec4f.h b/pxr/base/gf/vec4f.h index 4b2838c649..0b88bf9896 100644 --- a/pxr/base/gf/vec4f.h +++ b/pxr/base/gf/vec4f.h @@ -37,8 +37,7 @@ #include "pxr/base/gf/limits.h" #include "pxr/base/gf/traits.h" #include "pxr/base/gf/math.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -157,12 +156,7 @@ class GfVec4f /// Hash. friend inline size_t hash_value(GfVec4f const &vec) { - size_t h = 0; - boost::hash_combine(h, vec[0]); - boost::hash_combine(h, vec[1]); - boost::hash_combine(h, vec[2]); - boost::hash_combine(h, vec[3]); - return h; + return TfHash::Combine(vec[0], vec[1], vec[2], vec[3]); } /// Equality comparison. diff --git a/pxr/base/gf/vec4h.h b/pxr/base/gf/vec4h.h index 67b110dbbf..079586533b 100644 --- a/pxr/base/gf/vec4h.h +++ b/pxr/base/gf/vec4h.h @@ -38,8 +38,7 @@ #include "pxr/base/gf/traits.h" #include "pxr/base/gf/math.h" #include "pxr/base/gf/half.h" - -#include +#include "pxr/base/tf/hash.h" #include #include @@ -158,12 +157,7 @@ class GfVec4h /// Hash. friend inline size_t hash_value(GfVec4h const &vec) { - size_t h = 0; - boost::hash_combine(h, vec[0]); - boost::hash_combine(h, vec[1]); - boost::hash_combine(h, vec[2]); - boost::hash_combine(h, vec[3]); - return h; + return TfHash::Combine(vec[0], vec[1], vec[2], vec[3]); } /// Equality comparison. diff --git a/pxr/base/gf/vec4i.h b/pxr/base/gf/vec4i.h index a10894ce65..02a80a3b88 100644 --- a/pxr/base/gf/vec4i.h +++ b/pxr/base/gf/vec4i.h @@ -36,8 +36,7 @@ #include "pxr/base/gf/api.h" #include "pxr/base/gf/limits.h" #include "pxr/base/gf/traits.h" - -#include +#include "pxr/base/tf/hash.h" #include @@ -146,12 +145,7 @@ class GfVec4i /// Hash. friend inline size_t hash_value(GfVec4i const &vec) { - size_t h = 0; - boost::hash_combine(h, vec[0]); - boost::hash_combine(h, vec[1]); - boost::hash_combine(h, vec[2]); - boost::hash_combine(h, vec[3]); - return h; + return TfHash::Combine(vec[0], vec[1], vec[2], vec[3]); } /// Equality comparison. diff --git a/pxr/base/gf/wrapBBox3d.cpp b/pxr/base/gf/wrapBBox3d.cpp index 823063150e..b70ea776bc 100644 --- a/pxr/base/gf/wrapBBox3d.cpp +++ b/pxr/base/gf/wrapBBox3d.cpp @@ -48,6 +48,10 @@ string _Repr(GfBBox3d const &self) { TfPyRepr(self.GetMatrix()) + ")"; } +static size_t __hash__(GfBBox3d const &self) { + return TfHash()(self); +} + } // anonymous namespace void wrapBBox3d() @@ -128,6 +132,7 @@ void wrapBBox3d() .def(self != self) .def("__repr__", _Repr) + .def("__hash__", __hash__) ; to_python_converter, diff --git a/pxr/base/gf/wrapFrustum.cpp b/pxr/base/gf/wrapFrustum.cpp index 5cc359a689..a19f5ca0be 100644 --- a/pxr/base/gf/wrapFrustum.cpp +++ b/pxr/base/gf/wrapFrustum.cpp @@ -64,6 +64,10 @@ static std::string _Repr(GfFrustum const &self) return prefix + TfStringJoin(kwargs, seperator.c_str()) + ")"; } +static size_t __hash__(GfFrustum const &self) { + return TfHash()(self); +} + static object GetPerspectiveHelper( const GfFrustum &self, bool isFovVertical ) { double fov, aspect, nearDist, farDist; @@ -257,6 +261,7 @@ void wrapFrustum() .def(self != self) .def("__repr__", _Repr) + .def("__hash__", __hash__) ; TfPyWrapEnum(); diff --git a/pxr/base/gf/wrapInterval.cpp b/pxr/base/gf/wrapInterval.cpp index db52bc7c8c..8567309f93 100644 --- a/pxr/base/gf/wrapInterval.cpp +++ b/pxr/base/gf/wrapInterval.cpp @@ -68,6 +68,7 @@ void wrapInterval() .def(init( "Create a closed interval representing the range [v1,v2].")) .def(init("Create the interval.")) + .def(init()) .def( TfTypePythonClass() ) diff --git a/pxr/base/gf/wrapQuat.template.cpp b/pxr/base/gf/wrapQuat.template.cpp index 84cc1a67e2..bab4cf8a33 100644 --- a/pxr/base/gf/wrapQuat.template.cpp +++ b/pxr/base/gf/wrapQuat.template.cpp @@ -69,6 +69,10 @@ static {{ QUAT }}& __itruediv__({{ QUAT }} &self, {{ SCL }} value) return self /= value; } +static size_t __hash__({{ QUAT }} const &self) { + return TfHash()(self); +} + // Zero-initialized default ctor for python. static {{ QUAT }} *__init__() { return new {{ QUAT }}(0); } @@ -157,7 +161,7 @@ void wrapQuat{{ SUFFIX }}() .def({{ SCL }}() * self) .def(self / {{ SCL }}()) .def("__repr__", __repr__) - + .def("__hash__", __hash__) ; {% for S in SCALARS if S != SCL and ALLOW_IMPLICIT_CONVERSION(S, SCL) %} diff --git a/pxr/base/gf/wrapQuatd.cpp b/pxr/base/gf/wrapQuatd.cpp index d4b624340a..4f3218e54a 100644 --- a/pxr/base/gf/wrapQuatd.cpp +++ b/pxr/base/gf/wrapQuatd.cpp @@ -69,6 +69,10 @@ static GfQuatd& __itruediv__(GfQuatd &self, double value) return self /= value; } +static size_t __hash__(GfQuatd const &self) { + return TfHash()(self); +} + // Zero-initialized default ctor for python. static GfQuatd *__init__() { return new GfQuatd(0); } @@ -154,7 +158,7 @@ void wrapQuatd() .def(double() * self) .def(self / double()) .def("__repr__", __repr__) - + .def("__hash__", __hash__) ; implicitly_convertible(); diff --git a/pxr/base/gf/wrapQuaternion.cpp b/pxr/base/gf/wrapQuaternion.cpp index 9b034c8980..fd1580f463 100644 --- a/pxr/base/gf/wrapQuaternion.cpp +++ b/pxr/base/gf/wrapQuaternion.cpp @@ -86,6 +86,8 @@ void wrapQuaternion() .def(init()) + .def(init()) + .def( TfTypePythonClass() ) .def("GetZero", &This::GetZero) diff --git a/pxr/base/gf/wrapQuatf.cpp b/pxr/base/gf/wrapQuatf.cpp index 36a458a1cf..6ecb32473b 100644 --- a/pxr/base/gf/wrapQuatf.cpp +++ b/pxr/base/gf/wrapQuatf.cpp @@ -69,6 +69,10 @@ static GfQuatf& __itruediv__(GfQuatf &self, float value) return self /= value; } +static size_t __hash__(GfQuatf const &self) { + return TfHash()(self); +} + // Zero-initialized default ctor for python. static GfQuatf *__init__() { return new GfQuatf(0); } @@ -155,7 +159,7 @@ void wrapQuatf() .def(float() * self) .def(self / float()) .def("__repr__", __repr__) - + .def("__hash__", __hash__) ; implicitly_convertible(); diff --git a/pxr/base/gf/wrapQuath.cpp b/pxr/base/gf/wrapQuath.cpp index 8b60e08fbc..0bbc789199 100644 --- a/pxr/base/gf/wrapQuath.cpp +++ b/pxr/base/gf/wrapQuath.cpp @@ -69,6 +69,10 @@ static GfQuath& __itruediv__(GfQuath &self, GfHalf value) return self /= value; } +static size_t __hash__(GfQuath const &self) { + return TfHash()(self); +} + // Zero-initialized default ctor for python. static GfQuath *__init__() { return new GfQuath(0); } @@ -156,7 +160,7 @@ void wrapQuath() .def(GfHalf() * self) .def(self / GfHalf()) .def("__repr__", __repr__) - + .def("__hash__", __hash__) ; diff --git a/pxr/base/gf/wrapRect2i.cpp b/pxr/base/gf/wrapRect2i.cpp index 4a3a9559f4..108158e22e 100644 --- a/pxr/base/gf/wrapRect2i.cpp +++ b/pxr/base/gf/wrapRect2i.cpp @@ -48,6 +48,10 @@ static string _Repr(GfRect2i const &self) { TfPyRepr(self.GetMax()) + ")"; } +static size_t __hash__(GfRect2i const &self) { + return TfHash()(self); +} + } // anonymous namespace void wrapRect2i() @@ -115,7 +119,7 @@ void wrapRect2i() .def( self + self ) .def("__repr__", _Repr) - + .def("__hash__", __hash__) ; to_python_converter, TfPySequenceToPython > >(); diff --git a/pxr/base/gf/wrapRotation.cpp b/pxr/base/gf/wrapRotation.cpp index 4bea14ba28..024f490463 100644 --- a/pxr/base/gf/wrapRotation.cpp +++ b/pxr/base/gf/wrapRotation.cpp @@ -166,6 +166,10 @@ static GfRotation __itruediv__(GfRotation &self, double value) } // anonymous namespace +static size_t __hash__(GfRotation const &self) { + return TfHash()(self); +} + void wrapRotation() { typedef GfRotation This; @@ -176,6 +180,7 @@ void wrapRotation() .def(init()) .def(init()) .def(init()) + .def(init()) .def( TfTypePythonClass() ) @@ -258,7 +263,8 @@ void wrapRotation() #endif .def("__repr__", _Repr) - + .def("__hash__", __hash__) + ; to_python_converter, TfPySequenceToPython > >();