@@ -47,8 +47,18 @@ double
4747_points_to_pixels (RendererAggObject* renderer, double pt) {
4848 // convert a value in points to pixels depending on renderer dpi and
4949 // scrren pixels per inch
50+ return (pt*PIXELS_PER_INCH/72.0 *renderer->dpi /72.0 );
51+
52+ }
53+
54+ double
55+ _points_to_pixels_snapto (RendererAggObject* renderer, double pt) {
56+ // convert a value in points to pixels depending on renderer dpi and
57+ // scrren pixels per inch
58+ // snap return pixels to grid
5059 return (int )(pt*PIXELS_PER_INCH/72.0 *renderer->dpi /72.0 )+0.5 ;
5160
61+
5262}
5363
5464
@@ -618,7 +628,7 @@ RendererAgg_draw_lines(RendererAggObject *renderer, PyObject* args) {
618628 PyObject *dashSeq = NULL ;
619629 if (useDashes) {
620630 // TODO: use offset
621- offset = _points_to_pixels (renderer, _seqitem_as_double (dashes, 0 ));
631+ offset = _points_to_pixels_snapto (renderer, _seqitem_as_double (dashes, 0 ));
622632 // note, you must decref this later if useDashes
623633 dashSeq = PySequence_GetItem (dashes, 1 );
624634 };
@@ -629,14 +639,31 @@ RendererAgg_draw_lines(RendererAggObject *renderer, PyObject* args) {
629639
630640 double thisX, thisY;
631641 unsigned winHeight = renderer->rbase ->height ();
632- thisX = (int )(_seqitem_as_double (x, 0 ))+0.5 ;
633- thisY = (int )(winHeight - _seqitem_as_double (y, 0 ))+0.5 ;
634- path.move_to (thisX, thisY);
635- for (int i=1 ; i<Nx; ++i) {
636- thisX = (int )(_seqitem_as_double (x, i))+0.5 ;
637- thisY = (int )(winHeight - _seqitem_as_double (y, i)) + 0.5 ;
638- path.line_to (thisX, thisY);
642+
643+ if (Nx==2 ) {
644+ // this is a little hack - len(2) lines are probably grid and
645+ // ticks so I'm going to snap to pixel
646+ thisX = (int )(_seqitem_as_double (x, 0 ))+0.5 ;
647+ thisY = (int )(winHeight - _seqitem_as_double (y, 0 ))+0.5 ;
648+ path.move_to (thisX, thisY);
649+ for (int i=1 ; i<Nx; ++i) {
650+ thisX = (int )(_seqitem_as_double (x, i))+0.5 ;
651+ thisY = (int )(winHeight - _seqitem_as_double (y, i)) + 0.5 ;
652+ path.line_to (thisX, thisY);
653+ }
639654 }
655+ else {
656+ thisX = _seqitem_as_double (x, 0 );
657+ thisY = (winHeight - _seqitem_as_double (y, 0 ));
658+ path.move_to (thisX, thisY);
659+ for (int i=1 ; i<Nx; ++i) {
660+ thisX = (_seqitem_as_double (x, i));
661+ thisY = (winHeight - _seqitem_as_double (y, i)) ;
662+ path.line_to (thisX, thisY);
663+ }
664+ }
665+
666+
640667
641668
642669
@@ -671,8 +698,8 @@ RendererAgg_draw_lines(RendererAggObject *renderer, PyObject* args) {
671698 agg::conv_stroke<dash_t > stroke (dash);
672699 double on, off;
673700 for (int i=0 ; i<N/2 ; i+=2 ) {
674- on = _points_to_pixels (renderer, _seqitem_as_double (dashSeq, 2 *i));
675- off = _points_to_pixels (renderer, _seqitem_as_double (dashSeq, 2 *i+1 ));
701+ on = _points_to_pixels_snapto (renderer, _seqitem_as_double (dashSeq, 2 *i));
702+ off = _points_to_pixels_snapto (renderer, _seqitem_as_double (dashSeq, 2 *i+1 ));
676703 dash.add_dash (on, off);
677704 }
678705 stroke.line_cap (cap);
0 commit comments