Skip to content

Add tests for polylabel utility #4269

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

Merged

Conversation

giolucasd
Copy link
Contributor

@giolucasd giolucasd commented Jun 5, 2025

Overview: What does this pull request change?

Add tests for polylabel utility.

In detail:

  • Adds tests for classes Polygon and Cell, and method polylabel from file manim/utils/polylabel.py
  • Refactor the method Polygon.inside in order to fix edge case behavior and decompose into smaller private methods. The former method would fail to recognize points in the right and up edges as inside the polygon.
  • Configure coverage to ignore type checking blocks, since it would always be considered uncovered.
  • Improve Polygon class docstring descriptions.
  • Fix class OpenGLMobject methods set_width and stretch_to_fit_width doctests.

Motivation and Explanation: Why and how do your changes improve the library?

The polylabel utility is widely used in the project, but the existing tests were only indirectly testing these utilities. Therefore, adding unit tests can contribute to the robustness of the library.

Additionally, the implemented tests unmasked an edge case bug within the Polygon.inside method, leading to a fix and minor refactor.

Links to added or changed documentation pages

There are no changes to documentation pages.

Further Information and Comments

There were two doctests failing in the main branch:

  • method manim.mobject.opengl.opengl_mobject.OpenGLMobject.stretch_to_fit_width
  • method manim.mobject.opengl.opengl_mobject.OpenGLMobject.set_width

The error was caused by comparison between python float and numpy float. I assumed that there was no problem checking against numpy float. Let me know if there are any objections.

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@giolucasd giolucasd force-pushed the add-tests-for-polylabel-utility branch from 1030e8d to b3c6bd6 Compare June 9, 2025 19:13
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

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

Thank you for your efforts -- much appreciated! 🚀

@github-project-automation github-project-automation bot moved this from 🆕 New to 👍 To be merged in Dev Board Jun 11, 2025
@behackl behackl merged commit 5301ab8 into ManimCommunity:main Jun 11, 2025
21 checks passed
@github-project-automation github-project-automation bot moved this from 👍 To be merged to ✅ Done in Dev Board Jun 11, 2025
@behackl behackl added pr:bugfix Bug fix for use in PRs solving a specific issue:bug testing Anything related to testing the library labels Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:bugfix Bug fix for use in PRs solving a specific issue:bug testing Anything related to testing the library
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants