11
11
12
12
#include " _path.h"
13
13
14
+ #include " py_adaptors.h"
14
15
#include " py_converters.h"
15
16
#include " py_converters_11.h"
16
- #include " py_adaptors.h"
17
17
18
18
namespace py = pybind11;
19
19
using namespace pybind11 ::literals;
@@ -33,31 +33,21 @@ convert_polygon_vector(std::vector<Polygon> &polygons)
33
33
}
34
34
35
35
static bool
36
- Py_point_in_path (double x, double y, double r, py::object path_obj ,
36
+ Py_point_in_path (double x, double y, double r, mpl::PathIterator path ,
37
37
agg::trans_affine trans)
38
38
{
39
- mpl::PathIterator path;
40
-
41
- if (!convert_path (path_obj.ptr (), &path)) {
42
- throw py::error_already_set ();
43
- }
44
-
45
39
return point_in_path (x, y, r, path, trans);
46
40
}
47
41
48
42
static py::array_t <double >
49
- Py_points_in_path (py::array_t <double > points_obj, double r, py::object path_obj ,
43
+ Py_points_in_path (py::array_t <double > points_obj, double r, mpl::PathIterator path ,
50
44
agg::trans_affine trans)
51
45
{
52
46
numpy::array_view<double , 2 > points;
53
- mpl::PathIterator path;
54
47
55
48
if (!convert_points (points_obj.ptr (), &points)) {
56
49
throw py::error_already_set ();
57
50
}
58
- if (!convert_path (path_obj.ptr (), &path)) {
59
- throw py::error_already_set ();
60
- }
61
51
62
52
if (!check_trailing_shape (points, " points" , 2 )) {
63
53
throw py::error_already_set ();
@@ -73,16 +63,11 @@ Py_points_in_path(py::array_t<double> points_obj, double r, py::object path_obj,
73
63
}
74
64
75
65
static py::tuple
76
- Py_update_path_extents (py::object path_obj , agg::trans_affine trans, agg::rect_d rect ,
77
- py::array_t <double > minpos, bool ignore)
66
+ Py_update_path_extents (mpl::PathIterator path , agg::trans_affine trans,
67
+ agg::rect_d rect, py::array_t <double > minpos, bool ignore)
78
68
{
79
- mpl::PathIterator path;
80
69
bool changed;
81
70
82
- if (!convert_path (path_obj.ptr (), &path)) {
83
- throw py::error_already_set ();
84
- }
85
-
86
71
if (minpos.ndim () != 1 ) {
87
72
throw py::value_error (
88
73
" minpos must be 1D, got " + std::to_string (minpos.ndim ()));
@@ -202,32 +187,17 @@ Py_point_in_path_collection(double x, double y, double radius,
202
187
}
203
188
204
189
static bool
205
- Py_path_in_path (py::object a_obj , agg::trans_affine atrans,
206
- py::object b_obj , agg::trans_affine btrans)
190
+ Py_path_in_path (mpl::PathIterator a , agg::trans_affine atrans,
191
+ mpl::PathIterator b , agg::trans_affine btrans)
207
192
{
208
- mpl::PathIterator a;
209
- mpl::PathIterator b;
210
-
211
- if (!convert_path (a_obj.ptr (), &a)) {
212
- throw py::error_already_set ();
213
- }
214
- if (!convert_path (b_obj.ptr (), &b)) {
215
- throw py::error_already_set ();
216
- }
217
-
218
193
return path_in_path (a, atrans, b, btrans);
219
194
}
220
195
221
196
static py::list
222
- Py_clip_path_to_rect (py::object path_obj , agg::rect_d rect, bool inside)
197
+ Py_clip_path_to_rect (mpl::PathIterator path , agg::rect_d rect, bool inside)
223
198
{
224
- mpl::PathIterator path;
225
199
std::vector<Polygon> result;
226
200
227
- if (!convert_path (path_obj.ptr (), &path)) {
228
- throw py::error_already_set ();
229
- }
230
-
231
201
clip_path_to_rect (path, rect, inside, result);
232
202
233
203
return convert_polygon_vector (result);
@@ -278,21 +248,12 @@ Py_count_bboxes_overlapping_bbox(agg::rect_d bbox, py::object bboxes_obj)
278
248
}
279
249
280
250
static bool
281
- Py_path_intersects_path (py::object p1_obj, py::object p2_obj , bool filled)
251
+ Py_path_intersects_path (mpl::PathIterator p1, mpl::PathIterator p2 , bool filled)
282
252
{
283
- mpl::PathIterator p1;
284
- mpl::PathIterator p2;
285
253
agg::trans_affine t1;
286
254
agg::trans_affine t2;
287
255
bool result;
288
256
289
- if (!convert_path (p1_obj.ptr (), &p1)) {
290
- throw py::error_already_set ();
291
- }
292
- if (!convert_path (p2_obj.ptr (), &p2)) {
293
- throw py::error_already_set ();
294
- }
295
-
296
257
result = path_intersects_path (p1, p2);
297
258
if (filled) {
298
259
if (!result) {
@@ -307,46 +268,31 @@ Py_path_intersects_path(py::object p1_obj, py::object p2_obj, bool filled)
307
268
}
308
269
309
270
static bool
310
- Py_path_intersects_rectangle (py::object path_obj , double rect_x1, double rect_y1,
271
+ Py_path_intersects_rectangle (mpl::PathIterator path , double rect_x1, double rect_y1,
311
272
double rect_x2, double rect_y2, bool filled)
312
273
{
313
- mpl::PathIterator path;
314
-
315
- if (!convert_path (path_obj.ptr (), &path)) {
316
- throw py::error_already_set ();
317
- }
318
-
319
274
return path_intersects_rectangle (path, rect_x1, rect_y1, rect_x2, rect_y2, filled);
320
275
}
321
276
322
277
static py::list
323
- Py_convert_path_to_polygons (py::object path_obj , agg::trans_affine trans,
278
+ Py_convert_path_to_polygons (mpl::PathIterator path , agg::trans_affine trans,
324
279
double width, double height, bool closed_only)
325
280
{
326
- mpl::PathIterator path;
327
281
std::vector<Polygon> result;
328
282
329
- if (!convert_path (path_obj.ptr (), &path)) {
330
- throw py::error_already_set ();
331
- }
332
-
333
283
convert_path_to_polygons (path, trans, width, height, closed_only, result);
334
284
335
285
return convert_polygon_vector (result);
336
286
}
337
287
338
288
static py::tuple
339
- Py_cleanup_path (py::object path_obj , agg::trans_affine trans, bool remove_nans,
289
+ Py_cleanup_path (mpl::PathIterator path , agg::trans_affine trans, bool remove_nans,
340
290
agg::rect_d clip_rect, py::object snap_mode_obj, double stroke_width,
341
291
std::optional<bool > simplify, bool return_curves, py::object sketch_obj)
342
292
{
343
- mpl::PathIterator path;
344
293
e_snap_mode snap_mode;
345
294
SketchParams sketch;
346
295
347
- if (!convert_path (path_obj.ptr (), &path)) {
348
- throw py::error_already_set ();
349
- }
350
296
if (!convert_snap (snap_mode_obj.ptr (), &snap_mode)) {
351
297
throw py::error_already_set ();
352
298
}
@@ -406,19 +352,16 @@ postfix : bool
406
352
)""" ;
407
353
408
354
static py::object
409
- Py_convert_to_string (py::object path_obj, agg::trans_affine trans, agg::rect_d cliprect,
410
- std::optional<bool > simplify, py::object sketch_obj, int precision,
355
+ Py_convert_to_string (mpl::PathIterator path, agg::trans_affine trans,
356
+ agg::rect_d cliprect, std::optional<bool > simplify,
357
+ py::object sketch_obj, int precision,
411
358
std::array<std::string, 5 > codes_obj, bool postfix)
412
359
{
413
- mpl::PathIterator path;
414
360
SketchParams sketch;
415
361
char *codes[5 ];
416
362
std::string buffer;
417
363
bool status;
418
364
419
- if (!convert_path (path_obj.ptr (), &path)) {
420
- throw py::error_already_set ();
421
- }
422
365
if (!convert_sketch_params (sketch_obj.ptr (), &sketch)) {
423
366
throw py::error_already_set ();
424
367
}
0 commit comments