Optimize C code · matplotlib/matplotlib@03f83d3 · GitHub
Skip to content

Commit 03f83d3

Browse files
committed
Optimize C code
1 parent e240080 commit 03f83d3

5 files changed

Lines changed: 46 additions & 34 deletions

File tree

‎lib/matplotlib/tests/test_axes.py‎

Lines changed: 4 additions & 1 deletion

‎lib/matplotlib/tests/test_lines.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ def test_invalid_line_data():
101101
line.set_ydata(0)
102102

103103

104-
@image_comparison(['line_dashes'], remove_text=True)
104+
@image_comparison(['line_dashes'], remove_text=True, tol=0.002)
105105
def test_line_dashes():
106+
# Tolerance introduced after reordering of floating-point operations
107+
# Remove when regenerating the images
106108
fig, ax = plt.subplots()
107109

108110
ax.plot(range(10), linestyle=(0, (3, 3)), lw=5)

‎src/_backend_agg.h‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
745745

746746
agg::trans_affine mtx;
747747
mtx *= agg::trans_affine_translation(0, -image.dim(0));
748-
mtx *= agg::trans_affine_rotation(-angle * agg::pi / 180.0);
748+
mtx *= agg::trans_affine_rotation(-angle * (agg::pi / 180.0));
749749
mtx *= agg::trans_affine_translation(x, y);
750750

751751
agg::path_storage rect;
@@ -773,8 +773,10 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
773773
} else {
774774
agg::rect_i fig, text;
775775

776+
int deltay = y - image.dim(0);
777+
776778
fig.init(0, 0, width, height);
777-
text.init(x, y - image.dim(0), x + image.dim(1), y);
779+
text.init(x, deltay, x + image.dim(1), y);
778780
text.clip(fig);
779781

780782
if (gc.cliprect.x1 != 0.0 || gc.cliprect.y1 != 0.0 || gc.cliprect.x2 != 0.0 || gc.cliprect.y2 != 0.0) {
@@ -788,9 +790,11 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
788790
}
789791

790792
if (text.x2 > text.x1) {
793+
int deltax = text.x2 - text.x1;
794+
int deltax2 = text.x1 - x;
791795
for (int yi = text.y1; yi < text.y2; ++yi) {
792-
pixFmt.blend_solid_hspan(text.x1, yi, (text.x2 - text.x1), gc.color,
793-
&image(yi - (y - image.dim(0)), text.x1 - x));
796+
pixFmt.blend_solid_hspan(text.x1, yi, deltax, gc.color,
797+
&image(yi - deltay, deltax2));
794798
}
795799
}
796800
}
@@ -945,6 +949,7 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
945949
facepair_t face;
946950
face.first = Nfacecolors != 0;
947951
agg::trans_affine trans;
952+
bool do_clip = !face.first && !gc.has_hatchpath();
948953

949954
for (int i = 0; i < (int)N; ++i) {
950955
typename PathGenerator::path_iterator path = path_generator(i);
@@ -992,8 +997,6 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
992997
}
993998
}
994999

995-
bool do_clip = !face.first && !gc.has_hatchpath();
996-
9971000
if (check_snap) {
9981001
gc.isaa = antialiaseds(i % Naa);
9991002

‎src/_backend_agg_basic_types.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,19 @@ class Dashes
5252
template <class T>
5353
void dash_to_stroke(T &stroke, double dpi, bool isaa)
5454
{
55+
double scaleddpi = dpi / 72.0;
5556
for (dash_t::const_iterator i = dashes.begin(); i != dashes.end(); ++i) {
5657
double val0 = i->first;
5758
double val1 = i->second;
58-
val0 = val0 * dpi / 72.0;
59-
val1 = val1 * dpi / 72.0;
59+
val0 = val0 * scaleddpi;
60+
val1 = val1 * scaleddpi;
6061
if (!isaa) {
6162
val0 = (int)val0 + 0.5;
6263
val1 = (int)val1 + 0.5;
6364
}
6465
stroke.add_dash(val0, val1);
6566
}
66-
stroke.dash_start(get_dash_offset() * dpi / 72.0);
67+
stroke.dash_start(get_dash_offset() * scaleddpi);
6768
}
6869
};
6970

‎src/ft2font.cpp‎

Lines changed: 26 additions & 23 deletions

0 commit comments

Comments
 (0)