@@ -88,24 +88,27 @@ def test_contains_points_negative_radius():
8888 np .testing .assert_equal (result , [True , False , False ])
8989
9090
91- _ExampleCurve = namedtuple ('_ExampleCurve' , ['path' , 'extents' , 'area' ])
91+ _ExampleCurve = namedtuple ('_ExampleCurve' ,
92+ ['path' , 'extents' , 'area' , 'length' ])
9293_test_curves = [
9394 # interior extrema determine extents and degenerate derivative
9495 _ExampleCurve (Path ([[0 , 0 ], [1 , 0 ], [1 , 1 ], [0 , 1 ]],
9596 [Path .MOVETO , Path .CURVE4 , Path .CURVE4 , Path .CURVE4 ]),
96- extents = (0. , 0. , 0.75 , 1. ), area = 0.6 ),
97+ extents = (0. , 0. , 0.75 , 1. ), area = 0.6 , length = 2.0 ),
9798 # a quadratic curve, clockwise
98- _ExampleCurve (Path ([[0 , 0 ], [0 , 1 ], [1 , 0 ]],
99- [Path .MOVETO , Path .CURVE3 , Path .CURVE3 ]),
100- extents = (0. , 0. , 1. , 0.5 ), area = - 1 / 3 ),
99+ _ExampleCurve (Path ([[0 , 0 ], [0 , 1 ], [1 , 0 ]], [Path .MOVETO , Path .CURVE3 ,
100+ Path .CURVE3 ]), extents = (0. , 0. , 1. , 0.5 ), area = - 1 / 3 ,
101+ length = (1 / 25 )* (10 + 15 * np .sqrt (2 ) + np .sqrt (5 )
102+ * (np .arcsinh (2 ) + np .arcsinh (3 )))),
101103 # a linear curve, degenerate vertically
102104 _ExampleCurve (Path ([[0 , 1 ], [1 , 1 ]], [Path .MOVETO , Path .LINETO ]),
103- extents = (0. , 1. , 1. , 1. ), area = 0. ),
105+ extents = (0. , 1. , 1. , 1. ), area = 0. , length = 1.0 ),
104106 # a point
105107 _ExampleCurve (Path ([[1 , 2 ]], [Path .MOVETO ]), extents = (1. , 2. , 1. , 2. ),
106- area = 0. ),
108+ area = 0. , length = 0 ),
107109 # non-curved triangle
108- _ExampleCurve (Path ([(1 , 1 ), (2 , 1 ), (1.5 , 2 )]), extents = (1 , 1 , 2 , 2 ), area = 0.5 ),
110+ _ExampleCurve (Path ([(1 , 1 ), (2 , 1 ), (1.5 , 2 )]), extents = (1 , 1 , 2 , 2 ),
111+ area = 0.5 , length = 1 + np .sqrt (0.5 ** 2 + 1 )),
109112]
110113
111114
@@ -156,6 +159,13 @@ def test_signed_area_unit_circle():
156159 assert np .isclose (circ .signed_area (), np .pi )
157160
158161
162+ @pytest .mark .parametrize ('precomputed_curve' , _test_curves )
163+ def test_length_curve (precomputed_curve ):
164+ path , length = precomputed_curve .path , precomputed_curve .length
165+ np .testing .assert_allclose (path .length (rtol = 1e-5 , atol = 1e-8 ), length ,
166+ rtol = 1e-5 , atol = 1e-8 )
167+
168+
159169def test_point_in_path_nan ():
160170 box = np .array ([[0 , 0 ], [1 , 0 ], [1 , 1 ], [0 , 1 ], [0 , 0 ]])
161171 p = Path (box )
0 commit comments