| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d114237 commit f529327
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -922,22 +922,6 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc, | |||
| 922 | 922 | typedef agg::conv_curve<snapped_t> snapped_curve_t; | |
| 923 | 923 | typedef agg::conv_curve<clipped_t> curve_t; | |
| 924 | 924 | ||
| 925 | - if (offsets.dim(0) != 0 && offsets.dim(1) != 2) { | ||
| 926 | - throw "Offsets array must be Nx2 or empty"; | ||
| 927 | - } | ||
| 928 | - | ||
| 929 | - if (facecolors.dim(0) != 0 && facecolors.dim(1) != 4) { | ||
| 930 | - throw "Facecolors array must be a Nx4 array or empty"; | ||
| 931 | - } | ||
| 932 | - | ||
| 933 | - if (edgecolors.dim(0) != 0 && edgecolors.dim(1) != 4) { | ||
| 934 | - throw "Edgecolors array must by Nx4 or empty"; | ||
| 935 | - } | ||
| 936 | - | ||
| 937 | - if (transforms.dim(0) != 0 && (transforms.dim(1) != 3 || transforms.dim(2) != 3)) { | ||
| 938 | - throw "Transforms array must by Nx3x3 or empty"; | ||
| 939 | - } | ||
| 940 | - | ||
| 941 | 925 | size_t Npaths = path_generator.num_paths(); | |
| 942 | 926 | size_t Noffsets = offsets.size(); | |
| 943 | 927 | size_t N = std::max(Npaths, Noffsets); | |
@@ -1266,14 +1250,6 @@ inline void RendererAgg::draw_gouraud_triangle(GCAgg &gc, | |||
| 1266 | 1250 | set_clipbox(gc.cliprect, theRasterizer); | |
| 1267 | 1251 | bool has_clippath = render_clippath(gc.clippath.path, gc.clippath.trans); | |
| 1268 | 1252 | ||
| 1269 | - if (points.dim(0) != 3 || points.dim(1) != 2) { | ||
| 1270 | - throw "points must be a 3x2 array"; | ||
| 1271 | - } | ||
| 1272 | - | ||
| 1273 | - if (colors.dim(0) != 3 || colors.dim(1) != 4) { | ||
| 1274 | - throw "colors must be a 3x4 array"; | ||
| 1275 | - } | ||
| 1276 | - | ||
| 1277 | 1253 | _draw_gouraud_triangle(points, colors, trans, has_clippath); | |
| 1278 | 1254 | } | |
| 1279 | 1255 | ||
@@ -1288,18 +1264,6 @@ inline void RendererAgg::draw_gouraud_triangles(GCAgg &gc, | |||
| 1288 | 1264 | set_clipbox(gc.cliprect, theRasterizer); | |
| 1289 | 1265 | bool has_clippath = render_clippath(gc.clippath.path, gc.clippath.trans); | |
| 1290 | 1266 | ||
| 1291 | - if (points.dim(1) != 3 || points.dim(2) != 2) { | ||
| 1292 | - throw "points must be a Nx3x2 array"; | ||
| 1293 | - } | ||
| 1294 | - | ||
| 1295 | - if (colors.dim(1) != 3 || colors.dim(2) != 4) { | ||
| 1296 | - throw "colors must be a Nx3x4 array"; | ||
| 1297 | - } | ||
| 1298 | - | ||
| 1299 | - if (points.dim(0) != colors.dim(0)) { | ||
| 1300 | - throw "points and colors arrays must be the same length"; | ||
| 1301 | - } | ||
| 1302 | - | ||
| 1303 | 1267 | for (int i = 0; i < points.dim(0); ++i) { | |
| 1304 | 1268 | typename PointArray::sub_t point = points[i]; | |
| 1305 | 1269 | typename ColorArray::sub_t color = colors[i]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -340,15 +340,15 @@ PyRendererAgg_draw_path_collection(PyRendererAgg *self, PyObject *args, PyObject | |||
| 340 | 340 | &convert_trans_affine, | |
| 341 | 341 | &master_transform, | |
| 342 | 342 | &pathobj, | |
| 343 | - &transforms.converter, | ||
| 343 | + &convert_transforms, | ||
| 344 | 344 | &transforms, | |
| 345 | - &offsets.converter, | ||
| 345 | + &convert_points, | ||
| 346 | 346 | &offsets, | |
| 347 | 347 | &convert_trans_affine, | |
| 348 | 348 | &offset_trans, | |
| 349 | - &facecolors.converter, | ||
| 349 | + &convert_colors, | ||
| 350 | 350 | &facecolors, | |
| 351 | - &edgecolors.converter, | ||
| 351 | + &convert_colors, | ||
| 352 | 352 | &edgecolors, | |
| 353 | 353 | &linewidths.converter, | |
| 354 | 354 | &linewidths, | |
@@ -411,14 +411,14 @@ static PyObject *PyRendererAgg_draw_quad_mesh(PyRendererAgg *self, PyObject *arg | |||
| 411 | 411 | &mesh_height, | |
| 412 | 412 | &coordinates.converter, | |
| 413 | 413 | &coordinates, | |
| 414 | - &offsets.converter, | ||
| 414 | + &convert_points, | ||
| 415 | 415 | &offsets, | |
| 416 | 416 | &convert_trans_affine, | |
| 417 | 417 | &offset_trans, | |
| 418 | - &facecolors.converter, | ||
| 418 | + &convert_colors, | ||
| 419 | 419 | &facecolors, | |
| 420 | 420 | &antialiased, | |
| 421 | - &edgecolors.converter, | ||
| 421 | + &convert_colors, | ||
| 422 | 422 | &edgecolors)) { | |
| 423 | 423 | return NULL; | |
| 424 | 424 | } | |
@@ -459,6 +459,21 @@ PyRendererAgg_draw_gouraud_triangle(PyRendererAgg *self, PyObject *args, PyObjec | |||
| 459 | 459 | return NULL; | |
| 460 | 460 | } | |
| 461 | 461 | ||
| 462 | + if (points.dim(0) != 3 || points.dim(1) != 2) { | ||
| 463 | + PyErr_Format(PyExc_ValueError, | ||
| 464 | + "points must be a 3x2 array, got %dx%d", | ||
| 465 | + points.dim(0), points.dim(1)); | ||
| 466 | + return NULL; | ||
| 467 | + } | ||
| 468 | + | ||
| 469 | + if (colors.dim(0) != 3 || colors.dim(1) != 4) { | ||
| 470 | + PyErr_Format(PyExc_ValueError, | ||
| 471 | + "colors must be a 3x4 array, got %dx%d", | ||
| 472 | + colors.dim(0), colors.dim(1)); | ||
| 473 | + return NULL; | ||
| 474 | + } | ||
| 475 | + | ||
| 476 | + | ||
| 462 | 477 | CALL_CPP("draw_gouraud_triangle", (self->x->draw_gouraud_triangle(gc, points, colors, trans))); | |
| 463 | 478 | ||
| 464 | 479 | Py_RETURN_NONE; | |
@@ -485,6 +500,27 @@ PyRendererAgg_draw_gouraud_triangles(PyRendererAgg *self, PyObject *args, PyObje | |||
| 485 | 500 | return NULL; | |
| 486 | 501 | } | |
| 487 | 502 | ||
| 503 | + if (points.size() != 0 && (points.dim(1) != 3 || points.dim(2) != 2)) { | ||
| 504 | + PyErr_Format(PyExc_ValueError, | ||
| 505 | + "points must be a Nx3x2 array, got %dx%dx%d", | ||
| 506 | + points.dim(0), points.dim(1), points.dim(2)); | ||
| 507 | + return NULL; | ||
| 508 | + } | ||
| 509 | + | ||
| 510 | + if (colors.size() != 0 && (colors.dim(1) != 3 || colors.dim(2) != 4)) { | ||
| 511 | + PyErr_Format(PyExc_ValueError, | ||
| 512 | + "colors must be a Nx3x4 array, got %dx%dx%d", | ||
| 513 | + colors.dim(0), colors.dim(1), colors.dim(2)); | ||
| 514 | + return NULL; | ||
| 515 | + } | ||
| 516 | + | ||
| 517 | + if (points.size() != colors.size()) { | ||
| 518 | + PyErr_Format(PyExc_ValueError, | ||
| 519 | + "points and colors arrays must be the same length, got %d and %d", | ||
| 520 | + points.dim(0), colors.dim(0)); | ||
| 521 | + return NULL; | ||
| 522 | + } | ||
| 523 | + | ||
| 488 | 524 | CALL_CPP("draw_gouraud_triangles", self->x->draw_gouraud_triangles(gc, points, colors, trans)); | |
| 489 | 525 | ||
| 490 | 526 | Py_RETURN_NONE; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -358,7 +358,7 @@ void get_path_collection_extents(agg::trans_affine &master_transform, | |||
| 358 | 358 | agg::trans_affine &offset_trans, | |
| 359 | 359 | extent_limits &extent) | |
| 360 | 360 | { | |
| 361 | - if (offsets.dim(0) != 0 && offsets.dim(1) != 2) { | ||
| 361 | + if (offsets.size() != 0 && offsets.dim(1) != 2) { | ||
| 362 | 362 | throw "Offsets array must be Nx2"; | |
| 363 | 363 | } | |
| 364 | 364 | ||
@@ -416,7 +416,7 @@ void point_in_path_collection(double x, | |||
| 416 | 416 | return; | |
| 417 | 417 | } | |
| 418 | 418 | ||
| 419 | - size_t Noffsets = offsets.dim(0); | ||
| 419 | + size_t Noffsets = offsets.size(); | ||
| 420 | 420 | size_t N = std::max(Npaths, Noffsets); | |
| 421 | 421 | size_t Ntransforms = std::min(transforms.size(), N); | |
| 422 | 422 | size_t i; | |
@@ -692,11 +692,11 @@ clip_path_to_rect(PathIterator &path, agg::rect_d &rect, bool inside, std::vecto | |||
| 692 | 692 | template <class VerticesArray, class ResultArray> | |
| 693 | 693 | void affine_transform_2d(VerticesArray &vertices, agg::trans_affine &trans, ResultArray &result) | |
| 694 | 694 | { | |
| 695 | - if (vertices.dim(0) != 0 && vertices.dim(1) != 2) { | ||
| 695 | + if (vertices.size() != 0 && vertices.dim(1) != 2) { | ||
| 696 | 696 | throw "Invalid vertices array."; | |
| 697 | 697 | } | |
| 698 | 698 | ||
| 699 | - size_t n = vertices.dim(0); | ||
| 699 | + size_t n = vertices.size(); | ||
| 700 | 700 | double x; | |
| 701 | 701 | double y; | |
| 702 | 702 | double t0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,7 +69,7 @@ static PyObject *Py_points_in_path(PyObject *self, PyObject *args, PyObject *kwd | |||
| 69 | 69 | ||
| 70 | 70 | if (!PyArg_ParseTuple(args, | |
| 71 | 71 | "O&dO&O&:points_in_path", | |
| 72 | - &points.converter, | ||
| 72 | + &convert_points, | ||
| 73 | 73 | &points, | |
| 74 | 74 | &r, | |
| 75 | 75 | &convert_path, | |
@@ -79,7 +79,7 @@ static PyObject *Py_points_in_path(PyObject *self, PyObject *args, PyObject *kwd | |||
| 79 | 79 | return NULL; | |
| 80 | 80 | } | |
| 81 | 81 | ||
| 82 | - npy_intp dims[] = { points.dim(0) }; | ||
| 82 | + npy_intp dims[] = { points.size() }; | ||
| 83 | 83 | numpy::array_view<bool, 1> results(dims); | |
| 84 | 84 | ||
| 85 | 85 | CALL_CPP("points_in_path", (points_in_path(points, r, path, trans, results))); | |
@@ -128,7 +128,7 @@ static PyObject *Py_points_on_path(PyObject *self, PyObject *args, PyObject *kwd | |||
| 128 | 128 | ||
| 129 | 129 | if (!PyArg_ParseTuple(args, | |
| 130 | 130 | "O&dO&O&:points_on_path", | |
| 131 | - &points.converter, | ||
| 131 | + &convert_points, | ||
| 132 | 132 | &points, | |
| 133 | 133 | &r, | |
| 134 | 134 | &convert_path, | |
@@ -138,7 +138,7 @@ static PyObject *Py_points_on_path(PyObject *self, PyObject *args, PyObject *kwd | |||
| 138 | 138 | return NULL; | |
| 139 | 139 | } | |
| 140 | 140 | ||
| 141 | - npy_intp dims[] = { points.dim(0) }; | ||
| 141 | + npy_intp dims[] = { points.size() }; | ||
| 142 | 142 | numpy::array_view<bool, 1> results(dims); | |
| 143 | 143 | ||
| 144 | 144 | CALL_CPP("points_on_path", (points_on_path(points, r, path, trans, results))); | |
@@ -200,7 +200,10 @@ static PyObject *Py_update_path_extents(PyObject *self, PyObject *args, PyObject | |||
| 200 | 200 | } | |
| 201 | 201 | ||
| 202 | 202 | if (minpos.dim(0) != 2) { | |
| 203 | - PyErr_SetString(PyExc_ValueError, "minpos must be of length 2"); | ||
| 203 | + PyErr_Format(PyExc_ValueError, | ||
| 204 | + "minpos must be of length 2, got %d", | ||
| 205 | + minpos.dim(0)); | ||
| 206 | + return NULL; | ||
| 204 | 207 | } | |
| 205 | 208 | ||
| 206 | 209 | extent_limits e; | |
@@ -263,9 +266,9 @@ static PyObject *Py_get_path_collection_extents(PyObject *self, PyObject *args, | |||
| 263 | 266 | &convert_trans_affine, | |
| 264 | 267 | &master_transform, | |
| 265 | 268 | &pathsobj, | |
| 266 | - &transforms.converter, | ||
| 269 | + &convert_transforms, | ||
| 267 | 270 | &transforms, | |
| 268 | - &offsets.converter, | ||
| 271 | + &convert_points, | ||
| 269 | 272 | &offsets, | |
| 270 | 273 | &convert_trans_affine, | |
| 271 | 274 | &offset_trans)) { | |
@@ -319,9 +322,9 @@ static PyObject *Py_point_in_path_collection(PyObject *self, PyObject *args, PyO | |||
| 319 | 322 | &convert_trans_affine, | |
| 320 | 323 | &master_transform, | |
| 321 | 324 | &pathsobj, | |
| 322 | - &transforms.converter, | ||
| 325 | + &convert_transforms, | ||
| 323 | 326 | &transforms, | |
| 324 | - &offsets.converter, | ||
| 327 | + &convert_points, | ||
| 325 | 328 | &offsets, | |
| 326 | 329 | &convert_trans_affine, | |
| 327 | 330 | &offset_trans, | |
@@ -434,15 +437,15 @@ static PyObject *Py_affine_transform(PyObject *self, PyObject *args, PyObject *k | |||
| 434 | 437 | ||
| 435 | 438 | try { | |
| 436 | 439 | numpy::array_view<double, 2> vertices(vertices_obj); | |
| 437 | - npy_intp dims[] = { vertices.dim(0), 2 }; | ||
| 440 | + npy_intp dims[] = { vertices.size(), 2 }; | ||
| 438 | 441 | numpy::array_view<double, 2> result(dims); | |
| 439 | 442 | CALL_CPP("affine_transform", (affine_transform_2d(vertices, trans, result))); | |
| 440 | 443 | return result.pyobj(); | |
| 441 | 444 | } catch (py::exception) { | |
| 442 | 445 | PyErr_Clear(); | |
| 443 | 446 | try { | |
| 444 | 447 | numpy::array_view<double, 1> vertices(vertices_obj); | |
| 445 | - npy_intp dims[] = { vertices.dim(0) }; | ||
| 448 | + npy_intp dims[] = { vertices.size() }; | ||
| 446 | 449 | numpy::array_view<double, 1> result(dims); | |
| 447 | 450 | CALL_CPP("affine_transform", (affine_transform_1d(vertices, trans, result))); | |
| 448 | 451 | return result.pyobj(); | |
@@ -464,7 +467,7 @@ static PyObject *Py_count_bboxes_overlapping_bbox(PyObject *self, PyObject *args | |||
| 464 | 467 | "O&O&:count_bboxes_overlapping_bbox", | |
| 465 | 468 | &convert_rect, | |
| 466 | 469 | &bbox, | |
| 467 | - &bboxes.converter, | ||
| 470 | + &convert_bboxes, | ||
| 468 | 471 | &bboxes)) { | |
| 469 | 472 | return NULL; | |
| 470 | 473 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -479,9 +479,23 @@ class array_view : public detail::array_view_accessors<array_view, T, ND> | |||
| 479 | 479 | return m_shape[i]; | |
| 480 | 480 | } | |
| 481 | 481 | ||
| 482 | + /* | ||
| 483 | + In most cases, code should use size() instead of dim(0), since | ||
| 484 | + size() == 0 when any dimension is 0. | ||
| 485 | + */ | ||
| 482 | 486 | size_t size() const | |
| 483 | 487 | { | |
| 484 | - return (size_t)dim(0); | ||
| 488 | + bool empty = (ND == 0); | ||
| 489 | + for (size_t i = 0; i < ND; i++) { | ||
| 490 | + if (m_shape[i] == 0) { | ||
| 491 | + empty = true; | ||
| 492 | + } | ||
| 493 | + } | ||
| 494 | + if (empty) { | ||
| 495 | + return 0; | ||
| 496 | + } else { | ||
| 497 | + return (size_t)dim(0); | ||
| 498 | + } | ||
| 485 | 499 | } | |
| 486 | 500 | ||
| 487 | 501 | bool empty() const | |
| Back | FazBrowse Home | New Git URL |
0 commit comments