Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrows in drawn by the arrow3d are not clipped sometimes #68

Open
alex-hhh opened this issue Sep 1, 2020 · 1 comment
Open

Arrows in drawn by the arrow3d are not clipped sometimes #68

alex-hhh opened this issue Sep 1, 2020 · 1 comment

Comments

@alex-hhh
Copy link
Collaborator

alex-hhh commented Sep 1, 2020

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:

(arrows3d '((0 4 0) (2 4 0)) #:color 2 #:width 3 #:label "start OUT, end IN")

This is probably caused by the change here:

(when (and v1 v2 (or draw-outside? (in-bounds? v1)))

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.

@bdeket
Copy link
Contributor

bdeket commented Sep 1, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants