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

Add some more __str__ function to geometry classes for pretty print #1289

Merged
merged 21 commits into from
Jul 10, 2024

Conversation

yck011522
Copy link
Contributor

Partially Fixes #1287

What type of change is this?

  • Bug fix in a backwards-compatible manner.
  • New feature in a backwards-compatible manner.
  • Breaking change: bug fix or new feature that involve incompatible API changes.
  • Other (e.g. doc update, configuration, etc)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I added a line to the CHANGELOG.md file in the Unreleased section under the most fitting heading (e.g. Added, Changed, Removed).
  • I ran all tests on my computer and it's all green (i.e. invoke test).
  • I ran lint on my computer and there are no errors (i.e. invoke lint).
  • I added new functions/classes and made them available on a second-level import, e.g. compas.datastructures.Mesh.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if appropriate)

Copy link
Member

@gonzalocasas gonzalocasas left a comment

Choose a reason for hiding this comment

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

I added a few comments but generally looking good!

src/compas/geometry/frame.py Outdated Show resolved Hide resolved
src/compas/geometry/plane.py Outdated Show resolved Hide resolved
src/compas/geometry/pointcloud.py Outdated Show resolved Hide resolved
Comment on lines -248 to +253
points = box.points
x, y, z = zip(*points)
xmin, xmax = min(x), max(x)
ymin, ymax = min(y), max(y)
zmin, zmax = min(z), max(z)
xmin, xmax = box.xmin, box.xmax
ymin, ymax = box.ymin, box.ymax
zmin, zmax = box.zmin, box.zmax
Copy link
Member

Choose a reason for hiding this comment

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

This change is not related to the str stuff, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The change is there because I couldn't actually run tests without fixing the broken functions.

@@ -103,6 +103,9 @@ def __init__(self, points, name=None):
def __repr__(self):
return "{0}(points={1!r})".format(type(self).__name__, self.points)

def __str__(self):
return "{0}(points={1})".format(type(self).__name__, [point.__str__() for point in self.points])
Copy link
Member

Choose a reason for hiding this comment

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

switch to str() as above

src/compas/geometry/polyhedron.py Show resolved Hide resolved
src/compas/geometry/polyhedron.py Outdated Show resolved Hide resolved
src/compas/geometry/polyhedron.py Outdated Show resolved Hide resolved
@tomvanmele
Copy link
Member

@yck011522 please keep the PR focused on the implementation of __str__. adding other stuff will just drag out the review process...

@yck011522
Copy link
Contributor Author

@yck011522 please keep the PR focused on the implementation of __str__. adding other stuff will just drag out the review process...

@tomvanmele The associated changes are there only because those functions were broken to the point that prevented me to test out the new __str__ functios.

@tomvanmele tomvanmele marked this pull request as ready for review May 31, 2024 11:43
Copy link
Member

@gonzalocasas gonzalocasas left a comment

Choose a reason for hiding this comment

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

sorry, this slipped through the cracks... it lgtm!

@gonzalocasas
Copy link
Member

@yck011522 could you fix the conflict so that we can merge?

Copy link
Member

@gonzalocasas gonzalocasas left a comment

Choose a reason for hiding this comment

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

Besides the changelog fix it lgtm

CHANGELOG.md Outdated
@@ -268,6 +268,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Changed `compas.scene.VolMesh`'s `show_vertices`, `show_edges`, `show_faces`, `show_cells` to optionally accept a sequence of keys.
* Fixed missing implementation of `Sphere.base`.
* Fixed bug in `intersection_sphere_sphere`.
* Changed the `__str__` of `compas.geometry.Frame`, `compas.geometry.Plane`, `compas.geometry.Polygon`, `compas.geometry.Polyhedron`, `compas.geometry.Quaternion` to use a limited number of decimals (determined by `Tolerance.PRECISION`). Note: `__repr__` will instead maintain full precision.
Copy link
Member

Choose a reason for hiding this comment

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

Could you update this? Because after the merge it's way down in the file, changing an already released version

Copy link

codecov bot commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 60.19%. Comparing base (b23bf7b) to head (7d65bbb).

Files Patch % Lines
src/compas/colors/color.py 75.00% 1 Missing ⚠️
src/compas/geometry/frame.py 50.00% 1 Missing ⚠️
src/compas/geometry/plane.py 50.00% 1 Missing ⚠️
src/compas/geometry/pointcloud.py 80.00% 1 Missing ⚠️
src/compas/geometry/polygon.py 50.00% 1 Missing ⚠️
src/compas/geometry/polyhedron.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1289      +/-   ##
==========================================
+ Coverage   60.11%   60.19%   +0.07%     
==========================================
  Files         207      207              
  Lines       22234    22248      +14     
==========================================
+ Hits        13366    13392      +26     
+ Misses       8868     8856      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yck011522
Copy link
Contributor Author

@tomvanmele @gonzalocasas
I notice that the new check called codecov is not passing. The checker seems to want every line of code being included in test. How should I handle this? Should I make the compliant? It seems like some of the tests will be excessive if every line needs to be in CI.

Because newer float format behavior is different in different python versions
there seems to be a problem with TOL.format_numbers not passing test
@yck011522
Copy link
Contributor Author

I was trying to add some more tests to cover the str and repr functions. However I realized that the underlying mechanism of formatting the numbers in Point is based on TOL.format_number and its behavior is unstable across different environments.

So I have decided to open another PR to investigate the problem and this PR will not have those tests included.

@yck011522 yck011522 merged commit f4cf9cb into main Jul 10, 2024
17 checks passed
@gonzalocasas
Copy link
Member

@tomvanmele @gonzalocasas
I notice that the new check called codecov is not passing. The checker seems to want every line of code being included in test. How should I handle this? Should I make the compliant? It seems like some of the tests will be excessive if every line needs to be in CI.

Having coverage metrics is good, but we don't intend to be obsessive about it

@tomvanmele
Copy link
Member

@yck011522 the test is just feedback about coverage. it will not block the PR from being merged...

@yck011522 yck011522 deleted the yck011522/issue1287 branch July 11, 2024 02:27
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.

Add __str__ to all geometry classes for pretty print
3 participants