From a92866dcb25a653476daf1d1877fc34796d006f1 Mon Sep 17 00:00:00 2001 From: Joe Wallwork Date: Wed, 12 Jun 2024 13:39:46 +0100 Subject: [PATCH] Raise error if points are identical --- maths.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/maths.py b/maths.py index 6bd8cd5..5ea2e16 100644 --- a/maths.py +++ b/maths.py @@ -1,3 +1,6 @@ +import numpy as np + + def equation_of_line(a, b): """ Determine the equation of the line passing through two points. @@ -6,6 +9,8 @@ def equation_of_line(a, b): :arg b: the second point the line passes through :return: function of two variables defining the line """ + if np.allclose(a, b): + raise ValueError("Cannot determine a unique line through {a} and {b}.") x0, y0 = a x1, y1 = b