@@ -88,22 +88,24 @@ def test_contains_points_negative_radius():
88
88
np .testing .assert_equal (result , [True , False , False ])
89
89
90
90
91
- _ExampleCurve = namedtuple ('_ExampleCurve' , ['path' , 'extents' , 'area' ])
91
+ _ExampleCurve = namedtuple ('_ExampleCurve' ,
92
+ ['path' , 'extents' , 'area' , 'length' ])
92
93
_test_curves = [
93
94
# interior extrema determine extents and degenerate derivative
94
95
_ExampleCurve (Path ([[0 , 0 ], [1 , 0 ], [1 , 1 ], [0 , 1 ]],
95
96
[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 ),
97
98
# 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 )))),
101
103
# a linear curve, degenerate vertically
102
104
_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 ),
104
106
# a point
105
107
_ExampleCurve (Path ([[1 , 2 ]], [Path .MOVETO ]), extents = (1. , 2. , 1. , 2. ),
106
- area = 0. ),
108
+ area = 0. , length = 0.0 ),
107
109
]
108
110
109
111
@@ -154,6 +156,13 @@ def test_signed_area_unit_circle():
154
156
assert np .isclose (circ .signed_area (), np .pi )
155
157
156
158
159
+ @pytest .mark .parametrize ('precomputed_curve' , _test_curves )
160
+ def test_length_curve (precomputed_curve ):
161
+ path , length = precomputed_curve .path , precomputed_curve .length
162
+ assert np .isclose (path .length (rtol = 1e-5 , atol = 1e-8 ), length , rtol = 1e-5 ,
163
+ atol = 1e-8 )
164
+
165
+
157
166
def test_point_in_path_nan ():
158
167
box = np .array ([[0 , 0 ], [1 , 0 ], [1 , 1 ], [0 , 1 ], [0 , 0 ]])
159
168
p = Path (box )
0 commit comments