From 9c128d97b91c23bd186717e54c9a6b3a60ca7e57 Mon Sep 17 00:00:00 2001 From: janbridley Date: Mon, 18 Sep 2023 11:44:00 -0400 Subject: [PATCH 1/3] Added `edge_lengths` property --- coxeter/shapes/polyhedron.py | 5 +++++ tests/test_polyhedron.py | 1 + 2 files changed, 6 insertions(+) diff --git a/coxeter/shapes/polyhedron.py b/coxeter/shapes/polyhedron.py index 0f2dd6a9..b4ae1189 100644 --- a/coxeter/shapes/polyhedron.py +++ b/coxeter/shapes/polyhedron.py @@ -390,6 +390,11 @@ def edge_vectors(self): """:class:`numpy.ndarray`: Get the polyhedron's edges as vectors.""" 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.""" + return np.linalg.norm(self.edge_vectors, axis=1) + @property def num_edges(self): """int: Get the number of edges.""" diff --git a/tests/test_polyhedron.py b/tests/test_polyhedron.py index a31ece8c..3241e383 100644 --- a/tests/test_polyhedron.py +++ b/tests/test_polyhedron.py @@ -392,6 +392,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)) From de9e8dd488b5c18f5ae1c3e8ba658d8f167342a0 Mon Sep 17 00:00:00 2001 From: janbridley Date: Wed, 27 Sep 2023 16:10:23 -0400 Subject: [PATCH 2/3] Clarified documentation --- coxeter/shapes/polyhedron.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/coxeter/shapes/polyhedron.py b/coxeter/shapes/polyhedron.py index b4ae1189..4f0997cf 100644 --- a/coxeter/shapes/polyhedron.py +++ b/coxeter/shapes/polyhedron.py @@ -387,12 +387,18 @@ 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.""" + """: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 From 080e942d323540dd7f8f44bb59c48bea76c13504 Mon Sep 17 00:00:00 2001 From: janbridley Date: Wed, 27 Sep 2023 16:13:50 -0400 Subject: [PATCH 3/3] Updated changelog and credits --- ChangeLog.rst | 7 +++++++ Credits.rst | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog.rst b/ChangeLog.rst index e312f07a..349b06fa 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -1,6 +1,13 @@ The format is based on `Keep a Changelog `__. This project adheres to `Semantic Versioning `__. +v0.x.x - 20xx-xx-xx + +Added +~~~~~ + +- New `edge_lengths` method. + v0.7.0 - 2023-09-18 ------------------- diff --git a/Credits.rst b/Credits.rst index 97bc7beb..d6545066 100644 --- a/Credits.rst +++ b/Credits.rst @@ -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.