Closed eliocamp closed 3 years ago
I'm fine with this in principle, but is there any way the computation could break, e.g. when you divide by 0 or when the tan()
function returns Inf
?
Good question.
I don't think there's any risk of dividing by zero, since Sx is a dimension, which if grid is sensible enough, should only be zero if the drawing area is zero pixels wide. At that point, the angle of your labels is the least of your problems.
I tested it anyway. atan(1/0)
, atan(Inf)
and atan(tan(pi/2))
all return a sensible pi/2, so it seems that atan is safe for any input value.
The only problem I could envision is if both Sy and Sx are zero (that is, drawing area has zero extent). Then, atan(0/0)
is NULL. Would you like me to add a check for that?
Let's just make sure that the angle is always a reasonable number. So why not add the following code:
theta <- atan(tan(...))
labels_data$theta <- ifelse(is.finite(theta), theta, 0)
Sounds fair. Latest commit adds that line.
Thanks!
This PR addresses #27 by correcting the label angle at draw time to compensate by the viewport aspect ratio.
Example code:
With current master branch. Notice the lower-right "100", for example:
Exaggerated version:
WIth this PR:
Exaggerated version: