Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tclarke
Copy link

@tclarke tclarke commented Jul 22, 2022

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.

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.
Copy link
Owner

@matthuszagh matthuszagh left a 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.

Copy link
Owner

@matthuszagh matthuszagh left a 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.

Comment on lines +59 to +71
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)
Copy link
Owner

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.

Comment on lines +133 to +141
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))
Copy link
Owner

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.

Comment on lines +143 to +151
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)
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants