@@ -252,19 +252,30 @@ rotate_just <- function(angle, hjust, vjust) {
252
252
# vnew <- sin(rad) * hjust + cos(rad) * vjust + (1 - cos(rad) - sin(rad)) / 2
253
253
254
254
angle <- (angle %|| % 0 ) %% 360
255
- if (0 < = angle & angle < 90 ) {
256
- hnew <- hjust
257
- vnew <- vjust
258
- } else if (90 < = angle & angle < 180 ) {
259
- hnew <- 1 - vjust
260
- vnew <- hjust
261
- } else if (180 < = angle & angle < 270 ) {
262
- hnew <- 1 - hjust
263
- vnew <- 1 - vjust
264
- } else if (270 < = angle & angle < 360 ) {
265
- hnew <- vjust
266
- vnew <- 1 - hjust
267
- }
255
+
256
+ # Apply recycle rules
257
+ size <- vec_size_common(angle , hjust , vjust )
258
+ angle <- vec_recycle(angle , size )
259
+ hjust <- vec_recycle(hjust , size )
260
+ vjust <- vec_recycle(vjust , size )
261
+
262
+ # Find quadrant on circle
263
+ case <- findInterval(angle , c(0 , 90 , 180 , 270 , 360 ))
264
+
265
+ hnew <- hjust
266
+ vnew <- vjust
267
+
268
+ is_case <- which(case == 2 ) # 90 <= x < 180
269
+ hnew [is_case ] <- 1 - vjust [is_case ]
270
+ vnew [is_case ] <- hjust [is_case ]
271
+
272
+ is_case <- which(case == 3 ) # 180 <= x < 270
273
+ hnew [is_case ] <- 1 - hjust [is_case ]
274
+ vnew [is_case ] <- 1 - vjust [is_case ]
275
+
276
+ is_case <- which(case == 4 ) # 270 <= x < 360
277
+ hnew [is_case ] <- vjust [is_case ]
278
+ vnew [is_case ] <- 1 - hjust [is_case ]
268
279
269
280
list (hjust = hnew , vjust = vnew )
270
281
}
0 commit comments