|
From: <md...@us...> - 2007-09-20 14:26:32
|
Revision: 3868
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3868&view=rev
Author: mdboom
Date: 2007-09-20 07:26:27 -0700 (Thu, 20 Sep 2007)
Log Message:
-----------
Don't copy path array to a contiguous one.
Modified Paths:
--------------
branches/transforms/src/_backend_agg.cpp
Modified: branches/transforms/src/_backend_agg.cpp
===================================================================
--- branches/transforms/src/_backend_agg.cpp 2007-09-20 14:13:51 UTC (rev 3867)
+++ branches/transforms/src/_backend_agg.cpp 2007-09-20 14:26:27 UTC (rev 3868)
@@ -100,17 +100,18 @@
Py::Object vertices_obj = path_obj.getAttr("vertices");
Py::Object codes_obj = path_obj.getAttr("codes");
- vertices = (PyArrayObject*)PyArray_ContiguousFromObject
+ vertices = (PyArrayObject*)PyArray_FromObject
(vertices_obj.ptr(), PyArray_DOUBLE, 2, 2);
if (!vertices || vertices->nd != 2 || vertices->dimensions[1] != 2)
throw Py::ValueError("Invalid vertices array.");
- codes = (PyArrayObject*)PyArray_ContiguousFromObject
+
+ codes = (PyArrayObject*)PyArray_FromObject
(codes_obj.ptr(), PyArray_UINT8, 1, 1);
if (!codes)
throw Py::ValueError("Invalid codes array.");
if (codes->dimensions[0] != vertices->dimensions[0])
- throw Py::ValueError("Vertices and codes array are not the same length.");
+ throw Py::ValueError("vertices and codes arrays are not the same length.");
m_total_vertices = codes->dimensions[0];
}
@@ -125,10 +126,9 @@
inline unsigned vertex(unsigned idx, double* x, double* y) {
if (idx > m_total_vertices)
throw Py::RuntimeError("Requested vertex past end");
- double* pv = (double*)(vertices->data + (idx * vertices->strides[0]));
- *x = *pv++;
- *y = *pv;
- return code_map[(unsigned int)*(codes->data + (idx * codes->strides[0]))];
+ *x = *(double*)PyArray_GETPTR2(vertices, idx, 0);
+ *y = *(double*)PyArray_GETPTR2(vertices, idx, 1);
+ return code_map[(int)*(char *)PyArray_GETPTR1(codes, idx)];
}
inline unsigned vertex(double* x, double* y) {
@@ -145,12 +145,14 @@
}
};
-const char PathIterator::code_map[] = {0,
- agg::path_cmd_move_to,
- agg::path_cmd_line_to,
- agg::path_cmd_curve3,
- agg::path_cmd_curve4,
- agg::path_cmd_end_poly | agg::path_flags_close};
+// Maps path codes on the Python side to agg path commands
+const char PathIterator::code_map[] =
+ {0,
+ agg::path_cmd_move_to,
+ agg::path_cmd_line_to,
+ agg::path_cmd_curve3,
+ agg::path_cmd_curve4,
+ agg::path_cmd_end_poly | agg::path_flags_close};
template<class VertexSource> class conv_quantize
{
@@ -160,19 +162,16 @@
void set_source(VertexSource& source) { m_source = &source; }
- void rewind(unsigned path_id)
- {
+ void rewind(unsigned path_id) {
m_source->rewind(path_id);
}
- unsigned vertex(double* x, double* y)
- {
+ unsigned vertex(double* x, double* y) {
unsigned cmd = m_source->vertex(x, y);
- if(m_quantize && agg::is_vertex(cmd))
- {
- *x = (int)(*x);
- *y = (int)(*y);
- }
+ if (m_quantize && agg::is_vertex(cmd)) {
+ *x = (int)(*x + 0.5);
+ *y = (int)(*y + 0.5);
+ }
return cmd;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|