Update docs and add convenience methods to coordinate classes.#60
Update docs and add convenience methods to coordinate classes.#60tclarke wants to merge 1 commit into
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.
matthuszagh
left a comment
There was a problem hiding this comment.
Thanks for the PR @tclarke! And sorry for the delay in reviewing.
| 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.
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.
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.
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.