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