From b089ed3c43775785c2a29e47ba6e8cc045ea89ad Mon Sep 17 00:00:00 2001 From: Pete Haughie Date: Thu, 9 Oct 2025 01:57:41 +0200 Subject: [PATCH 1/2] Missing pvector.dist --- src/pycreative/app.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pycreative/app.py b/src/pycreative/app.py index 8704349..0cd61d3 100644 --- a/src/pycreative/app.py +++ b/src/pycreative/app.py @@ -277,6 +277,13 @@ def dot(a, b): bx, by = (b.x, b.y) if isinstance(b, PVector) else (float(b[0]), float(b[1])) return ax * bx + ay * by + @staticmethod + def dist(a, b): + """Euclidean distance between two PVectors or 2-length iterables.""" + ax, ay = (a.x, a.y) if isinstance(a, PVector) else (float(a[0]), float(a[1])) + bx, by = (b.x, b.y) if isinstance(b, PVector) else (float(b[0]), float(b[1])) + return math.hypot(ax - bx, ay - by) + @staticmethod def angle_between(a, b): ax, ay = (a.x, a.y) if isinstance(a, PVector) else (float(a[0]), float(a[1])) From e2ac542c027589957948c748601bca131e9aecf3 Mon Sep 17 00:00:00 2001 From: Pete Haughie Date: Thu, 9 Oct 2025 02:07:31 +0200 Subject: [PATCH 2/2] Added supporting unit test --- tests/test_pvector_dist.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/test_pvector_dist.py diff --git a/tests/test_pvector_dist.py b/tests/test_pvector_dist.py new file mode 100644 index 0000000..61e775f --- /dev/null +++ b/tests/test_pvector_dist.py @@ -0,0 +1,21 @@ +def test_pvector_dist_instance_and_classstyle(): + from pycreative.vector import PVector + import math + + v1 = PVector(10, 20) + v2 = PVector(60, 80) + + # expected distance between (10,20) and (60,80) + expected = math.hypot(50, 60) + + # instance method + d1 = v1.dist(v2) + assert abs(d1 - expected) < 1e-9 + + # class-style/unbound call (PVector.dist(v1, v2)) should work too + d2 = PVector.dist(v1, v2) + assert abs(d2 - expected) < 1e-9 + + # iterable input + d3 = v1.dist((60, 80)) + assert abs(d3 - expected) < 1e-9