Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions svgpathtools/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions test/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading