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

Fix the doctests #1340

Merged
merged 7 commits into from
Jul 3, 2024
Merged

Fix the doctests #1340

merged 7 commits into from
Jul 3, 2024

Conversation

tomvanmele
Copy link
Member

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)

@tomvanmele
Copy link
Member Author

  • not all objects have __str__
  • having to use print(...) in docstring examples to make sure they don't fail due to precision errors is annoying
  • would be good to have a template structure of some sorts, or at least a few "rules", for docstring examples

other things i have noticed

  • shapes have u and v even when only u makes sense. perhaps that should be changed
  • many attributes could be cached. would be good to have a system for that so that the cache gets invalidated when the parameters of an object are changed (could be a decorator for some attributes linked to an invalidate_cache method)
  • would be useful to further extend the basic infrastructure of with a bounding box attribute
  • point (and vector), line, polyline, polygon, polyhedron share the fact that they are defined explicitly by points. they therefore also don't have a frame. would be good to document this as such.
  • the parametric objects do have a frame, would be good to point this out as well in the docs
  • some intersections are still missing
  • an intersection class that combines all intersection calculations would be useful.
  • in general there should be a rule for binary operations between geometric entities about which entity is "left" and which is "right". for example the lower-dimensional object could always be on the left...

@tomvanmele
Copy link
Member Author

@jf--- since i can't add you as reviewer... ping

@tomvanmele
Copy link
Member Author

my mouse and keyboard don't want to connect anymore so i will take that as a sign that it is time to give up for today...

@tomvanmele
Copy link
Member Author

all are fixed.
some had to be skipped because of some weird behaviour, others because of an actual bug. we can do a search for # doctes: +SKIP to investigate in more detail later...

@tomvanmele
Copy link
Member Author

the tests are failing because of something weird going on on the github side

>>> with open('point.json', 'r') as f: # doctest: +SKIP
... point = json.load(f, cls=DataDecoder) # doctest: +SKIP
Copy link
Contributor

Choose a reason for hiding this comment

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

just out of curiosity why these needs to be skipped? So in doctest the read and writing to disk is not possible? If that's the case perhaps these kind of stuff can be loads and dumps instead

Copy link
Member Author

Choose a reason for hiding this comment

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

perhaps this works now actually. will try again...

Comment on lines -109 to +114
>>> from compas_viewer import Viewer # doctest: +SKIP
>>> viewer = Viewer() # doctest: +SKIP
>>> viewer.scene.add(line) # doctest: +SKIP
>>> from compas_viewer import Viewer # doctest: +SKIP
>>> viewer = Viewer() # doctest: +SKIP
>>> viewer.scene.add(line) # doctest: +SKIP
>>> viewer.scene.add(hyperbola) # doctest: +SKIP
>>> viewer.scene.add(hyperbola.frame) # doctest: +SKIP
>>> viewer.show() # doctest: +SKIP
>>> viewer.show() # doctest: +SKIP
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe in future we should remove them from API reference of core? (After we clean up and improve the documents of viewer)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes i agree. viewer stuff should not be in the docs. will already remove them...

Comment on lines +21 to +27
>>> from compas.geometry import Line # doctest: +SKIP
>>> from compas.geometry import Intersection # doctest: +SKIP
>>> a = Line([0, 0, 0], [2, 0, 0]) # doctest: +SKIP
>>> b = Line([1, 0, 0], [1, 1, 0]) # doctest: +SKIP
>>> intersection = Intersection() # doctest: +SKIP
>>> intersection.line_line(a, b) # doctest: +SKIP
>>> intersection.number_of_intersections # doctest: +SKIP
Copy link
Contributor

Choose a reason for hiding this comment

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

plugin required for these ones?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, this was more like an API test example. the class is not yet part of the public API...

@@ -138,7 +138,7 @@ def offset_polygon(polygon, distance, tol=None):
>>> polygon = Polygon([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)])
>>> offsetted_polygon = offset_polygon(polygon, 0.5)
>>> offsetted_polygon
Polygon[[0.5, 0.5, 0.0], [0.5, 0.5, 0.0], [0.5, 0.5, 0.0], [0.5, 0.5, 0.0]]
[[0.5, 0.5, 0.0], [0.5, 0.5, 0.0], [0.5, 0.5, 0.0], [0.5, 0.5, 0.0]]
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this function return a Polygon object instead of list to align with the input?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, the lower level function shouldn't. the version attached to the polygon class itself should...

Copy link
Contributor

Choose a reason for hiding this comment

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

i see

@@ -491,7 +491,7 @@ def from_convex_hull(cls, points):
--------
>>> from compas.geometry import Polyhedron
>>> points = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
>>> p = Polyhedron.from_convex_hull(points)
>>> p = Polyhedron.from_convex_hull(points) # doctest: +SKIP
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if we also have a way document the minimal plugins needed for certain functions

Copy link
Contributor

@Licini Licini left a comment

Choose a reason for hiding this comment

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

LGTM! Just some random comments!

@jf---
Copy link
Contributor

jf--- commented Apr 27, 2024

@tomvanmele this is exciting, is this PR tangential to #1340?

@tomvanmele
Copy link
Member Author

which one do you mean? this one is #1340...

@gonzalocasas
Copy link
Member

@tomvanmele there's quite a bunch of conflicts now, but it would be cool to merge this

@tomvanmele tomvanmele merged commit 0d71a41 into main Jul 3, 2024
14 checks passed
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.

4 participants