-
Notifications
You must be signed in to change notification settings - Fork 19
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
Update docs and add convenience methods to coordinate classes. #60
base: master
Are you sure you want to change the base?
Conversation
Add full documentation for some members of Coordinate2. Add repr() to Coordinate2, Coordinate3, Box2, Box3. Add some operator implementations for Coordinate2, Coordinate3, Box2, and Box3.
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.
Thanks for the PR @tclarke! And sorry for the delay in reviewing.
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.
Let me know if questions, etc.
def __add__(self, other: Coordinate2) -> Coordinate2: | ||
""" | ||
Positive translation by another Coordinate2. | ||
This does not modify the coordinate. | ||
|
||
:param other: The coordinate to translate by | ||
:type other: Coordinate2 | ||
:return: The translated coordinate. | ||
:rtype: Coordinate2 | ||
""" | ||
t = CSTransform() | ||
t.Translate((other.x, other.y, 0)) | ||
return self.transform(t) |
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 like the idea of overloading operators for coordinate2, etc. but my personal preference is that it be done without transforms. Transforms are a bit overkill here and make it a bit harder to read IMO. So, something like
def __add__(self, other: Coordinate2) -> Coordinate2:
"""
Positive translation by another Coordinate2.
This does not modify the coordinate.
:param other: The coordinate to translate by
:type other: Coordinate2
:return: The translated coordinate.
:rtype: Coordinate2
"""
return Coordinate2(self.x + other.x, self.y + other.y)
Same goes for the rest.
def __abs__(self) -> Coordinate2: | ||
""" | ||
Absolute value of both coodinate values. | ||
This does not modify the coordinate. | ||
|
||
:return: The new coordinate. | ||
:rtype: Coordinate2 | ||
""" | ||
return Coordinate2(abs(self.x), abs(self.y)) |
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 think this is fine. I was initially a bit on the fence because I normally think of the absolute value of a coordinate being its distance from the origin, but I think you're right this makes sense here.
def __round__(self, ndigits: int=0) -> Coordinate2: | ||
""" | ||
Round to a specified precision. Calls round_prec() | ||
This does not modify the coordinate. | ||
|
||
:return: A new coordinate with the specified precision. | ||
:rtype: Coordinate2 | ||
""" | ||
return self.round_prec(ndigits) |
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 like this, but let's get rid of round_prec
altogether as its no longer necessary. Just inline it's functionality here and replaces calls to round_prec
with round
elsewhere. Are you fine doing that?
Add full documentation for some members of Coordinate2.
Add repr() to Coordinate2, Coordinate3, Box2, Box3.
Add some operator implementations for Coordinate2, Coordinate3, Box2, and Box3.