Skip to content

Conversation

@ScriptLineStudios
Copy link
Member

@ScriptLineStudios ScriptLineStudios commented Jan 11, 2023

Closes #155

Comment on lines +452 to +477
def test_as_segments(self):
"""Checks whether polygon segments are correct"""
poly = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
self.assertEqual(
poly.as_segments(),
[
Line((0, 0), (1, 0)),
Line((1, 0), (1, 1)),
Line((1, 1), (0, 1)),
Line((0, 1), (0, 0)),
],
)
poly = Polygon([(123.23, 35.6), (56.4, 87.45), (43.1, 12.3)])
self.assertEqual(
poly.as_segments(),
[
Line((123.23, 35.6), (56.4, 87.45)),
Line((56.4, 87.45), (43.1, 12.3)),
Line((43.1, 12.3), (123.23, 35.6)),
],
)
poly = Polygon([[1, 2], [3, 4], [5, 6]])
self.assertEqual(
poly.as_segments(),
[Line((1, 2), (3, 4)), Line((3, 4), (5, 6)), Line((5, 6), (1, 2))],
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add more tests for invalid argument types and argument number.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically you should make sure that this is actually a no arguments method now and in the future

@itzpr3d4t0r
Copy link
Member

I would be thankful if you could add a couple benchmarks as well in the benchmarks directory, though that's not strictly necessary, i can add them later.

Comment on lines 210 to +211
@overload
def as_segments(self) -> List[Line]: ...
Copy link
Member

@itzpr3d4t0r itzpr3d4t0r Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need @overload here, there's just one way to call this function

@itzpr3d4t0r itzpr3d4t0r changed the title Polygon.as_segments Polygon as_segments() Jan 13, 2023
@itzpr3d4t0r itzpr3d4t0r added type:new_api Adds new functionalities to the project submodule:polygon labels Jan 13, 2023
@itzpr3d4t0r itzpr3d4t0r reopened this Feb 14, 2023
@itzpr3d4t0r itzpr3d4t0r reopened this May 19, 2023
@itzpr3d4t0r itzpr3d4t0r merged commit 2720df1 into pygame-community:main May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

submodule:polygon type:new_api Adds new functionalities to the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add as_segments() function to Polygon

2 participants