@@ -88,24 +88,27 @@ 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 ),
107
109
# 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 )),
109
112
]
110
113
111
114
@@ -156,6 +159,13 @@ def test_signed_area_unit_circle():
156
159
assert np .isclose (circ .signed_area (), np .pi )
157
160
158
161
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
+
159
169
def test_point_in_path_nan ():
160
170
box = np .array ([[0 , 0 ], [1 , 0 ], [1 , 1 ], [0 , 1 ], [0 , 0 ]])
161
171
p = Path (box )
0 commit comments