8000 fixed ticker average bug w/ numarray · matplotlib/matplotlib@f1c5597 · GitHub
[go: up one dir, main page]

Skip to content

Commit f1c5597

Browse files
committed
fixed ticker average bug w/ numarray
svn path=/trunk/matplotlib/; revision=1362
1 parent c25f882 commit f1c5597

File tree

5 files changed

+111
-59
lines changed

5 files changed

+111
-59
lines changed

agg23/include/agg_math_stroke.h

Lines changed: 68 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ namespace agg
4343
};
4444

4545
// Minimal angle to calculate round joins, less than 0.1 degree.
46-
const double stroke_theta = 0.001; //----stroke_theta
47-
46+
const double stroke_theta = 0.001; //----stroke_theta
4847

4948
//--------------------------------------------------------stroke_calc_arc
5049
template<class VertexConsumer>
@@ -125,50 +124,27 @@ namespace agg
125124
double xi = v1.x;
126125
double yi = v1.y;
127126

128-
if(!calc_intersection(v0.x + dx1, v0.y - dy1,
129-
v1.x + dx1, v1.y - dy1,
130-
v1.x + dx2, v1.y - dy2,
131-
v2.x + dx2, v2.y - dy2,
132-
&xi, &yi))
127+
if(calc_intersection(v0.x + dx1, v0.y - dy1,
128+
v1.x + dx1, v1.y - dy1,
129+
v1.x + dx2, v1.y - dy2,
130+
v2.x + dx2, v2.y - dy2,
131+
&xi, &yi))
133132
{
134-
// The calculation didn't succeed, most probaly
135-
// the three points lie one straight line
136-
//----------------
137-
if(calc_distance(dx1, -dy1, dx2, -dy2) < width * 0.025)
133+
// Calculation of the intersection succeeded
134+
//---------------------
135+
double d1 = calc_distance(v1.x, v1.y, xi, yi);
136+
double lim = width * miter_limit;
137+
if(d1 <= lim)
138138
{
139-
// This case means that the next segment continues
140-
// the previous one (straight line)
141-
//-----------------
142-
out_vertices.add(coord_type(v1.x + dx1, v1.y - dy1));
139+
// Inside the miter limit
140+
//---------------------
141+
out_vertices.add(coord_type(xi, yi));
143142
}
144143
else
145-
{
146-
// This case means that the next segment goes back
147-
//-----------------
148-
if(revert_flag)
149-
{
150-
out_vertices.add(coord_type(v1.x + dx1, v1.y - dy1));
151-
out_vertices.add(coord_type(v1.x + dx2, v1.y - dy2));
152-
}
153-
else
154-
{
155-
// If no miter-revert, calcuate new dx1, dy1, dx2, dy2
156-
out_vertices.add(coord_type(v1.x + dx1 + dy1 * miter_limit,
157-
v1.y - dy1 + dx1 * miter_limit));
158-
out_vertices.add(coord_type(v1.x + dx2 - dy2 * miter_limit,
159-
v1.y - dy2 - dx2 * miter_limit));
160-
}
161-
}
162-
}
163-
else
164-
{
165-
double d1 = calc_distance(v1.x, v1.y, xi, yi);
166-
double lim = width * miter_limit;
167-
if(d1 > lim)
168144
{
169145
// Miter limit exceeded
170146
//------------------------< 10000 /span>
171-
if(revert_flag)
147+
if(revert_flag || d1 < intersection_epsilon)
172148
{
173149
// For the compatibility with SVG, PDF, etc,
174150
// we use a simple bevel join instead of
@@ -195,11 +171,44 @@ namespace agg
195171
out_vertices.add(coord_type(x2, y2));
196172
}
197173
}
174+
}
175+
else
176+
{
177+
// Calculation of the intersection failed, most probaly
178+
// the three points lie one straight line.
179+
// First check if v0 and v2 lie on the opposite sides of vector:
180+
// (v1.x, v1.y) -> (v1.x+dx1, v1.y-dy1), that is, the perpendicular
181+
// to the line determined by vertices v0 and v1.
182+
// This condition deternines whether the next line segments continues
183+
// the previous one or goes back.
184+
//----------------
185+
double x2 = v1.x + dx1;
186+
double y2 = v1.y - dy1;
187+
if(((x2 - v0.x)*dy1 - (v0.y - y2)*dx1 < 0.0) !=
188+
((x2 - v2.x)*dy1 - (v2.y - y2)*dx1 < 0.0))
189+
{
190+
// This case means that the next segment continues
191+
// the previous one (straight line)
192+
//-----------------
193+
out_vertices.add(coord_type(v1.x + dx1, v1.y - dy1));
194+
}
198195
else
199196
{
200-
// Inside the miter limit
201-
//---------------------
202-
out_vertices.add(coord_type(xi, yi));
197+
// This case means that the next segment goes back
198+
//-----------------
199+
if(revert_flag)
200+
{
201+
out_vertices.add(coord_type(v1.x + dx1, v1.y - dy1));
202+
out_vertices.add(coord_type(v1.x + dx2, v1.y - dy2));
203+
}
204+
else
205+
{
206+
// If no miter-revert, calcuate new dx1, dy1, dx2, dy2
207+
out_vertices.add(coord_type(v1.x + dx1 + dy1 * miter_limit,
208+
v1.y - dy1 + dx1 * miter_limit));
209+
out_vertices.add(coord_type(v1.x + dx2 - dy2 * miter_limit,
210+
v1.y - dy2 - dx2 * miter_limit));
211+
}
203212
}
204213
}
205214
}
@@ -223,18 +232,27 @@ namespace agg
223232

224233
out_vertices.remove_all();
225234

226-
double dx1 = width * (v1.y - v0.y) / len;
227-
double dy1 = width * (v1.x - v0.x) / len;
235+
double dx1 = (v1.y - v0.y) / len;
236+
double dy1 = (v1.x - v0.x) / len;
228237
double dx2 = 0;
229238
double dy2 = 0;
230239

231-
if(line_cap == square_cap)
240+
dx1 *= width;
241+
dy1 *= width;
242+
243+
if(line_cap != round_cap)
232244
{
233-
dx2 = dy1;
234-
dy2 = dx1;
245+
if(line_cap == square_cap)
246+
{
247+
dx2 = dy1;
248+
dy2 = dx1;
249+
}
250+
double dx = dx1 - dx2;
251+
double dy = dy1 - dy2;
252+
out_vertices.add(coord_type(v0.x - dx, v0.y + dy));
253+
out_vertices.add(coord_type(v0.x + dx, v0.y - dy));
235254
}
236-
237-
if(line_cap == round_cap)
255+
else
238256
{
239257
double a1 = atan2(dy1, -dx1);
240258
double a2 = a1 + pi;
@@ -247,11 +265,6 @@ namespace agg
247265
}
248266
out_vertices.add(coord_type(v0.x + dx1, v0.y - dy1));
249267
}
250-
else
251-
{
252-
out_vertices.add(coord_type(v0.x - dx1 - dx2, v0.y + dy1 - dy2));
253-
out_vertices.add(coord_type(v0.x + dx1 - dx2, v0.y - dy1 - dy2));
254-
}
255268
}
256269

257270

@@ -283,7 +296,7 @@ namespace agg
283296

284297
out_vertices.remove_all();
285298

286-
if(calc_point_location(v0.x, v0.y, v1.x, v1.y, v2.x, v2.y) > 0.0)
299+
if(calc_point_location(v0.x, v0.y, v1.x, v1.y, v2.x, v2.y) > 0)
287300
{
288301
// Inner join
289302
//---------------

examples/tex_demo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
fontsize=20)
1313
grid(True)
1414
savefig('tex_demo')
15+
1516
show()

lib/matplotlib/ticker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@
111111
import sys, os, re, time, math, warnings
112112
from mlab import linspace
113113
from matplotlib import verbose
114-
from numerix import absolute, arange, array, asarray, average, Float, floor, log, \
114+
from numerix import absolute, arange, array, asarray, Float, floor, log, \
115115
logical_and, nonzero, ones, take, zeros
116-
from matplotlib.numerix.mlab import amin, amax, std
116+
from matplotlib.numerix.mlab import amin, amax, std, mean
117117
from matplotlib.mlab import frange
118118
from cbook import strip_math
119119

@@ -299,9 +299,9 @@ def set_locs(self, locs):
299299
def _set_offset(self, range):
300300
# offset of 20,001 is 20,000, for example
301301
locs = self.locs
302-
ave_loc = average(locs)
302+
ave_loc = mean(locs)
303303
if ave_loc: # dont want to take log10(0)
304-
ave_oom = math.floor(math.log10(average(absolute(locs))))
304+
ave_oom = math.floor(math.log10(mean(absolute(locs))))
305305
range_oom = math.floor(math.log10(range))
306306
if absolute(ave_oom-range_oom) >= 4: # four sig-figs
307307
if ave_loc < 0:

src/_image.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,41 @@ Image::buffer_argb32(const Py::Tuple& args) {
227227
return Py::asObject(o);
228228

229229

230+
}
231+
232+
233+
char Image::buffer_rgba__doc__[] =
234+
"buffer = buffer_rgba)"
235+
"\n"
236+
"Return the image buffer as rgba32\n"
237+
;
238+
Py::Object
239+
Image::buffer_rgba(const Py::Tuple& args) {
240+
//"Return the image object as rgba";
241+
242+
_VERBOSE("RendererAgg::buffer_rgba");
243+
244+
args.verify_length(0);
245+
int row_len = colsOut * 4;
246+
247+
//unsigned char* buf_tmp = new unsigned char[row_len * rowsOut];
248+
//if (buf_tmp ==NULL)
249+
// throw Py::MemoryError("RendererAgg::buffer_argb32 could not allocate memory");
250+
251+
//agg::rendering_buffer rtmp;
252+
//tmp.attach(buf_tmp, colsOut, rowsOut, row_len);
253+
254+
//color_conv(&rtmp, rbufOut, agg::color_conv_rgba32_to_argb32());
255+
256+
257+
//todo: how to do this with native CXX
258+
//PyObject* o = Py_BuildValue("s#", buf_tmp, row_len * rowsOut);
259+
PyObject* o = Py_BuildValue("lls#", rowsOut, colsOut,
260+
rbufOut, row_len * rowsOut);
261+
//delete [] buf_tmp;
262+
return Py::asObject(o);
263+
264+
230265
}
231266

232267
char Image::reset_matrix__doc__[] =
@@ -623,6 +658,7 @@ Image::init_type() {
623658
add_varargs_method( "apply_translation", &Image::apply_translation, Image::apply_translation__doc__);
624659
add_varargs_method( "as_str", &Image::as_str, Image::as_str__doc__);
625660
add_varargs_method( "buffer_argb32", &Image::buffer_argb32, Image::buffer_argb32__doc__);
661+
add_varargs_method( "buffer_rgba", &Image::buffer_rgba, Image::buffer_rgba__doc__);
626662
add_varargs_method( "get_aspect", &Image::get_aspect, Image::get_aspect__doc__);
627663
add_varargs_method( "get_interpolation", &Image::get_interpolation, Image::get_interpolation__doc__);
628664
add_varargs_method( "get_size", &Image::get_size, Image::get_size__doc__);

src/_image.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Image : public Py::PythonExtension<Image> {
2828
Py::Object apply_translation(const Py::Tuple& args);
2929
Py::Object as_str(const Py::Tuple& args);
3030
Py::Object buffer_argb32(const Py::Tuple& args);
31+
Py::Object buffer_rgba(const Py::Tuple& args);
3132
Py::Object reset_matrix(const Py::Tuple& args);
3233
Py::Object resize(const Py::Tuple& args, const Py::Dict& kwargs);
3334
Py::Object get_aspect(const Py::Tuple& args);
@@ -81,6 +82,7 @@ class Image : public Py::PythonExtension<Image> {
8182
static char apply_translation__doc__[];
8283
static char as_str__doc__[];
8384
static char buffer_argb32__doc__[];
85+
static char buffer_rgba__doc__[];
8486
static char reset_matrix__doc__[];
8587
static char resize__doc__[];
8688
static char get_aspect__doc__[];

0 commit comments

Comments
 (0)
0