From bcf7f07092e70831a7d6924552de935ea1460d86 Mon Sep 17 00:00:00 2001
From: Jen Bradley <55467578+janbridley@users.noreply.github.com>
Date: Sat, 30 Sep 2023 11:35:26 -0400
Subject: [PATCH] Added `edge_lengths` property (#196)
* Added `edge_lengths` property
* Clarified documentation
* Updated changelog and credits
---------
Co-authored-by: Domagoj Fijan <50439291+DomFijan@users.noreply.github.com>
---
ChangeLog.rst | 7 +++++++
Credits.rst | 2 +-
coxeter/shapes/polyhedron.py | 13 ++++++++++++-
tests/test_polyhedron.py | 1 +
4 files changed, 21 insertions(+), 2 deletions(-)
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.
diff --git a/coxeter/shapes/polyhedron.py b/coxeter/shapes/polyhedron.py
index 0f2dd6a9..4f0997cf 100644
--- a/coxeter/shapes/polyhedron.py
+++ b/coxeter/shapes/polyhedron.py
@@ -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."""
diff --git a/tests/test_polyhedron.py b/tests/test_polyhedron.py
index 03028ef6..caa13600 100644
--- a/tests/test_polyhedron.py
+++ b/tests/test_polyhedron.py
@@ -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))