plot icon indicating copy to clipboard operation
plot copied to clipboard

Arrows in drawn by the `arrow3d` are not clipped sometimes

Open alex-hhh opened this issue 5 years ago • 1 comments

NOTE Pull request #67 introduced the arrow and arrow3d renders

Arrows in drawn by the arrow3d are not clipped when the start is outside the plot area but the end is inside the area. This is visible in the following example: https://github.com/racket/plot/blob/master/plot-test/plot/tests/PRs/test-data/pr42-2-2.png

Source for the test data is at: https://github.com/racket/plot/blob/4415b2d3f36cec185c2c40c116932c88f384959b/plot-test/plot/tests/PRs/42.rkt#L59

This is probably caused by the change here: https://github.com/racket/plot/blob/4415b2d3f36cec185c2c40c116932c88f384959b/plot-lib/plot/private/plot3d/plot-area.rkt#L1519

When the draw-outside? parameter is #t, the line arrow is drawn even if the start is outside. Note that there is a check there for the end of the arrow, and if the end is outside, the arrow drawing is replaced with put-line which presumably clips the line correctly. We need to add line clipping for the start as well.

alex-hhh avatar Sep 01 '20 11:09 alex-hhh

This is not so much a new error, but an error that already existed in the put-arrow function. The arrows were never clipped. For vector-fields3d this was not a problem since the base-point of the vector was always lying within the plot area. The arrow3d just expose this problem since the start of an arrow can now be outside the area.

For the 2D case there is a similar clipping error when zooming in very deep.

(plot
 (list (arrows '((0 .5)(2 .5))
               #:arrow-head-size-or-scale '(= 50))
       (arrows '((0 -.5)(2 -.5))))
 #:x-min (- 2 1e-11) #:y-min -1
 #:x-max (+ 2 1e-11) #:y-max +1)

clip-err1

vector-field has the same error:

(plot
 (vector-field (λ (x y) (if (and (< (- 2 1e-11) x (+ 2 1e-11))
                                 (< -.1 y .1))
                            (list -2 0)
                            (list 0 0)))
               #:samples 3
               #:scale 1)
 #:x-min (- 2 1e-11) #:y-min -1
 #:x-max (+ 2 1e-11) #:y-max +1)

clip-err2

(** in both plots, the lines should be going to the left)

For the 2D case, this is happening when one end of the vector is a large (rational?) negative number. For Lines etc. this is solved by clipping the lines that go outside the drawing area. For arrows, I was hesitant to start clipping, since that also will affect the arrowheads.

bdeket avatar Sep 01 '20 12:09 bdeket