From f170ccc73df4998480cf972451589a283748f60d Mon Sep 17 00:00:00 2001 From: derVedro Date: Wed, 26 Nov 2025 23:42:19 +0100 Subject: [PATCH 1/2] fixed wrong length of flat quadratic bezier --- svgpathtools/path.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/svgpathtools/path.py b/svgpathtools/path.py index 434aef5..9aebf33 100644 --- a/svgpathtools/path.py +++ b/svgpathtools/path.py @@ -957,10 +957,11 @@ def length(self, t0=0, t1=1, error=None, min_depth=None): dq1_mag = sqrt(c2 * t1 ** 2 + c1 * t1 + c0) dq0_mag = sqrt(c2 * t0 ** 2 + c1 * t0 + c0) - logarand = (sqrt(c2) * (t1 + beta) + dq1_mag) / \ - (sqrt(c2) * (t0 + beta) + dq0_mag) + rand_num = sqrt(c2) * (t1 + beta) + dq1_mag + rand_den = sqrt(c2) * (t0 + beta) + dq0_mag + logarand = log(rand_num / rand_den) if rand_den != 0 else 0 s = (t1 + beta) * dq1_mag - (t0 + beta) * dq0_mag + \ - gamma * sqrt(c2) * log(logarand) + gamma * sqrt(c2) * logarand s /= 2 if isnan(s): tstar = abs(b) / (2 * abs(a)) From c70849bde347944b3860a314004b106fec0e09b7 Mon Sep 17 00:00:00 2001 From: derVedro Date: Wed, 26 Nov 2025 23:43:02 +0100 Subject: [PATCH 2/2] test for flat quadratic bezier --- test/test_path.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test_path.py b/test/test_path.py index 7a72e32..762c53a 100644 --- a/test/test_path.py +++ b/test/test_path.py @@ -500,6 +500,11 @@ def test_length(self): for t0, t1, exp_s in tests: self.assertAlmostEqual(linq2.length(t0=t0, t1=t1), exp_s, delta=TOL) + # flat quadratic bezier curve should be almost as long as a straight line + flat_quad_bez = QuadraticBezier(start=46 + 125j, control=45.8 + 124.6j, end=45.7 + 124.4j) + line = Line(start=46 + 125j, end=45.7 + 124.4j) + self.assertAlmostEqual(flat_quad_bez.length(), line.length(), delta=TOL) + def test_equality(self): # This is to test the __eq__ and __ne__ methods, so we can't use # assertEqual and assertNotEqual