You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TopoDS_Shape used to have a .HashCode() method and it now uses the builtin hash() (via .__hash__()).
However it still uses a .IsEqual() method and does not implement == (via .__eq__()).
This leads to counter-intuitive behavior such as:
print(f"{[hash(a)==hash(b) fora,binzip(edges1,edges2)] =}") # [True, True, True, True, True, True]print(f"{[a.IsEqual(b) fora,binzip(edges1,edges2)] =}") # [True, True, True, True, True, True]# but...print(f"{len(set(edges2) -set(edges1)) =}") # 6 <- would expect 0 as `IsEqual()` and `hash()` suggest the faces are the sameprint(f"{[a==bfora,binzip(edges1,edges2)] =}") # [False, False, False, False, False, False] <- that's why :(
if __eq__ was an alias of IsEqual (as can be simulated with TopoDS_Shape.__eq__ = TopoDS_Shape.IsEqual) we'd have
print(f"{[a==bfora,binzip(edges1,edges2)] =}") # [True, True, True, True, True, True]print(f"{len(set(edges2) -set(edges1)) =}") # 0 <- exclude the faces form themselves, nothing left :)
Are there any reasons not to do this?
(arguably __bool__ for .IsNull() would be nice too, but that doesn't seem as important as __hash__ and __eq__ being consistent)
hey @adam-urbanczyk thanks for the reply, do you have any further input as the maintainer of the project?
For now not planned, but I'll leave this open
What other elements could help decide one way or another?
To reiterate in a more concise way in case providing a full argument and example code wasn't the right thing to do:
Two of the TopoDS_Shape methods have been "moved" to Python's builtin (HashCode() to __hash__ and IsNull to __bool__) but IsEqual, which could follow as __eq__, remains.
TopoDS_Shape
used to have a.HashCode()
method and it now uses the builtinhash()
(via.__hash__()
).However it still uses a
.IsEqual()
method and does not implement==
(via.__eq__()
).This leads to counter-intuitive behavior such as:
if
__eq__
was an alias ofIsEqual
(as can be simulated withTopoDS_Shape.__eq__ = TopoDS_Shape.IsEqual
) we'd haveAre there any reasons not to do this?
(arguably
__bool__
for.IsNull()
would be nice too, but that doesn't seem as important as__hash__
and__eq__
being consistent)full example:
The text was updated successfully, but these errors were encountered: