@@ -100,17 +100,18 @@ class PathIterator {
100
100
Py::Object vertices_obj = path_obj.getAttr (" vertices" );
101
101
Py::Object codes_obj = path_obj.getAttr (" codes" );
102
102
103
- vertices = (PyArrayObject*)PyArray_ContiguousFromObject
103
+ vertices = (PyArrayObject*)PyArray_FromObject
104
104
(vertices_obj.ptr (), PyArray_DOUBLE, 2 , 2 );
105
105
if (!vertices || vertices->nd != 2 || vertices->dimensions [1 ] != 2 )
106
106
throw Py::ValueError (" Invalid vertices array." );
107
- codes = (PyArrayObject*)PyArray_ContiguousFromObject
107
+
108
+ codes = (PyArrayObject*)PyArray_FromObject
108
109
(codes_obj.ptr (), PyArray_UINT8, 1 , 1 );
109
110
if (!codes)
110
111
throw Py::ValueError (" Invalid codes array." );
111
112
112
113
if (codes->dimensions [0 ] != vertices->dimensions [0 ])
113
- throw Py::ValueError (" Vertices and codes array are not the same length." );
114
+ throw Py::ValueError (" vertices and codes arrays are not the same length." );
114
115
115
116
m_total_vertices = codes->dimensions [0 ];
116
117
}
@@ -125,10 +126,9 @@ class PathIterator {
125
126
inline unsigned vertex (unsigned idx, double * x, double * y) {
126
127
if (idx > m_total_vertices)
127
128
throw Py::RuntimeError (" Requested vertex past end" );
128
- double * pv = (double *)(vertices->data + (idx * vertices->strides [0 ]));
129
- *x = *pv++;
130
- *y = *pv;
131
- return code_map[(unsigned int )*(codes->data + (idx * codes->strides [0 ]))];
129
+ *x = *(double *)PyArray_GETPTR2 (vertices, idx, 0 );
130
+ *y = *(double *)PyArray_GETPTR2 (vertices, idx, 1 );
131
+ return code_map[(int )*(char *)PyArray_GETPTR1 (codes, idx)];
132
132
}
133
133
134
134
inline unsigned vertex (double * x, double * y) {
@@ -145,12 +145,14 @@ class PathIterator {
145
145
}
146
146
};
147
147
148
- const char PathIterator::code_map[] = {0 ,
149
- agg::path_cmd_move_to,
150
- agg::path_cmd_line_to,
151
- agg::path_cmd_curve3,
152
- agg::path_cmd_curve4,
153
- agg::path_cmd_end_poly | agg::path_flags_close};
148
+ // Maps path codes on the Python side to agg path commands
149
+ const char PathIterator::code_map[] =
150
+ {0 ,
151
+ agg::path_cmd_move_to,
152
+ agg::path_cmd_line_to,
153
+ agg::path_cmd_curve3,
154
+ agg::path_cmd_curve4,
155
+ agg::path_cmd_end_poly | agg::path_flags_close};
154
156
155
157
template <class VertexSource > class conv_quantize
156
158
{
@@ -160,19 +162,16 @@ template<class VertexSource> class conv_quantize
160
162
161
163
void set_source (VertexSource& source) { m_source = &source; }
162
164
163
- void rewind (unsigned path_id)
164
- {
165
+ void rewind (unsigned path_id) {
165
166
m_source->rewind (path_id);
166
167
}
167
168
168
- unsigned vertex (double * x, double * y)
169
- {
169
+ unsigned vertex (double * x, double * y) {
170
170
unsigned cmd = m_source->vertex (x, y);
171
- if (m_quantize && agg::is_vertex (cmd))
172
- {
173
- *x = (int )(*x);
174
- *y = (int )(*y);
175
- }
171
+ if (m_quantize && agg::is_vertex (cmd)) {
172
+ *x = (int )(*x + 0.5 );
173
+ *y = (int )(*y + 0.5 );
174
+ }
176
175
return cmd;
177
176
}
178
177
0 commit comments