Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc25f74

Browse files
authored
Merge pull request matplotlib#25207 from oscargus/roundtoint
Add mpl_round_to_int
2 parents 76dd07e + 0b1d5c7 commit bc25f74

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/_backend_agg.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,10 +780,10 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
780780
if (gc.cliprect.x1 != 0.0 || gc.cliprect.y1 != 0.0 || gc.cliprect.x2 != 0.0 || gc.cliprect.y2 != 0.0) {
781781
agg::rect_i clip;
782782

783-
clip.init(int(mpl_round(gc.cliprect.x1)),
784-
int(mpl_round(height - gc.cliprect.y2)),
785-
int(mpl_round(gc.cliprect.x2)),
786-
int(mpl_round(height - gc.cliprect.y1)));
783+
clip.init(mpl_round_to_int(gc.cliprect.x1),
784+
mpl_round_to_int(height - gc.cliprect.y2),
785+
mpl_round_to_int(gc.cliprect.x2),
786+
mpl_round_to_int(height - gc.cliprect.y1));
787787
text.clip(clip);
788788
}
789789

src/mplutils.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@
2929
#endif
3030

3131

32+
inline int mpl_round_to_int(double v)
33+
{
34+
return (int)(v + ((v >= 0.0) ? 0.5 : -0.5));
35+
}
36+
3237
inline double mpl_round(double v)
3338
{
34-
return (double)(int)(v + ((v >= 0.0) ? 0.5 : -0.5));
39+
return (double)mpl_round_to_int(v);
3540
}
3641

3742
// 'kind' codes for paths.

src/path_converters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ class PathSnapper
595595
m_snap = should_snap(source, snap_mode, total_vertices);
596596

597597
if (m_snap) {
598-
int is_odd = (int)mpl_round(stroke_width) % 2;
598+
int is_odd = mpl_round_to_int(stroke_width) % 2;
599599
m_snap_value = (is_odd) ? 0.5 : 0.0;
600600
}
601601

0 commit comments

Comments
 (0)