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)) 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