1818
1919#include " path_converters.h"
2020#include " _backend_agg_basic_types.h"
21+ #include " numpy_cpp.h"
2122
2223struct XY
2324{
@@ -79,7 +80,7 @@ struct XY
7980template <class PathIterator , class PointArray , class ResultArray >
8081void point_in_path_impl (PointArray &points, PathIterator &path, ResultArray &inside_flag)
8182{
82- bool yflag1;
83+ uint8_t yflag1;
8384 double vtx0, vty0, vtx1, vty1;
8485 double tx, ty;
8586 double sx, sy;
@@ -89,13 +90,13 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins
8990
9091 size_t n = points.size ();
9192
92- std::vector<bool > yflag0 (n);
93- std::vector<bool > subpath_flag (n);
93+ std::vector<uint8_t > yflag0 (n);
94+ std::vector<uint8_t > subpath_flag (n);
9495
9596 path.rewind (0 );
9697
9798 for (i = 0 ; i < n; ++i) {
98- inside_flag[i] = false ;
99+ inside_flag[i] = 0 ;
99100 }
100101
101102 unsigned code = 0 ;
@@ -112,13 +113,13 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins
112113 sy = vty0 = vty1 = y;
113114
114115 for (i = 0 ; i < n; ++i) {
115- ty = points[i][ 1 ] ;
116+ ty = points (i, 1 ) ;
116117
117118 if (std::isfinite (ty)) {
118119 // get test bit for above/below X axis
119120 yflag0[i] = (vty0 >= ty);
120121
121- subpath_flag[i] = false ;
122+ subpath_flag[i] = 0 ;
122123 }
123124 }
124125
@@ -135,8 +136,8 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins
135136 }
136137
137138 for (i = 0 ; i < n; ++i) {
138- tx = points[i][ 0 ] ;
139- ty = points[i][ 1 ] ;
139+ tx = points (i, 0 ) ;
140+ ty = points (i, 1 ) ;
140141
141142 if (!(std::isfinite (tx) && std::isfinite (ty))) {
142143 continue ;
@@ -164,7 +165,7 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins
164165 // Haigh-Hutchinson's different polygon inclusion
165166 // tests.
166167 if (((vty1 - ty) * (vtx0 - vtx1) >= (vtx1 - tx) * (vty0 - vty1)) == yflag1) {
167- subpath_flag[i] = subpath_flag[i] ^ true ;
168+ subpath_flag[i] ^= 1 ;
168169 }
169170 }
170171
@@ -183,8 +184,8 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins
183184
184185 all_done = true ;
185186 for (i = 0 ; i < n; ++i) {
186- tx = points[i][ 0 ] ;
187- ty = points[i][ 1 ] ;
187+ tx = points (i, 0 ) ;
188+ ty = points (i, 1 ) ;
188189
189190 if (!(std::isfinite (tx) && std::isfinite (ty))) {
190191 continue ;
@@ -196,8 +197,8 @@ void point_in_path_impl(PointArray &points, PathIterator &path, ResultArray &ins
196197 subpath_flag[i] = subpath_flag[i] ^ true ;
197198 }
198199 }
199- inside_flag[i] = inside_flag[i] || subpath_flag[i];
200- if (inside_flag[i] == false ) {
200+ inside_flag[i] |= subpath_flag[i];
201+ if (inside_flag[i] == 0 ) {
201202 all_done = false ;
202203 }
203204 }
@@ -232,21 +233,23 @@ inline void points_in_path(PointArray &points,
232233 transformed_path_t trans_path (path, trans);
233234 no_nans_t no_nans_path (trans_path, true , path.has_curves ());
234235 curve_t curved_path (no_nans_path);
235- contour_t contoured_path (curved_path);
236- contoured_path.width (r);
237-
238- point_in_path_impl (points, contoured_path, result);
236+ if (r != 0.0 ) {
237+ contour_t contoured_path (curved_path);
238+ contoured_path.width (r);
239+ point_in_path_impl (points, contoured_path, result);
240+ } else {
241+ point_in_path_impl (points, curved_path, result);
242+ }
239243}
240244
241245template <class PathIterator >
242246inline bool point_in_path (
243247 double x, double y, const double r, PathIterator &path, agg::trans_affine &trans)
244248{
245- std::vector<double > point;
246- std::vector<std::vector<double > > points;
247- point.push_back (x);
248- point.push_back (y);
249- points.push_back (point);
249+ npy_intp shape[] = {1 , 2 };
250+ numpy::array_view<double , 2 > points (shape);
251+ points (0 , 0 ) = x;
252+ points (0 , 1 ) = y;
250253
251254 int result[1 ];
252255 result[0 ] = 0 ;
@@ -285,11 +288,10 @@ template <class PathIterator>
285288inline bool point_on_path (
286289 double x, double y, const double r, PathIterator &path, agg::trans_affine &trans)
287290{
288- std::vector<double > point;
289- std::vector<std::vector<double > > points;
290- point.push_back (x);
291- point.push_back (y);
292- points.push_back (point);
291+ npy_intp shape[] = {1 , 2 };
292+ numpy::array_view<double , 2 > points (shape);
293+ points (0 , 0 ) = x;
294+ points (0 , 1 ) = y;
293295
294296 int result[1 ];
295297 result[0 ] = 0 ;
@@ -385,13 +387,13 @@ void get_path_collection_extents(agg::trans_affine &master_transform,
385387 for (i = 0 ; i < N; ++i) {
386388 typename PathGenerator::path_iterator path (paths (i % Npaths));
387389 if (Ntransforms) {
388- typename TransformArray:: sub_t subtrans = transforms[ i % Ntransforms] ;
389- trans = agg::trans_affine (subtrans ( 0 , 0 ),
390- subtrans ( 1 , 0 ),
391- subtrans ( 0 , 1 ),
392- subtrans ( 1 , 1 ),
393- subtrans ( 0 , 2 ),
394- subtrans ( 1 , 2 ));
390+ size_t ti = i % Ntransforms;
391+ trans = agg::trans_affine (transforms (ti, 0 , 0 ),
392+ transforms (ti, 1 , 0 ),
393+ transforms (ti, 0 , 1 ),
394+ transforms (ti, 1 , 1 ),
395+ transforms (ti, 0 , 2 ),
396+ transforms (ti, 1 , 2 ));
395397 } else {
396398 trans = master_transform;
397399 }
@@ -437,13 +439,13 @@ void point_in_path_collection(double x,
437439 typename PathGenerator::path_iterator path = paths (i % Npaths);
438440
439441 if (Ntransforms) {
440- typename TransformArray:: sub_t subtrans = transforms[ i % Ntransforms] ;
441- trans = agg::trans_affine (subtrans ( 0 , 0 ),
442- subtrans ( 1 , 0 ),
443- subtrans ( 0 , 1 ),
444- subtrans ( 1 , 1 ),
445- subtrans ( 0 , 2 ),
446- subtrans ( 1 , 2 ));
442+ size_t ti = i % Ntransforms;
443+ trans = agg::trans_affine (transforms (ti, 0 , 0 ),
444+ transforms (ti, 1 , 0 ),
445+ transforms (ti, 0 , 1 ),
446+ transforms (ti, 1 , 1 ),
447+ transforms (ti, 0 , 2 ),
448+ transforms (ti, 1 , 2 ));
447449 trans *= master_transform;
448450 } else {
449451 trans = master_transform;
@@ -771,8 +773,7 @@ int count_bboxes_overlapping_bbox(agg::rect_d &a, BBoxArray &bboxes)
771773
772774 size_t num_bboxes = bboxes.size ();
773775 for (size_t i = 0 ; i < num_bboxes; ++i) {
774- typename BBoxArray::sub_t bbox_b = bboxes[i];
775- b = agg::rect_d (bbox_b (0 , 0 ), bbox_b (0 , 1 ), bbox_b (1 , 0 ), bbox_b (1 , 1 ));
776+ b = agg::rect_d (bboxes (i, 0 , 0 ), bboxes (i, 0 , 1 ), bboxes (i, 1 , 0 ), bboxes (i, 1 , 1 ));
776777
777778 if (b.x2 < b.x1 ) {
778779 std::swap (b.x1 , b.x2 );
0 commit comments