-
-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hash eq and neq operations to TShape #1375
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1980,11 +1980,44 @@ Returns the type as a term of the shapeenum enum: vertex, edge, wire, face, .... | |
") ShapeType; | ||
virtual TopAbs_ShapeEnum ShapeType(); | ||
|
||
|
||
%extend{ | ||
bool __ne_wrapper__(const opencascade::handle<TopoDS_TShape> & other) { | ||
if (self!=other) return true; | ||
else return false; | ||
} | ||
} | ||
%pythoncode { | ||
def __ne__(self, right): | ||
try: | ||
return self.__ne_wrapper__(right) | ||
except: | ||
return True | ||
} | ||
|
||
%extend{ | ||
bool __eq_wrapper__(const opencascade::handle<TopoDS_TShape> & other) { | ||
if (self==other) return true; | ||
else return false; | ||
} | ||
} | ||
%pythoncode { | ||
def __eq__(self, right): | ||
try: | ||
return self.__eq_wrapper__(right) | ||
except: | ||
return False | ||
} | ||
}; | ||
|
||
|
||
%make_alias(TopoDS_TShape) | ||
|
||
%extend TopoDS_TShape { | ||
size_t __hash__() { | ||
return opencascade::hash(self);} | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I'll move the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to, I did it there's a build going on |
||
%extend TopoDS_TShape { | ||
%pythoncode { | ||
__repr__ = _dumps_object | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Consider using more specific exception handling in ne and eq methods.
The current implementation catches all exceptions and returns a default value. This might hide unexpected errors. Consider catching specific exceptions that you expect might occur during the comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied these method implementations from TopoDS_Shape, but it's true that the try-except is a bit weird.
Unless there is a specific reason to do it this way, I would remove the try-except from both the Shape and TShape implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your feedback, we will generate fewer comments like this in the future according to the following instructions:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the try except statement, something like:
would segfault because the right member is not a TopoDS_Shape. Using ``ìsinstance``` would certainly be better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes I see. I'll make a new commit using isinstance