-
Notifications
You must be signed in to change notification settings - Fork 3
Update to round_corner and round_corners Region methods #502
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
base: main
Are you sure you want to change the base?
Conversation
…date_lines Region method. Add _round_corner Region method.
@@ -836,11 +871,11 @@ def round_corner(self, corner_coordinate, radius): | |||
if converged == False: | |||
raise Exception("Cannot find intersection. Check if radius is too large") |
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.
For this exception, it might be worth using one of the more specific exceptions (probably ValueError, see https://docs.python.org/3/library/exceptions.html). This would mean that in the try/except block later, we can check specifically for a ValueError, rather than a bare except.
# the lengths of the adjacent entities. | ||
for index in range(len(adj_entity_lengths)): | ||
j = adj_entity_lengths[index] | ||
if j < 2 * distance: | ||
raise Exception( |
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.
As above, maybe use ValueError instead of Exception?
try: | ||
# try to round the corner with the specified radius | ||
self._round_corner(corner_coordinate, radius, adj_entity_lengths) | ||
except Exception as e: |
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.
If we use ValueError instead of Exception in _round_corner() then we can instead use
except ValueError as e:
instead of except Exception as e:
This would mean we would not inadvertently try to handle some unrelated exception that could be raised.
corner_coordinate, new_corner_radius, adj_entity_lengths | ||
) | ||
break | ||
except Exception as e: |
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.
Again this could be ValueError instead of Exception
Whether to maximise the possible radius if the radius provided is too large. | ||
""" | ||
# consolidate Line entities in the region where possible | ||
self._consolidate_lines() |
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.
try: | ||
# try to round the corner with the specified radius | ||
self._round_corner(corner, radius, adj_entity_lengths) | ||
except Exception as e: |
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.
As above, use ValueError instead of Exception?
# try to round the corner with the new shorter radius | ||
self._round_corner(corner, new_corner_radius, adj_entity_lengths) | ||
break | ||
except Exception as e: |
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.
As above, use ValueError instead of Exception?
for index in range(len(adj_entities)): | ||
j = adj_entities[index] | ||
if j.length < distance: | ||
# check that the distances by which the adjacent entities are shortened are less than half |
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.
Previously, you had to specify a valid radius for corner rounding, or an exception was raised.
Old behaviour:
New behaviour:
This update means that the Adaptive Templates corner rounding function behaviour is more in line with the in-built Motor-CAD Standard Template geometry corner rounding.
Also add _consolidate_lines Region method. This checks a region entities and consolidates multiple line entities into a single line entity where possible:
Without "consolidation"

With "consolidation"

It is useful to consolidate lines, otherwise the corner rounding functionality is limited by the lengths of the shorter lines.