Skip to content

Update docs and add convenience methods to coordinate classes.#60

Open
tclarke wants to merge 1 commit into
matthuszagh:masterfrom
tclarke:master
Open

Update docs and add convenience methods to coordinate classes.#60
tclarke wants to merge 1 commit into
matthuszagh:masterfrom
tclarke:master

Conversation

@tclarke

@tclarke tclarke commented Jul 22, 2022

Copy link
Copy Markdown

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.

@matthuszagh matthuszagh left a comment

Copy link
Copy Markdown
Owner

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.

@matthuszagh matthuszagh left a comment

Copy link
Copy Markdown
Owner

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 thread pyems/coordinate.py
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
Copy Markdown
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 thread pyems/coordinate.py
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
Copy Markdown
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 thread pyems/coordinate.py
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
Copy Markdown
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