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 edge_lengths property #196

Merged
merged 5 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
The format is based on `Keep a Changelog <http://keepachangelog.com/en/1.0.0/>`__.
This project adheres to `Semantic Versioning <http://semver.org/spec/v2.0.0.html>`__.

v0.x.x - 20xx-xx-xx

Added
~~~~~

- New `edge_lengths` method.

v0.7.0 - 2023-09-18
-------------------

Expand Down
2 changes: 1 addition & 1 deletion Credits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Jen Bradley
* Added shape families for Archimedean, Catalan, and Johnson solids.
* Added shape family for prisms and antiprisms.
* Added shape family for equilateral pyramids and dipyramids.
* Added edges, edge_vectors, and num_edges methods.
* Added edges, edge_vectors, edge_lengths, and num_edges methods.

Domagoj Fijan
* Rewrote point in polygon check to use NumPy vectorized operations.
Expand Down
13 changes: 12 additions & 1 deletion coxeter/shapes/polyhedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,20 @@ def edges(self):

@property
def edge_vectors(self):
""":class:`numpy.ndarray`: Get the polyhedron's edges as vectors."""
""":class:`numpy.ndarray`: Get the polyhedron's edges as vectors.
:code:`edge_vectors` are returned in the same order as in :attr:`edges`.
"""
return self.vertices[self.edges[:, 1]] - self.vertices[self.edges[:, 0]]

@property
def edge_lengths(self):
""":class:`numpy.ndarray`: Get the length of each edge of the polyhedron.
:code:`edge_lengths` are returned in the same order as in :attr:`edges`.
"""
return np.linalg.norm(self.edge_vectors, axis=1)

@property
def num_edges(self):
"""int: Get the number of edges."""
Expand Down
1 change: 1 addition & 0 deletions tests/test_polyhedron.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ def test_edge_lengths():
poly.vertices[poly.edges[:, 1]] - poly.vertices[poly.edges[:, 0]], axis=1
)
assert np.allclose(veclens, edgelength)
assert np.allclose(poly.edge_lengths, edgelength)
assert np.allclose(veclens, np.linalg.norm(poly.edge_vectors, axis=1))


Expand Down