8000 Don't copy path array to a contiguous one. · matplotlib/matplotlib@c957d1f · GitHub
[go: up one dir, main page]

Skip to content

Commit c957d1f

Browse files
committed
Don't copy path array to a contiguous one.
svn path=/branches/transforms/; revision=3868
1 parent 22fb41a commit c957d1f

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

src/_backend_agg.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,18 @@ class PathIterator {
100100
Py::Object vertices_obj = path_obj.getAttr("vertices");
101101
Py::Object codes_obj = path_obj.getAttr("codes");
102102

103-
vertices = (PyArrayObject*)PyArray_ContiguousFromObject
103+
vertices = (PyArrayObject*)PyArray_FromObject
104104
(vertices_obj.ptr(), PyArray_DOUBLE, 2, 2);
105105
if (!vertices || vertices->nd != 2 || vertices->dimensions[1] != 2)
106106
throw Py::ValueError("Invalid vertices array.");
107-
codes = (PyArrayObject*)PyArray_ContiguousFromObject
107+
108+
codes = (PyArrayObject*)PyArray_FromObject
108109
(codes_obj.ptr(), PyArray_UINT8, 1, 1);
109110
if (!codes)
110111
throw Py::ValueError("Invalid codes array.");
111112

112113
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.");
114115

115116
m_total_vertices = codes->dimensions[0];
116117
}
@@ -125,10 +126,9 @@ class PathIterator {
125126
inline unsigned vertex(unsigned idx, double* x, double* y) {
126127
if (idx > m_total_vertices)
127128
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)];
132132
}
133133

134134
inline unsigned vertex(double* x, double* y) {
@@ -145,12 +145,14 @@ class PathIterator {
145145
}
146146
};
147147

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};
154156

155157
template<class VertexSource> class conv_quantize
156158
{
@@ -160,19 +162,16 @@ template<class VertexSource> class conv_quantize
160162

161163
void set_source(VertexSource& source) { m_source = &source; }
162164

163-
void rewind(unsigned path_id)
164-
{
165+
void rewind(unsigned path_id) {
165166
m_source->rewind(path_id);
166167
}
167168

168-
unsigned vertex(double* x, double* y)
169-
{
169+
unsigned vertex(double* x, double* y) {
170170
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+
}
176175
return cmd;
177176
}
178177

0 commit comments

Comments
 (0)
0