From ec86a7ee11f3bd2163afd9d008ef0b52e1f603a6 Mon Sep 17 00:00:00 2001 From: Alexis King Date: Wed, 3 Jun 2020 22:07:49 -0500 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20draw=20diagonal=20lines=20inste?= =?UTF-8?q?ad=20of=20points=20at=20high=20scaling=20factors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit draw-point (and draw-line with a line length of zero) actually draws a very small line at a 45° angle, which forces Cairo to draw the line cap. But at large scaling factors, this tiny line stops looking like a point and starts looking like an actual line, which isn’t good. This commit adjusts the length of the tiny line based on the current scaling factor, so it will still look like a point even when scaled up. --- draw-lib/racket/draw/private/dc.rkt | 40 +++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/draw-lib/racket/draw/private/dc.rkt b/draw-lib/racket/draw/private/dc.rkt index 5498ef4..fc59f82 100644 --- a/draw-lib/racket/draw/private/dc.rkt +++ b/draw-lib/racket/draw/private/dc.rkt @@ -1158,28 +1158,30 @@ (def/public (draw-ellipse [real? x] [real? y] [nonnegative-real? width] [nonnegative-real? height]) (do-draw-arc 'draw-ellipse x y width height 0 2pi)) + (define/private (do-draw-point who x y) + (with-cr + (check-ok who) + cr + (cairo_new_path cr) + (let ([x (align-x x)] + [y (align-y y)]) + (cairo_move_to cr x y) + (cairo_line_to cr (+ x (/ 0.1 effective-scale-x)) (+ y (/ 0.1 effective-scale-y))) + (draw cr #f #t)))) + (def/public (draw-line [real? x1] [real? y1] [real? x2] [real? y2]) - (let ([dot (if (and (= x1 x2) (= y1 y2)) - 0.1 - 0)]) - (with-cr - (check-ok 'draw-line) - cr - (cairo_new_path cr) - (cairo_move_to cr (align-x x1) (align-y y1)) - (cairo_line_to cr (+ (align-x x2) dot) (+ (align-y y2) dot)) - (draw cr #f #t)))) + (if (and (= x1 x2) (= y1 y2)) + (do-draw-point 'draw-line x1 y1) + (with-cr + (check-ok 'draw-line) + cr + (cairo_new_path cr) + (cairo_move_to cr (align-x x1) (align-y y1)) + (cairo_line_to cr (align-x x2) (align-y y2)) + (draw cr #f #t)))) (def/public (draw-point [real? x] [real? y]) - (with-cr - (check-ok 'draw-point) - cr - (cairo_new_path cr) - (let ([x (align-x x)] - [y (align-y y)]) - (cairo_move_to cr x y) - (cairo_line_to cr (+ 0.1 x) (+ 0.1 y)) - (draw cr #f #t)))) + (do-draw-point 'draw-point x y)) (def/public (draw-lines [(make-alts (make-list point%) list-of-pair-of-real?) pts] [real? [x 0.0]] [real? [y 0.0]])