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;
@@ -43,31 +43,21 @@ convert_polygon_vector(std::vector<Polygon> &polygons)
43
43
}
44
44
45
45
static bool
46
- Py_point_in_path (double x, double y, double r, py::object path_obj ,
46
+ Py_point_in_path (double x, double y, double r, mpl::PathIterator path ,
47
47
agg::trans_affine trans)
48
48
{
49
- mpl::PathIterator path;
50
-
51
- if (!convert_path (path_obj.ptr (), &path)) {
52
- throw py::error_already_set ();
53
- }
54
-
55
49
return point_in_path (x, y, r, path, trans);
56
50
}
57
51
58
52
static py::array_t <double >
59
- Py_points_in_path (py::array_t <double > points_obj, double r, py::object path_obj ,
53
+ Py_points_in_path (py::array_t <double > points_obj, double r, mpl::PathIterator path ,
60
54
agg::trans_affine trans)
61
55
{
62
56
numpy::array_view<double , 2 > points;
63
- mpl::PathIterator path;
64
57
65
58
if (!convert_points (points_obj.ptr (), &points)) {
66
59
throw py::error_already_set ();
67
60
}
68
- if (!convert_path (path_obj.ptr (), &path)) {
69
- throw py::error_already_set ();
70
- }
71
61
72
62
if (!check_trailing_shape (points, " points" , 2 )) {
73
63
throw py::error_already_set ();
@@ -83,16 +73,11 @@ Py_points_in_path(py::array_t<double> points_obj, double r, py::object path_obj,
83
73
}
84
74
85
75
static py::tuple
86
- Py_update_path_extents (py::object path_obj , agg::trans_affine trans, agg::rect_d rect ,
87
- py::array_t <double > minpos, bool ignore)
76
+ Py_update_path_extents (mpl::PathIterator path , agg::trans_affine trans,
77
+ agg::rect_d rect, py::array_t <double > minpos, bool ignore)
88
78
{
89
- mpl::PathIterator path;
90
79
bool changed;
91
80
92
- if (!convert_path (path_obj.ptr (), &path)) {
93
- throw py::error_already_set ();
94
- }
95
-
96
81
if (minpos.ndim () != 1 ) {
97
82
throw py::value_error (
98
83
" minpos must be of 1D, got " + std::to_string (minpos.ndim ()));
@@ -216,32 +201,17 @@ Py_point_in_path_collection(double x, double y, double radius,
216
201
}
217
202
218
203
static bool
219
- Py_path_in_path (py::object a_obj , agg::trans_affine atrans,
220
- py::object b_obj , agg::trans_affine btrans)
204
+ Py_path_in_path (mpl::PathIterator a , agg::trans_affine atrans,
205
+ mpl::PathIterator b , agg::trans_affine btrans)
221
206
{
222
- mpl::PathIterator a;
223
- mpl::PathIterator b;
224
-
225
- if (!convert_path (a_obj.ptr (), &a)) {
226
- throw py::error_already_set ();
227
- }
228
- if (!convert_path (b_obj.ptr (), &b)) {
229
- throw py::error_already_set ();
230
- }
231
-
232
207
return path_in_path (a, atrans, b, btrans);
233
208
}
234
209
235
210
static py::object
236
- Py_clip_path_to_rect (py::object path_obj , agg::rect_d rect, bool inside)
211
+ Py_clip_path_to_rect (mpl::PathIterator path , agg::rect_d rect, bool inside)
237
212
{
238
- mpl::PathIterator path;
239
213
std::vector<Polygon> result;
240
214
241
- if (!convert_path (path_obj.ptr (), &path)) {
242
- throw py::error_already_set ();
243
- }
244
-
245
215
clip_path_to_rect (path, rect, inside, result);
246
216
247
217
return convert_polygon_vector (result);
@@ -292,21 +262,12 @@ Py_count_bboxes_overlapping_bbox(agg::rect_d bbox, py::object bboxes_obj)
292
262
}
293
263
294
264
static bool
295
- Py_path_intersects_path (py::object p1_obj, py::object p2_obj , bool filled)
265
+ Py_path_intersects_path (mpl::PathIterator p1, mpl::PathIterator p2 , bool filled)
296
266
{
297
- mpl::PathIterator p1;
298
- mpl::PathIterator p2;
299
267
agg::trans_affine t1;
300
268
agg::trans_affine t2;
301
269
bool result;
302
270
303
- if (!convert_path (p1_obj.ptr (), &p1)) {
304
- throw py::error_already_set ();
305
- }
306
- if (!convert_path (p2_obj.ptr (), &p2)) {
307
- throw py::error_already_set ();
308
- }
309
-
310
271
result = path_intersects_path (p1, p2);
311
272
if (filled) {
312
273
if (!result) {
@@ -321,46 +282,31 @@ Py_path_intersects_path(py::object p1_obj, py::object p2_obj, bool filled)
321
282
}
322
283
323
284
static bool
324
- Py_path_intersects_rectangle (py::object path_obj , double rect_x1, double rect_y1,
285
+ Py_path_intersects_rectangle (mpl::PathIterator path , double rect_x1, double rect_y1,
325
286
double rect_x2, double rect_y2, bool filled)
326
287
{
327
- mpl::PathIterator path;
328
-
329
- if (!convert_path (path_obj.ptr (), &path)) {
330
- throw py::error_already_set ();
331
- }
332
-
333
288
return path_intersects_rectangle (path, rect_x1, rect_y1, rect_x2, rect_y2, filled);
334
289
}
335
290
336
291
static py::object
337
- Py_convert_path_to_polygons (py::object path_obj , agg::trans_affine trans,
292
+ Py_convert_path_to_polygons (mpl::PathIterator path , agg::trans_affine trans,
338
293
double width, double height, bool closed_only)
339
294
{
340
- mpl::PathIterator path;
341
295
std::vector<Polygon> result;
342
296
343
- if (!convert_path (path_obj.ptr (), &path)) {
344
- throw py::error_already_set ();
345
- }
346
-
347
297
convert_path_to_polygons (path, trans, width, height, closed_only, result);
348
298
349
299
return convert_polygon_vector (result);
350
300
}
351
301
352
302
static py::tuple
353
- Py_cleanup_path (py::object path_obj , agg::trans_affine trans, bool remove_nans,
303
+ Py_cleanup_path (mpl::PathIterator path , agg::trans_affine trans, bool remove_nans,
354
304
agg::rect_d clip_rect, py::object snap_mode_obj, double stroke_width,
355
305
std::optional<bool > simplify, bool return_curves, py::object sketch_obj)
356
306
{
357
- mpl::PathIterator path;
358
307
e_snap_mode snap_mode;
359
308
SketchParams sketch;
360
309
361
- if (!convert_path (path_obj.ptr (), &path)) {
362
- throw py::error_already_set ();
363
- }
364
310
if (!convert_snap (snap_mode_obj.ptr (), &snap_mode)) {
365
311
throw py::error_already_set ();
366
312
}
@@ -423,19 +369,16 @@ postfix : bool
423
369
)""" ;
424
370
425
371
static py::object
426
- Py_convert_to_string (py::object path_obj, agg::trans_affine trans, agg::rect_d cliprect,
427
- std::optional<bool > simplify, py::object sketch_obj, int precision,
372
+ Py_convert_to_string (mpl::PathIterator path, agg::trans_affine trans,
373
+ agg::rect_d cliprect, std::optional<bool > simplify,
374
+ py::object sketch_obj, int precision,
428
375
std::array<std::string, 5 > codes_obj, bool postfix)
429
376
{
430
- mpl::PathIterator path;
431
377
SketchParams sketch;
432
378
char *codes[5 ];
433
379
std::string buffer;
434
380
bool status;
435
381
436
- if (!convert_path (path_obj.ptr (), &path)) {
437
- throw py::error_already_set ();
438
- }
439
382
if (!convert_sketch_params (sketch_obj.ptr (), &sketch)) {
440
383
throw py::error_already_set ();
441
384
}
0 commit comments