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

Added new shape families for Archimedean, Catalan, Johnson, and other solids. #177

Merged
merged 23 commits into from
Mar 27, 2023

Conversation

janbridley
Copy link
Contributor

@janbridley janbridley commented Feb 13, 2023

Description

Expanded on coxeter.families with methods and data for several families of common convex polyhedra:

  • ArchimedeanFamily: The 13 Archimedean solids.
  • CatalanFamily: The 13 Archimedean duals.
  • JohnsonFamily: The 92 Johnson solids.
  • PrismAntiprismFamily: The 16 n-gonal prisms and antiprisms ranging from n=3 to n=10.
  • PyramidDipyramidFamily: The 6 equilateral pyramids and dipyramids.

Each new family is queryable with get_shape("Shape Name") and returns a ConvexPolyhedron normalized to volume of 1, just as PlatonicFamily currently does. Vertex data for all new families is stored as a float64, and stored data for the current PlatonicFamily has been updated to match that precision. This change fixes intermittent bugs that arose from lack of numerical precision. New pytests have been added to verify the new families behave as expected.

Motivation and Context

Querying polyhedra other than Platonic solids could be relatively difficult. This release streamlines the process and allows for simple access to a greatly increased number of convex solids.

Types of Changes

  • Documentation update
  • Bug fix
  • New feature
  • Breaking change1

1The change breaks (or has the potential to break) existing functionality.

Checklist:

b-butler and others added 12 commits January 25, 2023 18:30
Only test quaternions that are not effectively zero.
The new class ``polyhedron.edges`` returns the a list of the edges of a polyhedron as vertex-index pairs, similar to the current ``polyhedron.faces`` class. The class ``polyhedron.get_edge_vectors`` returns a list of edges as vectors in 3D space.
* New pytest marks have been created for the Archimedean, Catalan, and Johnson shape families.
* A function has been written to combine multiple marks into a single mark for more compact testing of shape properties.
* test_volume function for damasceno shapes has been adapted to test the new shape families
* A test_surface_area method similar to test_volume has been added.
Tightened ``atol`` of ``test_insphere``. Increased the deadline of the test to accommodate testing of shapes with many faces (e.g. disdyakis triacontahedron).
…ew shape families, including prism/antiprism and pyramid/dipyramid
This commit reverts changes made in  ab21279, which are included in a different PR.
@janbridley janbridley requested a review from a team as a code owner February 13, 2023 16:28
janbridley and others added 4 commits February 13, 2023 11:41
…exity.

The Random3DRotationStrategy test varies widely in runtime based on the complexity of the input shape. Splitting the calling function into two tests (for simple Platonic shapes and more complex Catalan shapes) should solve this issue.
@janbridley janbridley force-pushed the release-recalculate_renormalize_platonic branch from 52533ec to 2df65c0 Compare February 13, 2023 18:53
The ``minimal_bounding_sphere`` method is reliant on the solution to a linear system of equations. For polyhedra with portions that protrude out from the main mass, this method can fail due to numerical instability in a small percent of cases. This fix double-checks that the calculated miniball contains all points on the polyhedron, and allows the method to make more attempts to find a correct answer before failing.
Copy link
Collaborator

@vyasr vyasr left a comment

Choose a reason for hiding this comment

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

Some minor suggestions here, as well as a request to clean out miniball-related changes. Aside from that, is there anyone else in the group who could confirm the validity of the shape families themselves? I am not working with these currently and it would be good for someone who is to take a few minutes to spot check that the produced shapes are valid.

coxeter/shapes/polyhedron.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
tests/conftest.py Show resolved Hide resolved
janbridley added a commit that referenced this pull request Feb 27, 2023
Until the precision improvements in #177 are added, a decrease in rtol and the merge_faces call are required for pytest to succeed on the dodecahedron's edges. Once the precision is increased, these temporary solutions can be reverted
janbridley added a commit that referenced this pull request Feb 27, 2023
…ed data

Currently, the stored data for polyhedra is not accurate enough for the ``edges`` and ``edge_vectors`` properties to function as expected. Once #177 is merged, the accuracy increase should fix the issue and assertion tolerances for testing can be tightened. In addition, ``merge_faces`` should no longer be required for any of the polyhedra included with this package.
@codecov
Copy link

codecov bot commented Feb 27, 2023

Codecov Report

Merging #177 (e950097) into master (cfb4637) will increase coverage by 0.01%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master     #177      +/-   ##
==========================================
+ Coverage   54.44%   54.45%   +0.01%     
==========================================
  Files          27       27              
  Lines        2623     2628       +5     
==========================================
+ Hits         1428     1431       +3     
- Misses       1195     1197       +2     
Impacted Files Coverage Δ
coxeter/families/__init__.py 0.00% <0.00%> (ø)
coxeter/families/common.py 32.14% <0.00%> (-6.99%) ⬇️

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@janbridley janbridley self-assigned this Mar 21, 2023
Copy link
Collaborator

@vyasr vyasr left a comment

Choose a reason for hiding this comment

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

This PR LGTM now! For future reference, once you've addressed PR review changes you can re-request review by clicking on the button right next to the reviewer name in the Reviewers section on the top-right of the PR page.


# A convenient mark decorator that also includes names for the polyhedra.
# Assumes that the argument name is "poly".
_archimedean_shape_names = ArchimedeanFamily.data.keys()
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI you don't need to extract keys to iterate over a dictionary, and it's usually more performant not to do so:

In [3]: for key in dict.fromkeys('abcdefg'):print(key)
a
b
c
d
e
f
g

In [4]: %timeit for key in dict.fromkeys('abcdefg'): pass
629 ns _ 8.29 ns per loop (mean _ std. dev. of 7 runs, 1,000,000 loops each)

In [5]: %timeit for key in dict.fromkeys('abcdefg').keys(): pass
711 ns _ 6.37 ns per loop (mean _ std. dev. of 7 runs, 1,000,000 loops each)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback, and noted for next time!

@vyasr
Copy link
Collaborator

vyasr commented Mar 27, 2023

@janbridley feel free to click the "Squash and merge" button when you're ready!

Copy link
Contributor

@Tobias-Dwyer Tobias-Dwyer left a comment

Choose a reason for hiding this comment

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

looks good!

@Tobias-Dwyer Tobias-Dwyer merged commit 2a2bff3 into master Mar 27, 2023
@Tobias-Dwyer Tobias-Dwyer deleted the release-recalculate_renormalize_platonic branch March 27, 2023 16:01
janbridley added a commit that referenced this pull request Aug 16, 2023
* test: Fix assumption on quaternions.

Only test quaternions that are not effectively zero.

* Added new classes to return the edges of polyhedra

The new class ``polyhedron.edges`` returns the a list of the edges of a polyhedron as vertex-index pairs, similar to the current ``polyhedron.faces`` class. The class ``polyhedron.get_edge_vectors`` returns a list of edges as vectors in 3D space.

* Fixed return for get_edge_vectors method.

* Renamed get_edge_vectors property to edge_vectors

Co-authored-by: Vyas Ramasubramani <vyas.ramasubramani@gmail.com>

* Vectorized edge_vectors return with numpy

Co-authored-by: Vyas Ramasubramani <vyas.ramasubramani@gmail.com>

* Updated test_polyhedron to be compatible with the renamed edge_vectors property

* Updated test_polyhedron to explicitly cover the edges property

* Updated rtol for edge property test

Until the precision improvements in #177 are added, a decrease in rtol and the merge_faces call are required for pytest to succeed on the dodecahedron's edges. Once the precision is increased, these temporary solutions can be reverted

* Reverted small fixes that account for inaccuracies in polyhedron stored data

Currently, the stored data for polyhedra is not accurate enough for the ``edges`` and ``edge_vectors`` properties to function as expected. Once #177 is merged, the accuracy increase should fix the issue and assertion tolerances for testing can be tightened. In addition, ``merge_faces`` should no longer be required for any of the polyhedra included with this package.

* Removed unnecessary comment from ``test_edges``

* Changed ``edge_vectors`` property to return a numpy array

Co-authored-by: Bradley Dice <bdice@bradleydice.com>

* Rewrote ``edges`` method and updated ``edge_vectors`` for compatibility

After discussing possible options for returning polyhedral edges, it was determined that a set of i<j pairs of vertices was the best option for output in the ``edges`` method. A description of how to generate (j,i) pairs was added to the docstring, and the edge_vectors method was updated to work with the new set/tuple structure.

* Updated ``test_polyhedron`` to work with set edges

* Fixed docstring formatting for ``edges`` and ``edge_vectors``

* Updated edges method to return Numpy array

It was determined that edges should be returned as an ordered Numpy array. This commit ensures the final output is a numpy array, sorted first by the (i) element and then by the (j) element where i<j. This mimics Mathematica's edges output format and should aid in usability. Documentation was updated accordingly.

* test_polyhedron::test_edges now checks edge count

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Updated edges property to cache result

* Updated edges and edge_vectors to make better use of numpy functions and functools caching

* Added num_edges method

* Updated credits

* Updated test_polyhedron to test num_edges property

* Updated edges documentation

Co-authored-by: Bradley Dice <bdice@bradleydice.com>

* Updated edge_vectors documentation

Co-authored-by: Bradley Dice <bdice@bradleydice.com>

* Refactored test_edges to be more comprehensive

Added explicit tests for sorting, double checks for edge length, and an additional test for the number of edges based on the euler characteristic

* Added fast num_edges calculation for convex polyhedron and improved pytests

* test_num_edges now covers nonconvex Polyhedron class

* Update Credits.rst

Co-authored-by: Bradley Dice <bdice@bradleydice.com>

* Test i-i edges

Co-authored-by: Bradley Dice <bdice@bradleydice.com>

* Removed changes to .gitignore

---------

Co-authored-by: Brandon Butler <butlerbr@umich.edu>
Co-authored-by: Vyas Ramasubramani <vyas.ramasubramani@gmail.com>
Co-authored-by: Bradley Dice <bdice@bradleydice.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This was referenced Aug 29, 2023
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.

None yet

4 participants